From: Satyam Sharma <satyam@infradead.org>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH -mm] Introduce strtol_check_range()
Date: Thu, 2 Aug 2007 05:16:59 +0530 (IST) [thread overview]
Message-ID: <alpine.LFD.0.999.0708020454440.8258@enigma.security.iitk.ac.in> (raw)
In-Reply-To: <20070801053509.GA5905@martell.zuzino.mipt.ru>
Hi Alexey,
On Wed, 1 Aug 2007, Alexey Dobriyan wrote:
> On Tue, Jul 31, 2007 at 10:04:10PM +0530, Satyam Sharma wrote:
> > Callers (especially "store" functions for sysfs or configfs attributes)
> > that want to convert an input string to a number may often also want to
> > check for simple input sanity or allowable range. strtol10_check_range()
> > of netconsole does this, so extract it out into lib/vsprintf.c, make it
> > generic w.r.t. base, and export it to the rest of the kernel and modules.
>
> > --- a/drivers/net/netconsole.c
> > +++ b/drivers/net/netconsole.c
> > @@ -335,9 +307,11 @@ static ssize_t store_enabled(struct netconsole_target *nt,
> > int err;
> > long enabled;
> >
> > - enabled = strtol10_check_range(buf, 0, 1);
> > - if (enabled < 0)
> > + enabled = strtol_check_range(buf, 0, 1, 10);
> > + if (enabled < 0) {
> > + printk(KERN_ERR "netconsole: invalid input\n");
> > return enabled;
> > + }
>
> Please, copy strtonum() from BSD instead. Nobody needs another
> home-grown converter.
BSD's strtonum(3) is a detestful, horrible shame.
The strtol_check_range() I implemented here does _all_ that strtonum()
does, plus is generic w.r.t. base, and minus the tasteless "errstr"
argument.
Tell me, how does that "errstr" ever make sense? We _anyway_ return
errors (-EINVAL or -ERANGE) if any of those cases show up. And
_because_ we use negative numbers to return errors, we can't use this
function to convert negative inputs anyway ... an appropriate error
message can always be outputted by the caller itself. [ hence the
two WARN_ON's I added here ]
But yeah, considering this implementation is so similar to strtonum(3)
(minus the shortcomings, that is :-) we can probably rename it to
something like kstrtonum() ... and we should probably be returning
different errors for the two invalid conditions, yes.
Thanks,
Satyam
next prev parent reply other threads:[~2007-08-01 23:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-31 16:34 Satyam Sharma
2007-07-31 19:02 ` Andrew Morton
2007-08-01 5:35 ` Alexey Dobriyan
2007-08-01 23:46 ` Satyam Sharma [this message]
2007-08-02 0:22 ` Satyam Sharma
2007-08-02 4:25 ` Alexey Dobriyan
2007-08-02 10:13 ` Denis Vlasenko
2007-08-03 7:59 ` Jan Engelhardt
2007-08-03 8:59 ` Satyam Sharma
2007-08-04 22:49 ` Alexey Dobriyan
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=alpine.LFD.0.999.0708020454440.8258@enigma.security.iitk.ac.in \
--to=satyam@infradead.org \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®