public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Ruan Jinjie <ruanjinjie@huawei.com>
Cc: linux-block@vger.kernel.org, Jens Axboe <axboe@kernel.dk>
Subject: Re: [PATCH -next] ublk: Switch to memdup_user_nul() helper
Date: Tue, 15 Aug 2023 20:39:37 +0800	[thread overview]
Message-ID: <ZNtyCQoso3RNMvwp@fedora> (raw)
In-Reply-To: <20230815114815.1551171-1-ruanjinjie@huawei.com>

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


  reply	other threads:[~2023-08-15 12:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-15 11:48 [PATCH -next] ublk: Switch to memdup_user_nul() helper Ruan Jinjie
2023-08-15 12:39 ` Ming Lei [this message]
2023-08-15 15:06 ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZNtyCQoso3RNMvwp@fedora \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=ruanjinjie@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox