From: zhong jiang Date: Tue, 18 Sep 2018 15:54:41 +0000 (+0800) Subject: scsi: hpsa: Use vmemdup_user to replace the open code X-Git-Tag: v5.15~7642^2~166 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=048a864e533039cc950b716e774c2c09af8fa1dd;p=platform%2Fkernel%2Flinux-starfive.git scsi: hpsa: Use vmemdup_user to replace the open code vmemdup_user is better than duplicating its implementation, So just replace the open code. The issue is detected with the help of Coccinelle. Tested-by: Don Brace Acked-by: Don Brace Signed-off-by: zhong jiang Signed-off-by: Martin K. Petersen --- diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c index 58bb70b..666ba09e5 100644 --- a/drivers/scsi/hpsa.c +++ b/drivers/scsi/hpsa.c @@ -6381,13 +6381,9 @@ static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp) return -EINVAL; if (!capable(CAP_SYS_RAWIO)) return -EPERM; - ioc = kmalloc(sizeof(*ioc), GFP_KERNEL); - if (!ioc) { - status = -ENOMEM; - goto cleanup1; - } - if (copy_from_user(ioc, argp, sizeof(*ioc))) { - status = -EFAULT; + ioc = vmemdup_user(argp, sizeof(*ioc)); + if (IS_ERR(ioc)) { + status = PTR_ERR(ioc); goto cleanup1; } if ((ioc->buf_size < 1) && @@ -6505,7 +6501,7 @@ cleanup1: kfree(buff); } kfree(buff_size); - kfree(ioc); + kvfree(ioc); return status; }