18 Mar, 2016

2 commits

  • 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
     
  • Occasionally we have to search for an occurrence of a string in an array
    of strings. Make a simple helper for that purpose.

    Signed-off-by: Andy Shevchenko
    Cc: "David S. Miller"
    Cc: Bartlomiej Zolnierkiewicz
    Cc: David Airlie
    Cc: David Woodhouse
    Cc: Dmitry Eremin-Solenikov
    Cc: Greg Kroah-Hartman
    Cc: Heikki Krogerus
    Cc: Linus Walleij
    Cc: Mika Westerberg
    Cc: Rafael J. Wysocki
    Cc: Sebastian Reichel
    Cc: Tejun Heo
    Cc: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andy Shevchenko
     

11 Nov, 2015

1 commit


07 Oct, 2015

1 commit


11 Sep, 2015

1 commit

  • The strscpy() API is intended to be used instead of strlcpy(),
    and instead of most uses of strncpy().

    - Unlike strlcpy(), it doesn't read from memory beyond (src + size).

    - Unlike strlcpy() or strncpy(), the API provides an easy way to check
    for destination buffer overflow: an -E2BIG error return value.

    - The provided implementation is robust in the face of the source
    buffer being asynchronously changed during the copy, unlike the
    current implementation of strlcpy().

    - Unlike strncpy(), the destination buffer will be NUL-terminated
    if the string in the source buffer is too long.

    - Also unlike strncpy(), the destination buffer will not be updated
    beyond the NUL termination, avoiding strncpy's behavior of zeroing
    the entire tail end of the destination buffer. (A memset() after
    the strscpy() can be used if this behavior is desired.)

    - The implementation should be reasonably performant on all
    platforms since it uses the asm/word-at-a-time.h API rather than
    simple byte copy. Kernel-to-kernel string copy is not considered
    to be performance critical in any case.

    Signed-off-by: Chris Metcalf

    Chris Metcalf
     

26 Jun, 2015

1 commit

  • Strings are sometimes sanitized by replacing a certain character (often
    '/') by another (often '!'). In a few places, this is done the same way
    Schlemiel the Painter would do it. Others are slightly smarter but still
    do multiple strchr() calls. Introduce strreplace() to do this using a
    single function call and a single pass over the string.

    One would expect the return value to be one of three things: void, s, or
    the number of replacements made. I chose the fourth, returning a pointer
    to the end of the string. This is more likely to be useful (for example
    allowing the caller to avoid a strlen call).

    Signed-off-by: Rasmus Villemoes
    Cc: "Theodore Ts'o"
    Cc: Greg Kroah-Hartman
    Cc: Neil Brown
    Cc: Steven Rostedt
    Cc: Joe Perches
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     

04 May, 2015

