Skip to content

Commit 03c9e6f

Browse files
Ruan Jinjiejonmason
authored andcommitted
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>
1 parent 4519108 commit 03c9e6f

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

drivers/ntb/test/ntb_tool.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -370,16 +370,9 @@ static ssize_t tool_fn_write(struct tool_ctx *tc,
370370
if (*offp)
371371
return 0;
372372

373-
buf = kmalloc(size + 1, GFP_KERNEL);
374-
if (!buf)
375-
return -ENOMEM;
376-
377-
if (copy_from_user(buf, ubuf, size)) {
378-
kfree(buf);
379-
return -EFAULT;
380-
}
381-
382-
buf[size] = 0;
373+
buf = memdup_user_nul(ubuf, size);
374+
if (IS_ERR(buf))
375+
return PTR_ERR(buf);
383376

384377
n = sscanf(buf, "%c %lli", &cmd, &bits);
385378

0 commit comments

Comments
 (0)