Skip to content

Commit

Permalink
ublk: Switch to memdup_user_nul() helper
Browse files Browse the repository at this point in the history
Use memdup_user_nul() helper instead of open-coding
to simplify the code.

Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20230815114815.1551171-1-ruanjinjie@huawei.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Ruan Jinjie authored and Jens Axboe committed Aug 15, 2023
1 parent c7b4b23 commit 66a6a5d
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions drivers/block/ublk_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2742,14 +2742,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)) {
Expand Down

0 comments on commit 66a6a5d

Please sign in to comment.