1 commit

  • In commit 0b053c951829 ("lib: memzero_explicit: use barrier instead
    of OPTIMIZER_HIDE_VAR"), we made memzero_explicit() more robust in
    case LTO would decide to inline memzero_explicit() and eventually
    find out it could be elimiated as dead store.

    While using barrier() works well for the case of gcc, recent efforts
    from LLVMLinux people suggest to use llvm as an alternative to gcc,
    and there, Stephan found in a simple stand-alone user space example
    that llvm could nevertheless optimize and thus elimitate the memset().
    A similar issue has been observed in the referenced llvm bug report,
    which is regarded as not-a-bug.

    Based on some experiments, icc is a bit special on its own, while it
    doesn't seem to eliminate the memset(), it could do so with an own
    implementation, and then result in similar findings as with llvm.

    The fix in this patch now works for all three compilers (also tested
    with more aggressive optimization levels). Arguably, in the current
    kernel tree it's more of a theoretical issue, but imho, it's better
    to be pedantic about it.

    It's clearly visible with gcc/llvm though, with the below code: if we
    would have used barrier() only here, llvm would have omitted clearing,
    not so with barrier_data() variant:

    static inline void memzero_explicit(void *s, size_t count)
    {
    memset(s, 0, count);
    barrier_data(s);
    }

    int main(void)
    {
    char buff[20];
    memzero_explicit(buff, sizeof(buff));
    return 0;
    }

    $ gcc -O2 test.c
    $ gdb a.out
    (gdb) disassemble main
    Dump of assembler code for function main:
    0x0000000000400400 : lea -0x28(%rsp),%rax
    0x0000000000400405 : movq $0x0,-0x28(%rsp)
    0x000000000040040e : movq $0x0,-0x20(%rsp)
    0x0000000000400417 : movl $0x0,-0x18(%rsp)
    0x000000000040041f : xor %eax,%eax
    0x0000000000400421 : retq
    End of assembler dump.

    $ clang -O2 test.c
    $ gdb a.out
    (gdb) disassemble main
    Dump of assembler code for function main:
    0x00000000004004f0 : xorps %xmm0,%xmm0
    0x00000000004004f3 : movaps %xmm0,-0x18(%rsp)
    0x00000000004004f8 : movl $0x0,-0x8(%rsp)
    0x0000000000400500 : lea -0x18(%rsp),%rax
    0x0000000000400505 : xor %eax,%eax
    0x0000000000400507 : retq
    End of assembler dump.

    As gcc, clang, but also icc defines __GNUC__, it's sufficient to define
    this in compiler-gcc.h only to be picked up. For a fallback or otherwise
    unsupported compiler, we define it as a barrier. Similarly, for ecc which
    does not support gcc inline asm.

    Reference: https://llvm.org/bugs/show_bug.cgi?id=15495
    Reported-by: Stephan Mueller
    Tested-by: Stephan Mueller
    Signed-off-by: Daniel Borkmann
    Cc: Theodore Ts'o
    Cc: Stephan Mueller
    Cc: Hannes Frederic Sowa
    Cc: mancha security
    Cc: Mark Charlebois
    Cc: Behan Webster
    Signed-off-by: Herbert Xu

    Daniel Borkmann
     

20 Mar, 2015

1 commit

  • OPTIMIZER_HIDE_VAR(), as defined when using gcc, is insufficient to
    ensure protection from dead store optimization.

    For the random driver and crypto drivers, calls are emitted ...

    $ gdb vmlinux
    (gdb) disassemble memzero_explicit
    Dump of assembler code for function memzero_explicit:
    0xffffffff813a18b0 : push %rbp
    0xffffffff813a18b1 : mov %rsi,%rdx
    0xffffffff813a18b4 : xor %esi,%esi
    0xffffffff813a18b6 : mov %rsp,%rbp
    0xffffffff813a18b9 : callq 0xffffffff813a7120
    0xffffffff813a18be : pop %rbp
    0xffffffff813a18bf : retq
    End of assembler dump.

    (gdb) disassemble extract_entropy
    [...]
    0xffffffff814a5009 : mov %r12,%rdi
    0xffffffff814a500c : mov $0xa,%esi
    0xffffffff814a5011 : callq 0xffffffff813a18b0
    0xffffffff814a5016 : mov -0x48(%rbp),%rax
    [...]

    ... but in case in future we might use facilities such as LTO, then
    OPTIMIZER_HIDE_VAR() is not sufficient to protect gcc from a possible
    eviction of the memset(). We have to use a compiler barrier instead.

    Minimal test example when we assume memzero_explicit() would *not* be
    a call, but would have been *inlined* instead:

    static inline void memzero_explicit(void *s, size_t count)
    {
    memset(s, 0, count);

    }

    int main(void)
    {
    char buff[20];

    snprintf(buff, sizeof(buff) - 1, "test");
    printf("%s", buff);

    memzero_explicit(buff, sizeof(buff));
    return 0;
    }

    With := OPTIMIZER_HIDE_VAR():

    (gdb) disassemble main
    Dump of assembler code for function main:
    [...]
    0x0000000000400464 : callq 0x400410
    0x0000000000400469 : xor %eax,%eax
    0x000000000040046b : add $0x28,%rsp
    0x000000000040046f : retq
    End of assembler dump.

    With := barrier():

    (gdb) disassemble main
    Dump of assembler code for function main:
    [...]
    0x0000000000400464 : callq 0x400410
    0x0000000000400469 : movq $0x0,(%rsp)
    0x0000000000400471 : movq $0x0,0x8(%rsp)
    0x000000000040047a : movl $0x0,0x10(%rsp)
    0x0000000000400482 : xor %eax,%eax
    0x0000000000400484 : add $0x28,%rsp
    0x0000000000400488 : retq
    End of assembler dump.

    As can be seen, movq, movq, movl are being emitted inlined
    via memset().

    Reference: http://thread.gmane.org/gmane.linux.kernel.cryptoapi/13764/
    Fixes: d4c5efdb9777 ("random: add and use memzero_explicit() for clearing data")
    Cc: Theodore Ts'o
    Signed-off-by: mancha security
    Signed-off-by: Daniel Borkmann
    Acked-by: Hannes Frederic Sowa
    Acked-by: Stephan Mueller
    Signed-off-by: Herbert Xu

    mancha security
     

15 Feb, 2015

1 commit

  • Pull crypto update from Herbert Xu:
    "Here is the crypto update for 3.20:

    - Added 192/256-bit key support to aesni GCM.
    - Added MIPS OCTEON MD5 support.
    - Fixed hwrng starvation and race conditions.
    - Added note that memzero_explicit is not a subsitute for memset.
    - Added user-space interface for crypto_rng.
    - Misc fixes"

    * git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (71 commits)
    crypto: tcrypt - do not allocate iv on stack for aead speed tests
    crypto: testmgr - limit IV copy length in aead tests
    crypto: tcrypt - fix buflen reminder calculation
    crypto: testmgr - mark rfc4106(gcm(aes)) as fips_allowed
    crypto: caam - fix resource clean-up on error path for caam_jr_init
    crypto: caam - pair irq map and dispose in the same function
    crypto: ccp - terminate ccp_support array with empty element
    crypto: caam - remove unused local variable
    crypto: caam - remove dead code
    crypto: caam - don't emit ICV check failures to dmesg
    hwrng: virtio - drop extra empty line
    crypto: replace scatterwalk_sg_next with sg_next
    crypto: atmel - Free memory in error path
    crypto: doc - remove colons in comments
    crypto: seqiv - Ensure that IV size is at least 8 bytes
    crypto: cts - Weed out non-CBC algorithms
    MAINTAINERS: add linux-crypto to hw random
    crypto: cts - Remove bogus use of seqiv
    crypto: qat - don't need qat_auth_state struct
    crypto: algif_rng - fix sparse non static symbol warning
    ...

    Linus Torvalds
     

14 Feb, 2015

1 commit

  • Instead of potentially passing over the string twice in case c is not
    found, just keep track of the last occurrence. According to
    bloat-o-meter, this also cuts the generated code by a third (54 vs 36
    bytes). Oh, and we get rid of those 7-space indented lines.

    Signed-off-by: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     

13 Feb, 2015

1 commit

  • Now that all in-tree users of strnicmp have been converted to
    strncasecmp, the wrapper can be removed.

    Signed-off-by: Rasmus Villemoes
    Cc: David Howells
    Cc: Heiko Carstens
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     

08 Jan, 2015

1 commit

  • Lets improve the comment to add a note on when to use memzero_explicit()
    for those not digging through the git logs. We don't want people to
    pollute places with memzero_explicit() where it's not really necessary.

    Reference: https://lkml.org/lkml/2015/1/4/190
    Suggested-by: Herbert Xu
    Signed-off-by: Daniel Borkmann
    Signed-off-by: Herbert Xu

    Daniel Borkmann
     

25 Oct, 2014

1 commit


17 Oct, 2014

1 commit

  • zatimend has reported that in his environment (3.16/gcc4.8.3/corei7)
    memset() calls which clear out sensitive data in extract_{buf,entropy,
    entropy_user}() in random driver are being optimized away by gcc.

    Add a helper memzero_explicit() (similarly as explicit_bzero() variants)
    that can be used in such cases where a variable with sensitive data is
    being cleared out in the end. Other use cases might also be in crypto
    code. [ I have put this into lib/string.c though, as it's always built-in
    and doesn't need any dependencies then. ]

    Fixes kernel bugzilla: 82041

    Reported-by: zatimend@hotmail.co.uk
    Signed-off-by: Daniel Borkmann
    Acked-by: Hannes Frederic Sowa
    Cc: Alexey Dobriyan
    Signed-off-by: Theodore Ts'o
    Cc: stable@vger.kernel.org

    Daniel Borkmann
     

14 Oct, 2014

2 commits

  • The previous patch made strnicmp into a wrapper for strncasecmp.

    This patch makes all in-tree users of strnicmp call strncasecmp
    directly, while still making sure that the strnicmp symbol can be used
    by out-of-tree modules. It should be considered a temporary hack until
    all in-tree callers have been converted.

    Signed-off-by: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     
  • lib/string.c contains two functions, strnicmp and strncasecmp, which do
    roughly the same thing, namely compare two strings case-insensitively up
    to a given bound. They have slightly different implementations, but the
    only important difference is that strncasecmp doesn't handle len==0
    appropriately; it effectively becomes strcasecmp in that case. strnicmp
    correctly says that two strings are always equal in their first 0
    characters.

    strncasecmp is the POSIX name for this functionality. So rename the
    non-broken function to the standard name. To minimize the impact on the
    rest of the kernel (and since both are exported to modules), make strnicmp
    a wrapper for strncasecmp.

    Signed-off-by: Rasmus Villemoes
    Cc: Grant Likely
    Cc: Andi Kleen
    Cc: Dan Carpenter
    Cc: "H. Peter Anvin"
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     

14 Sep, 2014

1 commit

  • It used to be an ad-hoc hack defined by the x86 version of
    that enabled a couple of library routines to know whether
    an integer multiply is faster than repeated shifts and additions.

    This just makes it use the real Kconfig system instead, and makes x86
    (which was the only architecture that did this) select the option.

    NOTE! Even for x86, this really is kind of wrong. If we cared, we would
    probably not enable this for builds optimized for netburst (P4), where
    shifts-and-adds are generally faster than multiplies. This patch does
    *not* change that kind of logic, though, it is purely a syntactic change
    with no code changes.

    This was triggered by the fact that we have other places that really
    want to know "do I want to expand multiples by constants by hand or
    not", particularly the hash generation code.

    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

05 Jun, 2014

1 commit

  • For strncpy() and friends the source string may or may not have an actual
    NUL character at the end. The documentation is confusing in this because
    it specifically mentions that you are passing a "NUL-terminated" string.
    Wikipedia says that "C-string" is an alternative name we can use instead.

    http://en.wikipedia.org/wiki/Null-terminated_string

    Signed-off-by: Dan Carpenter
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Dan Carpenter
     

23 May, 2014

1 commit

  • The strchrnul() variant helpfully returns a the end of the string
    instead of a NULL if the requested character is not found. This can
    simplify string parsing code since it doesn't need to expicitly check
    for a NULL return. If a valid string pointer is passed in, then a valid
    null terminated string will always come back out.

    Signed-off-by: Grant Likely

    Grant Likely
     

14 Feb, 2014

1 commit

  • In LTO symbols implicitely referenced by the compiler need
    to be visible. Earlier these symbols were visible implicitely
    from being exported, but we disabled implicit visibility fo
    EXPORTs when modules are disabled to improve code size. So
    now these symbols have to be marked visible explicitely.

    Do this for __stack_chk_fail (with stack protector)
    and memcmp.

    Signed-off-by: Andi Kleen
    Link: http://lkml.kernel.org/r/1391845930-28580-10-git-send-email-ak@linux.intel.com
    Signed-off-by: H. Peter Anvin

    Andi Kleen
     

25 Mar, 2012

2 commits

  • Pull cleanup of fs/ and lib/ users of module.h from Paul Gortmaker:
    "Fix up files in fs/ and lib/ dirs to only use module.h if they really
    need it.

    These are trivial in scope vs the work done previously. We now have
    things where any few remaining cleanups can be farmed out to arch or
    subsystem maintainers, and I have done so when possible. What is
    remaining here represents the bits that don't clearly lie within a
    single arch/subsystem boundary, like the fs dir and the lib dir.

    Some duplicate includes arising from overlapping fixes from
    independent subsystem maintainer submissions are also quashed."

    Fix up trivial conflicts due to clashes with other include file cleanups
    (including some due to the previous bug.h cleanup pull).

    * tag 'module-for-3.4' of git://git.kernel.org/pub/scm/linux/kernel/git/paulg/linux:
    lib: reduce the use of module.h wherever possible
    fs: reduce the use of module.h wherever possible
    includecheck: delete any duplicate instances of module.h

    Linus Torvalds
     
  • Pull cleanup from Paul Gortmaker:
    "The changes shown here are to unify linux's BUG support under the one
    file. Due to historical reasons, we have some BUG code
    in bug.h and some in kernel.h -- i.e. the support for BUILD_BUG in
    linux/kernel.h predates the addition of linux/bug.h, but old code in
    kernel.h wasn't moved to bug.h at that time. As a band-aid, kernel.h
    was including to pseudo link them.

    This has caused confusion[1] and general yuck/WTF[2] reactions. Here
    is an example that violates the principle of least surprise:

    CC lib/string.o
    lib/string.c: In function 'strlcat':
    lib/string.c:225:2: error: implicit declaration of function 'BUILD_BUG_ON'
    make[2]: *** [lib/string.o] Error 1
    $
    $ grep linux/bug.h lib/string.c
    #include
    $

    We've included for the BUG infrastructure and yet we
    still get a compile fail! [We've not kernel.h for BUILD_BUG_ON.] Ugh -
    very confusing for someone who is new to kernel development.

    With the above in mind, the goals of this changeset are:

    1) find and fix any include/*.h files that were relying on the
    implicit presence of BUG code.
    2) find and fix any C files that were consuming kernel.h and hence
    relying on implicitly getting some/all BUG code.
    3) Move the BUG related code living in kernel.h to
    4) remove the asm/bug.h from kernel.h to finally break the chain.

    During development, the order was more like 3-4, build-test, 1-2. But
    to ensure that git history for bisect doesn't get needless build
    failures introduced, the commits have been reorderd to fix the problem
    areas in advance.

    [1] https://lkml.org/lkml/2012/1/3/90
    [2] https://lkml.org/lkml/2012/1/17/414"

    Fix up conflicts (new radeon file, reiserfs header cleanups) as per Paul
    and linux-next.

    * tag 'bug-for-3.4' of git://git.kernel.org/pub/scm/linux/kernel/git/paulg/linux:
    kernel.h: doesn't explicitly use bug.h, so don't include it.
    bug: consolidate BUILD_BUG_ON with other bug code
    BUG: headers with BUG/BUG_ON etc. need linux/bug.h
    bug.h: add include of it to various implicit C users
    lib: fix implicit users of kernel.h for TAINT_WARN
    spinlock: macroize assert_spin_locked to avoid bug.h dependency
    x86: relocate get/set debugreg fcns to include/asm/debugreg.

    Linus Torvalds
     

24 Mar, 2012

1 commit

  • - Generate a 64-bit pattern more efficiently

    memchr_inv needs to generate a 64-bit pattern filled with a target
    character. The operation can be done by more efficient way.

    - Don't call the slow check_bytes() if the memory area is 64-bit aligned

    memchr_inv compares contiguous 64-bit words with the 64-bit pattern as
    much as possible. The outside of the region is checked by check_bytes()
    that scans for each byte. Unfortunately, the first 64-bit word is
    unexpectedly scanned by check_bytes() even if the memory area is aligned
    to a 64-bit boundary.

    Both changes were originally suggested by Eric Dumazet.

    Signed-off-by: Akinobu Mita
    Suggested-by: Eric Dumazet
    Cc: Brian Norris
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Akinobu Mita
     

08 Mar, 2012

1 commit


01 Mar, 2012

1 commit


01 Nov, 2011

2 commits

  • Commit 84c95c9acf0 ("string: on strstrip(), first remove leading spaces
    before running over str") improved the performance of the strim()
    function.

    Unfortunately this changed the semantics of strim() and broke my code.
    Before the patch it was possible to use strim() without using the return
    value for removing trailing spaces from strings that had either only
    blanks or only trailing blanks.

    Now this does not work any longer for strings that *only* have blanks.

    Before patch: " " -> "" (empty string)
    After patch: " " -> " " (no change)

    I think we should remove your patch to restore the old behavior.

    The description (lib/string.c):

    * Note that the first trailing whitespace is replaced with a %NUL-terminator

    => The first trailing whitespace of a string that only has whitespace
    characters is the first whitespace

    The patch restores the old strim() semantics.

    Signed-off-by: Michael Holzheu
    Cc: Andre Goddard Rosa
    Cc: Martin Schwidefsky
    Cc: Heiko Carstens
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michael Holzheu
     
  • memchr_inv() is mainly used to check whether the whole buffer is filled
    with just a specified byte.

    The function name and prototype are stolen from logfs and the
    implementation is from SLUB.

    Signed-off-by: Akinobu Mita
    Acked-by: Christoph Lameter
    Acked-by: Pekka Enberg
    Cc: Matt Mackall
    Acked-by: Joern Engel
    Cc: Marcin Slusarz
    Cc: Eric Dumazet
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Akinobu Mita
     

19 May, 2011

1 commit


07 Mar, 2010

2 commits


15 Jan, 2010

1 commit

  • It differs strstr() in that it limits the length to be searched
    in the first string.

    Signed-off-by: Li Zefan
    LKML-Reference:
    Acked-by: Frederic Weisbecker
    Signed-off-by: Steven Rostedt

    Li Zefan
     

23 Dec, 2009

1 commit

  • Fix kernel-doc warnings (@arg name) in string.c::skip_spaces().

    Warning(lib/string.c:347): No description found for parameter 'str'
    Warning(lib/string.c:347): Excess function parameter 's' description in 'skip_spaces'

    Signed-off-by: Randy Dunlap
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Randy Dunlap
     

16 Dec, 2009

3 commits

  • Recently, We marked strstrip() as must_check. because it was frequently
    misused and it should be checked. However, we found one exception.
    scsi/ipr.c intentionally ignore return value of strstrip. Because it
    wishes to keep the whitespace at the beginning.

    Thus we need to keep with and without checked whitespace trim function.
    This patch adds a new strim() and changes ipr.c to use it.

    [akpm@linux-foundation.org: coding-style fixes]
    Suggested-by: Alan Cox
    Signed-off-by: KOSAKI Motohiro
    Cc: James Bottomley
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    KOSAKI Motohiro
     
  • ... so that strlen() iterates over a smaller string comprising of the
    remaining characters only.

    Signed-off-by: André Goddard Rosa
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    André Goddard Rosa
     
  • On the following sentence:
    while (*s && isspace(*s))
    s++;

    If *s == 0, isspace() evaluates to ((_ctype[*s] & 0x20) != 0), which
    evaluates to ((0x08 & 0x20) != 0) which equals to 0 as well.
    If *s == 1, we depend on isspace() result anyway. In other words,
    "a char equals zero is never a space", so remove this check.

    Also, *s != 0 is most common case (non-null string).

    Fixed const return as noticed by Jan Engelhardt and James Bottomley.
    Fixed unnecessary extra cast on strstrip() as noticed by Jan Engelhardt.

    Signed-off-by: André Goddard Rosa
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    André Goddard Rosa
     

19 Nov, 2009

1 commit

  • Doing the strcmp return value as

    signed char __res = *cs - *ct;

    is wrong for two reasons. The subtraction can overflow because __res
    doesn't use a type big enough. Moreover the compared bytes should be
    interpreted as unsigned char as specified by POSIX.

    The same problem is fixed in strncmp.

    Signed-off-by: Uwe Kleine-König
    Cc: Michael Buesch
    Cc: Andreas Schwab
    Cc: Andrew Morton
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

01 May, 2008

1 commit

  • Add a new sysfs_streq() string comparison function, which ignores
    the trailing newlines found in sysfs inputs. By example:

    sysfs_streq("a", "b") ==> false
    sysfs_streq("a", "a") ==> true
    sysfs_streq("a", "a\n") ==> true
    sysfs_streq("a\n", "a") ==> true

    This is intended to simplify parsing of sysfs inputs, letting them
    avoid the need to manually strip off newlines from inputs.

    Signed-off-by: David Brownell
    Acked-by: Greg KH
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    David Brownell
     

26 Apr, 2007

1 commit


12 Feb, 2007

1 commit

  • A variety of (mostly) innocuous fixes to the embedded kernel-doc content in
    source files, including:

    * make multi-line initial descriptions single line
    * denote some function names, constants and structs as such
    * change erroneous opening '/*' to '/**' in a few places
    * reword some text for clarity

    Signed-off-by: Robert P. J. Day
    Cc: "Randy.Dunlap"
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Robert P. J. Day
     

29 Oct, 2006

1 commit

  • strstrip() does not remove the last blank from strings which only consist
    of blanks.

    Example:
    char string[] = " ";
    strstrip(string);

    results in " ", but should produce an empty string!

    The following patch solves this problem:

    Acked-by: Martin Schwidefsky
    Signed-off-by: Michael Holzheu
    Acked-by: Pekka Enberg
    Acked-by Joern Engel
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michael Holzheu