* [PATCH -next] NTB: ntb_tool: Switch to memdup_user_nul() helper
@ 2023-08-10 11:14 Ruan Jinjie
2023-08-10 11:19 ` Dan Carpenter
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ruan Jinjie @ 2023-08-10 11:14 UTC (permalink / raw)
To: jdmason, dave.jiang, allenbh, dan.carpenter, fancer.lancer,
machel, jiasheng, ntb
Cc: ruanjinjie
Use memdup_user_nul() helper instead of open-coding to simplify the code.
Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
---
drivers/ntb/test/ntb_tool.c | 13 +++----------
1 file 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);
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH -next] NTB: ntb_tool: Switch to memdup_user_nul() helper
2023-08-10 11:14 [PATCH -next] NTB: ntb_tool: Switch to memdup_user_nul() helper Ruan Jinjie
@ 2023-08-10 11:19 ` Dan Carpenter
2023-08-10 15:42 ` Dave Jiang
2023-08-13 14:00 ` Serge Semin
2 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2023-08-10 11:19 UTC (permalink / raw)
To: Ruan Jinjie
Cc: jdmason, dave.jiang, allenbh, fancer.lancer, machel, jiasheng, ntb
On Thu, Aug 10, 2023 at 07:14:02PM +0800, Ruan Jinjie wrote:
> Use memdup_user_nul() helper instead of open-coding to simplify the code.
>
> Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
> ---
LGTM.
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
regards,
dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH -next] NTB: ntb_tool: Switch to memdup_user_nul() helper
2023-08-10 11:14 [PATCH -next] NTB: ntb_tool: Switch to memdup_user_nul() helper Ruan Jinjie
2023-08-10 11:19 ` Dan Carpenter
@ 2023-08-10 15:42 ` Dave Jiang
2023-08-13 14:00 ` Serge Semin
2 siblings, 0 replies; 4+ messages in thread
From: Dave Jiang @ 2023-08-10 15:42 UTC (permalink / raw)
To: Ruan Jinjie, jdmason, allenbh, dan.carpenter, fancer.lancer,
machel, jiasheng, ntb
On 8/10/23 04:14, Ruan Jinjie wrote:
> 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>
> ---
> drivers/ntb/test/ntb_tool.c | 13 +++----------
> 1 file 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);
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH -next] NTB: ntb_tool: Switch to memdup_user_nul() helper
2023-08-10 11:14 [PATCH -next] NTB: ntb_tool: Switch to memdup_user_nul() helper Ruan Jinjie
2023-08-10 11:19 ` Dan Carpenter
2023-08-10 15:42 ` Dave Jiang
@ 2023-08-13 14:00 ` Serge Semin
2 siblings, 0 replies; 4+ messages in thread
From: Serge Semin @ 2023-08-13 14:00 UTC (permalink / raw)
To: Ruan Jinjie
Cc: jdmason, dave.jiang, allenbh, dan.carpenter, machel, jiasheng, ntb
On Thu, Aug 10, 2023 at 07:14:02PM +0800, Ruan Jinjie wrote:
> Use memdup_user_nul() helper instead of open-coding to simplify the code.
>
> Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
> ---
> drivers/ntb/test/ntb_tool.c | 13 +++----------
> 1 file 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);
Nice code simplification. Thanks!
Reviewed-by: Serge Semin <fancer.lancer@gmail.com>
-Serge(y)
>
> n = sscanf(buf, "%c %lli", &cmd, &bits);
>
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-08-13 14:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-10 11:14 [PATCH -next] NTB: ntb_tool: Switch to memdup_user_nul() helper Ruan Jinjie
2023-08-10 11:19 ` Dan Carpenter
2023-08-10 15:42 ` Dave Jiang
2023-08-13 14:00 ` Serge Semin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).