public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next] ublk: Switch to memdup_user_nul() helper
@ 2023-08-15 11:48 Ruan Jinjie
  2023-08-15 12:39 ` Ming Lei
  2023-08-15 15:06 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Ruan Jinjie @ 2023-08-15 11:48 UTC (permalink / raw)
  To: linux-block, Ming Lei, Jens Axboe; +Cc: ruanjinjie

Use memdup_user_nul() helper instead of open-coding
to simplify the code.

Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
---
 drivers/block/ublk_drv.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 85a81ee556d5..fa7e6955eb3b 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -2743,14 +2743,9 @@ static int ublk_ctrl_uring_cmd_permission(struct ublk_device *ub,
 	if (header->len < header->dev_path_len)
 		return -EINVAL;
 
-	dev_path = kmalloc(header->dev_path_len + 1, GFP_KERNEL);
-	if (!dev_path)
-		return -ENOMEM;
-
-	ret = -EFAULT;
-	if (copy_from_user(dev_path, argp, header->dev_path_len))
-		goto exit;
-	dev_path[header->dev_path_len] = 0;
+	dev_path = memdup_user_nul(argp, header->dev_path_len);
+	if (IS_ERR(dev_path))
+		return PTR_ERR(dev_path);
 
 	ret = -EINVAL;
 	switch (_IOC_NR(cmd->cmd_op)) {
-- 
2.34.1


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

* Re: [PATCH -next] ublk: Switch to memdup_user_nul() helper
  2023-08-15 11:48 [PATCH -next] ublk: Switch to memdup_user_nul() helper Ruan Jinjie
@ 2023-08-15 12:39 ` Ming Lei
  2023-08-15 15:06 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Ming Lei @ 2023-08-15 12:39 UTC (permalink / raw)
  To: Ruan Jinjie; +Cc: linux-block, Jens Axboe

On Tue, Aug 15, 2023 at 07:48:14PM +0800, Ruan Jinjie wrote:
> Use memdup_user_nul() helper instead of open-coding
> to simplify the code.
> 
> Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
> ---
>  drivers/block/ublk_drv.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> index 85a81ee556d5..fa7e6955eb3b 100644
> --- a/drivers/block/ublk_drv.c
> +++ b/drivers/block/ublk_drv.c
> @@ -2743,14 +2743,9 @@ static int ublk_ctrl_uring_cmd_permission(struct ublk_device *ub,
>  	if (header->len < header->dev_path_len)
>  		return -EINVAL;
>  
> -	dev_path = kmalloc(header->dev_path_len + 1, GFP_KERNEL);
> -	if (!dev_path)
> -		return -ENOMEM;
> -
> -	ret = -EFAULT;
> -	if (copy_from_user(dev_path, argp, header->dev_path_len))
> -		goto exit;
> -	dev_path[header->dev_path_len] = 0;
> +	dev_path = memdup_user_nul(argp, header->dev_path_len);
> +	if (IS_ERR(dev_path))
> +		return PTR_ERR(dev_path);

Nice cleanup:

Reviewed-by: Ming Lei <ming.lei@redhat.com>

Thanks,
Ming


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

* Re: [PATCH -next] ublk: Switch to memdup_user_nul() helper
  2023-08-15 11:48 [PATCH -next] ublk: Switch to memdup_user_nul() helper Ruan Jinjie
  2023-08-15 12:39 ` Ming Lei
@ 2023-08-15 15:06 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2023-08-15 15:06 UTC (permalink / raw)
  To: linux-block, Ming Lei, Ruan Jinjie


On Tue, 15 Aug 2023 19:48:14 +0800, Ruan Jinjie wrote:
> Use memdup_user_nul() helper instead of open-coding
> to simplify the code.
> 
> 

Applied, thanks!

[1/1] ublk: Switch to memdup_user_nul() helper
      commit: 306d74055754976f6bbe67aef60fe1022c6b76e0

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2023-08-15 15:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-15 11:48 [PATCH -next] ublk: Switch to memdup_user_nul() helper Ruan Jinjie
2023-08-15 12:39 ` Ming Lei
2023-08-15 15:06 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox