Skip to content

Commit 66a6a5d

Browse files
ruanjinjie-engaxboe
authored andcommitted
ublk: Switch to memdup_user_nul() helper
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>
1 parent c7b4b23 commit 66a6a5d

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

drivers/block/ublk_drv.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,14 +2742,9 @@ static int ublk_ctrl_uring_cmd_permission(struct ublk_device *ub,
27422742
if (header->len < header->dev_path_len)
27432743
return -EINVAL;
27442744

2745-
dev_path = kmalloc(header->dev_path_len + 1, GFP_KERNEL);
2746-
if (!dev_path)
2747-
return -ENOMEM;
2748-
2749-
ret = -EFAULT;
2750-
if (copy_from_user(dev_path, argp, header->dev_path_len))
2751-
goto exit;
2752-
dev_path[header->dev_path_len] = 0;
2745+
dev_path = memdup_user_nul(argp, header->dev_path_len);
2746+
if (IS_ERR(dev_path))
2747+
return PTR_ERR(dev_path);
27532748

27542749
ret = -EINVAL;
27552750
switch (_IOC_NR(cmd->cmd_op)) {

0 commit comments

Comments
 (0)