1. 30 Apr, 2013 1 commit
    • Oleg Nesterov's avatar
      argv_split(): teach it to handle mutable strings · 095d141b
      Oleg Nesterov authored
      argv_split() allocates argv[count_argc(str)] array and assumes that it
      will find the same number of arguments later.  This is obviously wrong if
      this string can be changed, say, by sysctl.
      
      With this patch argv_split() kstrndup's the whole string and does not
      split it, we simply replace the spaces with zeroes and keep the allocated
      memory in argv[-1] for argv_free(arg).
      
      We do not use argv[0] because:
      
      	- str can be all-spaces or empty. In fact this case is fine,
      	  we could kfree() it before return, but:
      
      	- str can have a space at the start, and we can not rely on
      	  kstrndup(skip_spaces(str)) because it can equally race if
      	  this string is mutable.
      
      Also, simplify count_argc() and kill the no longer used skip_arg().
      Signed-off-by: 's avatarOleg Nesterov <oleg@redhat.com>
      Cc: Andi Kleen <andi@firstfloor.org>
      Signed-off-by: 's avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: 's avatarLinus Torvalds <torvalds@linux-foundation.org>
      095d141b
  2. 07 Mar, 2012 1 commit
  3. 15 Dec, 2009 1 commit
    • André Goddard Rosa's avatar
      tree-wide: convert open calls to remove spaces to skip_spaces() lib function · e7d2860b
      André Goddard Rosa authored
      Makes use of skip_spaces() defined in lib/string.c for removing leading
      spaces from strings all over the tree.
      
      It decreases lib.a code size by 47 bytes and reuses the function tree-wide:
         text    data     bss     dec     hex filename
        64688     584     592   65864   10148 (TOTALS-BEFORE)
        64641     584     592   65817   10119 (TOTALS-AFTER)
      
      Also, while at it, if we see (*str && isspace(*str)), we can be sure to
      remove the first condition (*str) as the second one (isspace(*str)) also
      evaluates to 0 whenever *str == 0, making it redundant. In other words,
      "a char equals zero is never a space".
      
      Julia Lawall tried the semantic patch (http://coccinelle.lip6.fr) below,
      and found occurrences of this pattern on 3 more files:
          drivers/leds/led-class.c
          drivers/leds/ledtrig-timer.c
          drivers/video/output.c
      
      @@
      expression str;
      @@
      
      ( // ignore skip_spaces cases
      while (*str &&  isspace(*str)) { \(str++;\|++str;\) }
      |
      - *str &&
      isspace(*str)
      )
      Signed-off-by: 's avatarAndré Goddard Rosa <andre.goddard@gmail.com>
      Cc: Julia Lawall <julia@diku.dk>
      Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
      Cc: Jeff Dike <jdike@addtoit.com>
      Cc: Ingo Molnar <mingo@elte.hu>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Richard Purdie <rpurdie@rpsys.net>
      Cc: Neil Brown <neilb@suse.de>
      Cc: Kyle McMartin <kyle@mcmartin.ca>
      Cc: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
      Cc: David Howells <dhowells@redhat.com>
      Cc: <linux-ext4@vger.kernel.org>
      Cc: Samuel Ortiz <samuel@sortiz.org>
      Cc: Patrick McHardy <kaber@trash.net>
      Cc: Takashi Iwai <tiwai@suse.de>
      Signed-off-by: 's avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: 's avatarLinus Torvalds <torvalds@linux-foundation.org>
      e7d2860b
  4. 19 Oct, 2007 1 commit
  5. 17 Oct, 2007 1 commit
  6. 18 Jul, 2007 1 commit
    • Jeremy Fitzhardinge's avatar
      add argv_split() · d84d1cc7
      Jeremy Fitzhardinge authored
      argv_split() is a helper function which takes a string, splits it at
      whitespace, and returns a NULL-terminated argv vector.  This is
      deliberately simple - it does no quote processing of any kind.
      
      [ Seems to me that this is something which is already being done in
        the kernel, but I couldn't find any other implementations, either to
        steal or replace.  Keep an eye out. ]
      Signed-off-by: 's avatarJeremy Fitzhardinge <jeremy@xensource.com>
      Signed-off-by: 's avatarChris Wright <chrisw@sous-sol.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Randy Dunlap <randy.dunlap@oracle.com>
      d84d1cc7