12 Oct, 2016

1 commit

  • Set "overflow" bit upon encountering it instead of postponing to the end
    of the conversion. Somehow gcc unwedges itself and generates better code:

    $ ./scripts/bloat-o-meter ../vmlinux-000 ../obj/vmlinux
    _parse_integer 177 139 -38

    Inspired by patch from Zhaoxiu Zeng.

    Link: http://lkml.kernel.org/r/20160826221920.GA1909@p183.telecom.by
    Signed-off-by: Alexey Dobriyan
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexey Dobriyan
     

18 Mar, 2016

2 commits

  • Add support for "on" and "off" when converting to boolean.

    Signed-off-by: Kees Cook
    Cc: Amitkumar Karwar
    Cc: Andy Shevchenko
    Cc: Daniel Borkmann
    Cc: Heiko Carstens
    Cc: Joe Perches
    Cc: Kalle Valo
    Cc: Martin Schwidefsky
    Cc: Michael Ellerman
    Cc: Nishant Sarmukadam
    Cc: Rasmus Villemoes
    Cc: Steve French
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kees Cook
     
  • Create the kstrtobool_from_user() helper and move strtobool() logic into
    the new kstrtobool() (matching all the other kstrto* functions).
    Provides an inline wrapper for existing strtobool() callers.

    Signed-off-by: Kees Cook
    Cc: Joe Perches
    Cc: Andy Shevchenko
    Cc: Rasmus Villemoes
    Cc: Daniel Borkmann
    Cc: Amitkumar Karwar
    Cc: Nishant Sarmukadam
    Cc: Kalle Valo
    Cc: Steve French
    Cc: Michael Ellerman
    Cc: Heiko Carstens
    Cc: Martin Schwidefsky
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kees Cook
     

11 Sep, 2015

1 commit


24 Jan, 2014

1 commit

  • We can't reach the cleanup code unless the flag KSTRTOX_OVERFLOW is not
    set, so there's not no point in clearing a bit that we know is not set.

    Signed-off-by: Felipe Contreras
    Acked-by: Levente Kurusa
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Felipe Contreras
     

18 Dec, 2012

1 commit

  • As Bruce Fields pointed out, kstrto* is currently lacking kerneldoc
    comments. This patch adds kerneldoc comments to common variants of
    kstrto*: kstrto(u)l, kstrto(u)ll and kstrto(u)int.

    Signed-off-by: Eldad Zack
    Cc: J. Bruce Fields
    Cc: Joe Perches
    Cc: Randy Dunlap
    Cc: Alexey Dobriyan
    Cc: Rob Landley
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Eldad Zack
     

08 Mar, 2012

1 commit


10 Feb, 2012

1 commit

  • _parse_integer() does one or two division instructions (which are slow)
    per digit parsed to perform the overflow check.

    Furthermore, these are particularly expensive examples of division
    instruction as the number of clock cycles required to complete them may
    go up with the position of the most significant set bit in the dividend:

    if (*res > div_u64(ULLONG_MAX - val, base))

    which is as maximal as possible.

    Worse, on 32-bit arches, more than one of these division instructions
    may be required per digit.

    So, assuming we don't support a base of more than 16, skip the check if the
    top nibble of the result is not set at this point.

    Signed-off-by: David Howells
    [ Changed it to not dereference the pointer all the time - even if the
    compiler can and does optimize it away, the code just looks cleaner.
    And edited the top nybble test slightly to make the code generated on
    x86-64 better in the loop - test against a hoisted constant instead of
    shifting and testing the result ]
    Signed-off-by: Linus Torvalds

    David Howells
     

01 Nov, 2011

1 commit

  • Currently termination logic (\0 or \n\0) is hardcoded in _kstrtoull(),
    avoid that for code reuse between kstrto*() and simple_strtoull().
    Essentially, make them different only in termination logic.

    simple_strtoull() (and scanf(), BTW) ignores integer overflow, that's a
    bug we currently don't have guts to fix, making KSTRTOX_OVERFLOW hack
    necessary.

    Almost forgot: patch shrinks code size by about ~80 bytes on x86_64.

    Signed-off-by: Alexey Dobriyan
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexey Dobriyan
     

26 Jul, 2011

1 commit

  • This function is required by *printf and kstrto* functions that are
    located in the different modules. This patch makes _tolower() public.
    However, it's good idea to not use the helper outside of mentioned
    functions.

    [akpm@linux-foundation.org: coding-style fixes]
    Signed-off-by: Andy Shevchenko
    Acked-by: Alexey Dobriyan
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andy Shevchenko
     

25 May, 2011

1 commit

  • There is quite a lot of code which does copy_from_user() + strict_strto*()
    or simple_strto*() combo in slightly different ways.

    Before doing conversions all over tree, let's get final API correct.

    Enter kstrtoull_from_user() and friends.

    Typical code which uses them looks very simple:

    TYPE val;
    int rv;

    rv = kstrtoTYPE_from_user(buf, count, 0, &val);
    if (rv < 0)
    return rv;
    [use val]
    return count;

    There is a tiny semantic difference from the plain kstrto*() API -- the
    latter allows any amount of leading zeroes, while the former copies data
    into buffer on stack and thus allows leading zeroes as long as it fits
    into buffer.

    This shouldn't be a problem for typical usecase "echo 42 > /proc/x".

    The point is to make reading one integer from userspace _very_ simple and
    very bug free.

    Signed-off-by: Alexey Dobriyan
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexey Dobriyan
     

15 Apr, 2011

1 commit


23 Mar, 2011

1 commit

  • 1. simple_strto*() do not contain overflow checks and crufty,
    libc way to indicate failure.
    2. strict_strto*() also do not have overflow checks but the name and
    comments pretend they do.
    3. Both families have only "long long" and "long" variants,
    but users want strtou8()
    4. Both "simple" and "strict" prefixes are wrong:
    Simple doesn't exactly say what's so simple, strict should not exist
    because conversion should be strict by default.

    The solution is to use "k" prefix and add convertors for more types.
    Enter
    kstrtoull()
    kstrtoll()
    kstrtoul()
    kstrtol()
    kstrtouint()
    kstrtoint()

    kstrtou64()
    kstrtos64()
    kstrtou32()
    kstrtos32()
    kstrtou16()
    kstrtos16()
    kstrtou8()
    kstrtos8()

    Include runtime testsuite (somewhat incomplete) as well.

    strict_strto*() become deprecated, stubbed to kstrto*() and
    eventually will be removed altogether.

    Use kstrto*() in code today!

    Note: on some archs _kstrtoul() and _kstrtol() are left in tree, even if
    they'll be unused at runtime. This is temporarily solution,
    because I don't want to hardcode list of archs where these
    functions aren't needed. Current solution with sizeof() and
    __alignof__ at least always works.

    Signed-off-by: Alexey Dobriyan
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexey Dobriyan