From 03c9e6f0e0ab3fb6129b8a9f064b7d7957aa969a Mon Sep 17 00:00:00 2001 From: Ruan Jinjie Date: Thu, 10 Aug 2023 19:14:02 +0800 Subject: 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 Reviewed-by: Dave Jiang Reviewed-by: Dan Carpenter Reviewed-by: Serge Semin Signed-off-by: Jon Mason --- drivers/ntb/test/ntb_tool.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'drivers/ntb') 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); -- cgit v1.2.3