linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RESEND PATCH v2] scsi: Use vmemdup_user to replace the open code
@ 2018-09-18 15:54 zhong jiang
  2018-09-21 14:16 ` zhong jiang
  2018-09-26  0:45 ` Martin K. Petersen
  0 siblings, 2 replies; 3+ messages in thread
From: zhong jiang @ 2018-09-18 15:54 UTC (permalink / raw)
  To: martin.petersen; +Cc: don.brace, jejb, linux-scsi, linux-kernel

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 <don.brace@microsemi.com>
Acked-by: Don Brace <don.brace@microsemi.com>
Signed-off-by: zhong jiang <zhongjiang@huawei.com>
---
 drivers/scsi/hpsa.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

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 @@ static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp)
 		kfree(buff);
 	}
 	kfree(buff_size);
-	kfree(ioc);
+	kvfree(ioc);
 	return status;
 }
 
-- 
1.7.12.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RESEND PATCH v2] scsi: Use vmemdup_user to replace the open code
  2018-09-18 15:54 [RESEND PATCH v2] scsi: Use vmemdup_user to replace the open code zhong jiang
@ 2018-09-21 14:16 ` zhong jiang
  2018-09-26  0:45 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: zhong jiang @ 2018-09-21 14:16 UTC (permalink / raw)
  To: martin.petersen; +Cc: don.brace, jejb, linux-scsi, linux-kernel, Greg KH

Hi,  martin

Can you pick up the patch?  Thanks,

Sincerely,
zhong jiang

On 2018/9/18 23:54, zhong jiang wrote:
> 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 <don.brace@microsemi.com>
> Acked-by: Don Brace <don.brace@microsemi.com>
> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
> ---
>  drivers/scsi/hpsa.c | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
>
> 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 @@ static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp)
>  		kfree(buff);
>  	}
>  	kfree(buff_size);
> -	kfree(ioc);
> +	kvfree(ioc);
>  	return status;
>  }
>  



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RESEND PATCH v2] scsi: Use vmemdup_user to replace the open code
  2018-09-18 15:54 [RESEND PATCH v2] scsi: Use vmemdup_user to replace the open code zhong jiang
  2018-09-21 14:16 ` zhong jiang
@ 2018-09-26  0:45 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2018-09-26  0:45 UTC (permalink / raw)
  To: zhong jiang; +Cc: martin.petersen, don.brace, jejb, linux-scsi, linux-kernel


zhong,

> vmemdup_user is better than duplicating its implementation, So just
> replace the open code.

Applied to 4.20/scsi-queue, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-09-26  0:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-18 15:54 [RESEND PATCH v2] scsi: Use vmemdup_user to replace the open code zhong jiang
2018-09-21 14:16 ` zhong jiang
2018-09-26  0:45 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).