Amending W4 for extra withholding late in the year

Taxes are withheld throughout the year by my employer. However, I realize that I may not have had enough withheld for my state (and maybe for Federal) and I may have an underpayment penalty.  Can I amend my W4 for State and Federal now to have an extra amount withheld for my last few paychecks in 2022 so I hopefully can avoid a penalty?  Thank you.