linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@cam.ac.uk>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: JJ Ding <jj_ding@emc.com.tw>,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org,
	JJ Ding <dgdunix@gmail.com>
Subject: Re: [PATCH v2] Input: convert obsolete strict_strtox to kstrtox
Date: Tue, 08 Nov 2011 21:33:21 +0000	[thread overview]
Message-ID: <4EB9A021.6000705@cam.ac.uk> (raw)
In-Reply-To: <CAKdAkRR+kmxBzmhBJ80F4pMTbf_oQWiUh-hXaG2tQMRynmWP3A@mail.gmail.com>

On 11/08/2011 06:41 PM, Dmitry Torokhov wrote:
> On Tue, Nov 8, 2011 at 12:47 AM, JJ Ding <jj_ding@emc.com.tw> wrote:
>> On Tue, 08 Nov 2011 15:47:36 +0800, JJ Ding <jj_ding@emc.com.tw> wrote:
>>> On Mon, 7 Nov 2011 22:28:01 -0800, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
>>>> On Mon, Nov 07, 2011 at 07:59:30PM -0800, Dmitry Torokhov wrote:
>>>>>
>>>>> Applied, thanks JJ.
>>>>>
>>>>
>>>> Sorry, I take it back...
>>>>
>>>>> -       if (strict_strtoul(buf, 10, &value) || value > 1)
>>>>> +       if (kstrtouint(buf, 10, &value) || value > 1)
>>>>>                 return -EINVAL;
>>>>
>>>> This mangles error condition from kstrtouint and reporting conditions
>>>> beside -EINVAL was the reason for introducing new API IIRC. The proper
>>>> conversion should be:
>>>>
>>>>     err = kstrtouint(buf, 10, &value);
>>>>     if (err)
>>>>             return err;
>>>>
>>>>     if (value > 1)
>>>>             return -EINVAL;
>>>>
>>>> Thanks.
>>>>
>>>
>>> Thanks, I get it. I'll fix and resend.
>>>
>>> jj
>>>
>>
>> Thinking a bit more about your suggestion, and looking at the code more
>> closely, some uses of these conversions really want a u8, and some want a
>> bool. I think I should check the data type where these converted values
>> are really used, and use a more appropriate kstrtox.
> 
> If some really want full u8 range then yes, I agree, kstrtou8 is best. For
> ones where we have just a few valid values I think we should stick with
> conversing to unsigned int and then validate the range manually.
> 
>>
>> And for those that just need a bool, do you think using strtobool
>> introduced in commit d0f1fed29e6e73d9d17f4c91a5896a4ce3938d45 OK?
>> That way the user may even type [NnYy01].
> 
> I do not like strtobool because it is sloppy. It will also accept 10, yoda, nada
> and similar inputs as correct.
> 
plenty of room for kstrtobool if anyone wants to take it on...


      reply	other threads:[~2011-11-08 21:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-07 11:54 [PATCH v2] Input: convert obsolete strict_strtox to kstrtox JJ Ding
2011-11-08  3:59 ` Dmitry Torokhov
2011-11-08  6:28   ` Dmitry Torokhov
2011-11-08  7:47     ` JJ Ding
2011-11-08  8:47       ` JJ Ding
2011-11-08 18:41         ` Dmitry Torokhov
2011-11-08 21:33           ` Jonathan Cameron [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=4EB9A021.6000705@cam.ac.uk \
    --to=jic23@cam.ac.uk \
    --cc=dgdunix@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jj_ding@emc.com.tw \
    --cc=linux-input@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).