Re: [PATCH 1/3] Add a kstrtobool function matching semantics ofexisting in kernel equivalents.

From: Alexey Dobriyan
Date: Wed Mar 23 2011 - 11:30:21 EST


On Wed, Mar 23, 2011 at 3:39 PM, Jonathan Cameron <jic23@xxxxxxxxx> wrote:
> +int kstrtobool(const char *s, bool *res)
> +{
> +       switch (s[0]) {
> +       case 'y':
> +       case 'Y':
> +       case '1':
> +               *res = true;
> +       case 'n':
> +       case 'N':
> +       case '0':
> +               *res = false;
> +       default:
> +               return -EINVAL;
> +       }
> +       return 0;
> +}

sigh... such simple thing and so many bugs

The only values such function should accept is 0 and 1.

Have you read the rest of kstrto*() code?
Where is newline check?

Anyway, I think it's better do not exist.
--
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/