From: Serge Semin <fancer.lancer@gmail.com>
To: Ruan Jinjie <ruanjinjie@huawei.com>
Cc: jdmason@kudzu.us, dave.jiang@intel.com, allenbh@gmail.com,
dan.carpenter@linaro.org, machel@vivo.com, jiasheng@iscas.ac.cn,
ntb@lists.linux.dev
Subject: Re: [PATCH -next] NTB: ntb_tool: Switch to memdup_user_nul() helper
Date: Sun, 13 Aug 2023 17:00:36 +0300 [thread overview]
Message-ID: <nl4xu7tecp3ytntobzkxmnqeraa3lpaveolz7uft6gdzyr4aa6@h4mf4otod3ew> (raw)
In-Reply-To: <20230810111402.1923113-1-ruanjinjie@huawei.com>
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
>
prev parent reply other threads:[~2023-08-13 14:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=nl4xu7tecp3ytntobzkxmnqeraa3lpaveolz7uft6gdzyr4aa6@h4mf4otod3ew \
--to=fancer.lancer@gmail.com \
--cc=allenbh@gmail.com \
--cc=dan.carpenter@linaro.org \
--cc=dave.jiang@intel.com \
--cc=jdmason@kudzu.us \
--cc=jiasheng@iscas.ac.cn \
--cc=machel@vivo.com \
--cc=ntb@lists.linux.dev \
--cc=ruanjinjie@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).