Re: [PATCH -next] ublk: Switch to memdup_user_nul() helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
> ---
>  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@xxxxxxxxxx>

Thanks,
Ming




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux