On Tue, Aug 15, 2023 at 07:55:46PM +0800, Ruan Jinjie wrote: > Use memdup_user_nul() helper instead of open-coding > to simplify the code. > > Signed-off-by: Ruan Jinjie <ruanjinjie@xxxxxxxxxx> > --- > drivers/s390/char/hmcdrv_dev.c | 17 +++++------------ > 1 file changed, 5 insertions(+), 12 deletions(-) > > diff --git a/drivers/s390/char/hmcdrv_dev.c b/drivers/s390/char/hmcdrv_dev.c > index 8d50c894711f..504cdbf9998d 100644 > --- a/drivers/s390/char/hmcdrv_dev.c > +++ b/drivers/s390/char/hmcdrv_dev.c > @@ -252,19 +252,12 @@ static ssize_t hmcdrv_dev_write(struct file *fp, const char __user *ubuf, > fp, (long long) *pos, len); > > if (!fp->private_data) { /* first expect a cmd write */ > - fp->private_data = kmalloc(len + 1, GFP_KERNEL); > - > - if (!fp->private_data) > - return -ENOMEM; > - > - if (!copy_from_user(fp->private_data, ubuf, len)) { > - ((char *)fp->private_data)[len] = '\0'; > - return len; > + fp->private_data = memdup_user_nul(ubuf, len); > + if (IS_ERR(fp->private_data)) { > + fp->private_data = NULL; > + return PTR_ERR(fp->private_data); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This is obviously broken. Sorry, but I'm not willing to review such "trivial" cleanup patches for subtle bugs anymore - maybe you would sooner or later succeed and I would apply such a broken patch. Just don't send such patches; at least I won't take them.