NTB: ntb_tool: 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: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Serge Semin <fancer.lancer@gmail.com>
Signed-off-by: Jon Mason <jdmason@kudzu.us>
This commit is contained in:
Ruan Jinjie 2023-08-10 19:14:02 +08:00 committed by Jon Mason
parent 45191087c3
commit 03c9e6f0e0

View File

@ -370,16 +370,9 @@ static ssize_t tool_fn_write(struct tool_ctx *tc,
if (*offp)
return 0;
buf = kmalloc(size + 1, GFP_KERNEL);
if (!buf)
return -ENOMEM;
if (copy_from_user(buf, ubuf, size)) {
kfree(buf);
return -EFAULT;
}
buf[size] = 0;
buf = memdup_user_nul(ubuf, size);
if (IS_ERR(buf))
return PTR_ERR(buf);
n = sscanf(buf, "%c %lli", &cmd, &bits);