1. 26 7月, 2011 1 次提交
  2. 25 5月, 2011 1 次提交
    • A
      lib: add kstrto*_from_user() · c196e32a
      Alexey Dobriyan 提交于
      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: NAlexey Dobriyan <adobriyan@gmail.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      c196e32a
  3. 15 4月, 2011 1 次提交
  4. 23 3月, 2011 1 次提交
    • A
      kstrto*: converting strings to integers done (hopefully) right · 33ee3b2e
      Alexey Dobriyan 提交于
      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: NAlexey Dobriyan <adobriyan@gmail.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      33ee3b2e