]> git.baikalelectronics.ru Git - kernel.git/commit
lib: add kstrto*_from_user()
authorAlexey Dobriyan <adobriyan@gmail.com>
Wed, 25 May 2011 00:13:31 +0000 (17:13 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 25 May 2011 15:39:52 +0000 (08:39 -0700)
commit9d6fe6efe3755a406305aa1609cf060a52065892
tree8759b68d81eb693e391dee8f85a8d418ea5656a6
parent48804ecf13584620a005f3c4ee60f1ad8e5010b0
lib: add kstrto*_from_user()

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 <adobriyan@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/kernel.h
lib/kstrtox.c