diff options
author | Ruan Jinjie <ruanjinjie@huawei.com> | 2023-08-10 13:14:02 +0200 |
---|---|---|
committer | Jon Mason <jdmason@kudzu.us> | 2023-08-18 15:50:06 +0200 |
commit | 03c9e6f0e0ab3fb6129b8a9f064b7d7957aa969a (patch) | |
tree | 8688fa1cbc97648c9c7d2da2bd3d0d9d453dcee7 /drivers/ntb | |
parent | dtivers: ntb: fix parameter check in perf_setup_dbgfs() (diff) | |
download | linux-03c9e6f0e0ab3fb6129b8a9f064b7d7957aa969a.tar.xz linux-03c9e6f0e0ab3fb6129b8a9f064b7d7957aa969a.zip |
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>
Diffstat (limited to 'drivers/ntb')
-rw-r--r-- | drivers/ntb/test/ntb_tool.c | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/drivers/ntb/test/ntb_tool.c b/drivers/ntb/test/ntb_tool.c index e0acc11d29ba..641cb7e05a47 100644 --- a/drivers/ntb/test/ntb_tool.c +++ b/drivers/ntb/test/ntb_tool.c @@ -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); |