From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Mathias Rav <mathiasrav@gmail.com>
Cc: devel@driverdev.osuosl.org, Oleg Drokin <oleg.drokin@intel.com>,
Andreas Dilger <andreas.dilger@intel.com>,
James Simmons <jsimmons@infradead.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Lustre Development List <lustre-devel@lists.lustre.org>
Subject: Re: [PATCH 1/2] staging: lustre: lprocfs: Use kstrtouint_from_user
Date: Thu, 18 May 2017 15:53:22 +0200 [thread overview]
Message-ID: <20170518135322.GA6772@kroah.com> (raw)
In-Reply-To: <20170504161339.15901-2-mathiasrav@gmail.com>
On Thu, May 04, 2017 at 12:13:38PM -0400, Mathias Rav wrote:
> Prefer kstrtouint_from_user to copy_from_user+simple_strtoul.
>
> The helper function lprocfs_wr_uint() is only used to implement
> "dump_granted_max" in debugfs.
>
> Note the slight change in semantics: The previous implementation using
> simple_strtoul allows garbage after the number, whereas kstrtox only allows
> a trailing line break. The previous implementation allowed a write of zero
> bytes whereas kstrtox will return -EINVAL. Since this only affects a single
> debugfs endpoint, this should be a permissible slight change of semantics
> in exchange for 18 fewer lines of code.
>
> Signed-off-by: Mathias Rav <mathiasrav@gmail.com>
> ---
> .../lustre/lustre/obdclass/lprocfs_status.c | 22 +---------------------
> 1 file changed, 1 insertion(+), 21 deletions(-)
>
> diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
> index 1ec6e3767d81..338ce34d6514 100644
> --- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
> +++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
> @@ -399,27 +399,7 @@ EXPORT_SYMBOL(lprocfs_rd_uint);
> int lprocfs_wr_uint(struct file *file, const char __user *buffer,
> unsigned long count, void *data)
> {
> - unsigned *p = data;
> - char dummy[MAX_STRING_SIZE + 1], *end;
> - unsigned long tmp;
> -
> - if (count >= sizeof(dummy))
> - return -EINVAL;
> -
> - if (count == 0)
> - return 0;
> -
> - if (copy_from_user(dummy, buffer, count))
> - return -EFAULT;
> -
> - dummy[count] = '\0';
> -
> - tmp = simple_strtoul(dummy, &end, 0);
> - if (dummy == end)
> - return -EINVAL;
> -
> - *p = (unsigned int)tmp;
> - return count;
> + return kstrtouint_from_user(buffer, count, 0, (unsigned int *)data);
Why not just delete this whole function and have the callers make this
call instead? No need for unneeded wrapper functions of core kernel
calls.
thanks,
greg k-h
next prev parent reply other threads:[~2017-05-18 13:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-04 16:13 [PATCH 0/2] staging: lustre: lprocfs: Fix coding style issues Mathias Rav
2017-05-04 16:13 ` [PATCH 1/2] staging: lustre: lprocfs: Use kstrtouint_from_user Mathias Rav
2017-05-04 16:13 ` [PATCH 2/2] staging: lustre: lprocfs: Use seq_puts Mathias Rav
2017-05-18 13:53 ` Greg Kroah-Hartman [this message]
2017-05-18 14:48 ` [PATCH 1/2] staging: lustre: lprocfs: Use kstrtouint_from_user Dilger, Andreas
2017-05-18 15:13 ` Mathias Rav
2017-05-19 3:02 ` Dilger, Andreas
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=20170518135322.GA6772@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=andreas.dilger@intel.com \
--cc=devel@driverdev.osuosl.org \
--cc=jsimmons@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lustre-devel@lists.lustre.org \
--cc=mathiasrav@gmail.com \
--cc=oleg.drokin@intel.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