linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@gmail.com>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Linux Kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 06/10] parse_integer: convert mm/
Date: Mon, 4 May 2015 18:09:15 +0300	[thread overview]
Message-ID: <CACVxJT_1SVRKmptjnSonabtsEXM3dc8_NgQD9QP9qHV5xX3UBA@mail.gmail.com> (raw)
In-Reply-To: <878ud4if9z.fsf@rasmusvillemoes.dk>

On Mon, May 4, 2015 at 5:33 PM, Rasmus Villemoes
<linux@rasmusvillemoes.dk> wrote:
> On Sat, May 02 2015, Alexey Dobriyan <adobriyan@gmail.com> wrote:
>
>> Convert mm/ directory away from deprecated simple_strto*() interface.
>>
>> One thing to note about parse_integer() and seemingly useless casts --
>> range of accepted values depends on result type.
>>
>>       int val;
>>       parse_integer(s, 0, &val);
>>
>> will accept negative integers, while
>>
>>       int val;
>>       parse_integer(s, 0, (unsigned int *)&val);
>>
>> will accept only 0 and positive integers.
>
> ... and then silently write a negative value to val if the parsed
> integer happens to be larger than INT_MAX.
>
> Again, I think passing cast expressions to parse_integer should be
> verboten.

> In these particular cases:
>
> * memtest_pattern should just be unsigned int - it's only ever used as
>   such anyway, and it represents a count.
>
> * hashdist should be a boolean, but even in its current form, there's no
>   reason to not just use parse_integer as-is. If people like to set it
>   by passing -42 just let them.

In this particular code, maybe. The real use case is this:

    int val = -1; //default
    parse_integer(s, 0, (unsigned int *)&val); //accept unsigned only

Either you add cast here, or cast where you check that value is really
unsigned after parsing:

  int val = -1;
  parse_integer(s, 0, (unsiged int *)&val);
  if (val < 0)
    return -EINVAL;

Overall number of casts is preserved.

Just grep for simple_strto* and see how much error checking people do.
The aim of the patchset is to convert code, error checking is separate story.
I fixed types and added error checks in obvious cases but really:

static int memtest_pattern __initdata;
static int __init parse_memtest(char *arg)
{
        if (arg)
                memtest_pattern = simple_strtoul(arg, NULL, 0);

"int" and strtoul() => developer doesn't care, neither do I.

  reply	other threads:[~2015-05-04 15:09 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-02  0:47 [PATCH 01/10] Add parse_integer() (replacement for simple_strto*()) Alexey Dobriyan
2015-05-02  0:48 ` [PATCH 02/10] parse_integer: rewrite kstrto*() Alexey Dobriyan
2015-05-02  0:50 ` [PATCH 03/10] parse_integer: convert sscanf() Alexey Dobriyan
2015-05-02  1:10   ` [PATCH CORRECT " Alexey Dobriyan
2015-05-02  0:51 ` [PATCH 04/10] sscanf: fix overflow Alexey Dobriyan
2015-05-05  9:51   ` Rasmus Villemoes
2015-05-05 11:10     ` Alexey Dobriyan
2015-05-06  7:49       ` Rasmus Villemoes
2015-05-02  0:53 ` [PATCH 05/10] parse_integer: convert lib/ Alexey Dobriyan
2015-05-04 14:10   ` Rasmus Villemoes
2015-05-04 14:57     ` Alexey Dobriyan
2015-05-02  0:55 ` [PATCH 06/10] parse_integer: convert mm/ Alexey Dobriyan
2015-05-04 14:33   ` Rasmus Villemoes
2015-05-04 15:09     ` Alexey Dobriyan [this message]
2015-05-02  0:56 ` [PATCH 07/10] parse_integer: convert misc fs/ code Alexey Dobriyan
2015-05-02  0:59 ` [PATCH 08/10] fs/cachefiles/: convert to parse_integer() Alexey Dobriyan
2015-05-02  1:01 ` [PATCH 09/10] ocfs2: convert to parse_integer()/kstrto*() Alexey Dobriyan
2015-05-02  1:03 ` [PATCH 10/10] ext2, ext3, ext4: " Alexey Dobriyan
2015-05-04 13:24 ` [PATCH 01/10] Add parse_integer() (replacement for simple_strto*()) Rasmus Villemoes
2015-05-04 14:32   ` Alexey Dobriyan
2015-05-04 16:44     ` Rasmus Villemoes
2015-05-04 19:54       ` Alexey Dobriyan
2015-05-04 21:48         ` Rasmus Villemoes

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=CACVxJT_1SVRKmptjnSonabtsEXM3dc8_NgQD9QP9qHV5xX3UBA@mail.gmail.com \
    --to=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    /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).