Re: [PATCH 06/10] parse_integer: convert mm/

From: Rasmus Villemoes
Date: Mon May 04 2015 - 10:33:26 EST


On Sat, May 02 2015, Alexey Dobriyan <adobriyan@xxxxxxxxx> 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.

Rasmus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/