Regularity and linearity defect of modules over local rings