2010-12-05 17:50:13

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 01/45] kstrtox: converting strings to integers done (hopefully) right

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: sizeof and __alignof__ trick is done to save function call
where types aren't distinguishable.

Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/video/via/viafbdev.h | 3 -
include/linux/kernel.h | 62 ++++-
lib/Kconfig.debug | 3 +
lib/Makefile | 2 +
lib/kstrtox.c | 227 +++++++++++++
lib/test-kstrtox.c | 739 ++++++++++++++++++++++++++++++++++++++++++
lib/vsprintf.c | 141 --------
scripts/checkpatch.pl | 4 +-
8 files changed, 1031 insertions(+), 150 deletions(-)
create mode 100644 lib/kstrtox.c
create mode 100644 lib/test-kstrtox.c

diff --git a/drivers/video/via/viafbdev.h b/drivers/video/via/viafbdev.h
index 4960e3d..57d77e1 100644
--- a/drivers/video/via/viafbdev.h
+++ b/drivers/video/via/viafbdev.h
@@ -94,9 +94,6 @@ extern int viafb_LCD_ON;
extern int viafb_DVI_ON;
extern int viafb_hotplug;

-extern int strict_strtoul(const char *cp, unsigned int base,
- unsigned long *res);
-
u8 viafb_gpio_i2c_read_lvds(struct lvds_setting_information
*plvds_setting_info, struct lvds_chip_information
*plvds_chip_info, u8 index);
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index b6de9a6..1801bae 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -172,14 +172,68 @@ NORET_TYPE void do_exit(long error_code)
ATTRIB_NORET;
NORET_TYPE void complete_and_exit(struct completion *, long)
ATTRIB_NORET;
+
+/* Internal, do not use. */
+int __must_check _kstrtoul(const char *s, unsigned int base, unsigned long *res);
+int __must_check _kstrtol(const char *s, unsigned int base, long *res);
+
+int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res);
+int __must_check kstrtoll(const char *s, unsigned int base, long long *res);
+static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res)
+{
+ if (sizeof(unsigned long) == sizeof(unsigned long long) &&
+ __alignof__(unsigned long) == __alignof__(unsigned long long))
+ return kstrtoull(s, base, (unsigned long long *)res);
+ else
+ return _kstrtoul(s, base, res);
+}
+
+static inline int __must_check kstrtol(const char *s, unsigned int base, long *res)
+{
+ if (sizeof(long) == sizeof(long long) &&
+ __alignof__(long) == __alignof__(long long))
+ return kstrtoll(s, base, (long long *)res);
+ else
+ return _kstrtol(s, base, res);
+}
+
+int __must_check kstrtouint(const char *s, unsigned int base, unsigned int *res);
+int __must_check kstrtoint(const char *s, unsigned int base, int *res);
+
+static inline int __must_check kstrtou64(const char *s, unsigned int base, u64 *res)
+{
+ return kstrtoull(s, base, res);
+}
+
+static inline int __must_check kstrtos64(const char *s, unsigned int base, s64 *res)
+{
+ return kstrtoll(s, base, res);
+}
+
+static inline int __must_check kstrtou32(const char *s, unsigned int base, u32 *res)
+{
+ return kstrtouint(s, base, res);
+}
+
+static inline int __must_check kstrtos32(const char *s, unsigned int base, s32 *res)
+{
+ return kstrtoint(s, base, res);
+}
+
+int __must_check kstrtou16(const char *s, unsigned int base, u16 *res);
+int __must_check kstrtos16(const char *s, unsigned int base, s16 *res);
+int __must_check kstrtou8(const char *s, unsigned int base, u8 *res);
+int __must_check kstrtos8(const char *s, unsigned int base, s8 *res);
+
extern unsigned long simple_strtoul(const char *,char **,unsigned int);
extern long simple_strtol(const char *,char **,unsigned int);
extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
extern long long simple_strtoll(const char *,char **,unsigned int);
-extern int __must_check strict_strtoul(const char *, unsigned int, unsigned long *);
-extern int __must_check strict_strtol(const char *, unsigned int, long *);
-extern int __must_check strict_strtoull(const char *, unsigned int, unsigned long long *);
-extern int __must_check strict_strtoll(const char *, unsigned int, long long *);
+#define strict_strtoul kstrtoul
+#define strict_strtol kstrtol
+#define strict_strtoull kstrtoull
+#define strict_strtoll kstrtoll
+
extern int sprintf(char * buf, const char * fmt, ...)
__attribute__ ((format (printf, 2, 3)));
extern int vsprintf(char *buf, const char *, va_list)
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 28b42b9..64a6577 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1235,3 +1235,6 @@ source "samples/Kconfig"
source "lib/Kconfig.kgdb"

source "lib/Kconfig.kmemcheck"
+
+config TEST_KSTRTOX
+ tristate "Test kstrto*() family of functions at runtime"
diff --git a/lib/Makefile b/lib/Makefile
index e6a3763..75b524a 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -22,6 +22,8 @@ lib-y += kobject.o kref.o klist.o
obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \
bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \
string_helpers.o gcd.o lcm.o list_sort.o uuid.o
+obj-y += kstrtox.o
+obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o

ifeq ($(CONFIG_DEBUG_KOBJECT),y)
CFLAGS_kobject.o += -DDEBUG
diff --git a/lib/kstrtox.c b/lib/kstrtox.c
new file mode 100644
index 0000000..d8af7f6
--- /dev/null
+++ b/lib/kstrtox.c
@@ -0,0 +1,227 @@
+/*
+ * Convert integer string representation to an integer.
+ * If an integer doesn't fit into specified type, -E is returned.
+ *
+ * Integer starts with optional sign.
+ * kstrtou*() functions do not accept sign "-".
+ *
+ * Radix 0 means autodetection: leading "0x" implies radix 16,
+ * leading "0" implies radix 8, otherwise radix is 10.
+ * Autodetection hints work after optional sign, but not before.
+ *
+ * If -E is returned, result is not touched.
+ */
+#include <linux/ctype.h>
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/math64.h>
+#include <linux/module.h>
+#include <linux/types.h>
+
+static inline char _tolower(const char c)
+{
+ return c | 0x20;
+}
+
+static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
+{
+ unsigned long long acc;
+ int ok;
+
+ if (base == 0) {
+ if (s[0] == '0') {
+ if (_tolower(s[1]) == 'x' && isxdigit(s[2]))
+ base = 16;
+ else
+ base = 8;
+ } else
+ base = 10;
+ }
+ if (base == 16 && s[0] == '0' && _tolower(s[1]) == 'x')
+ s += 2;
+
+ acc = 0;
+ ok = 0;
+ while (*s) {
+ unsigned int val;
+
+ if ('0' <= *s && *s <= '9')
+ val = *s - '0';
+ else if ('a' <= _tolower(*s) && _tolower(*s) <= 'f')
+ val = _tolower(*s) - 'a' + 10;
+ else if (*s == '\n') {
+ if (*(s + 1) == '\0')
+ break;
+ else
+ return -EINVAL;
+ } else
+ return -EINVAL;
+
+ if (val >= base)
+ return -EINVAL;
+ if (acc > div_u64(ULLONG_MAX - val, base))
+ return -EINVAL;
+ acc = acc * base + val;
+ ok = 1;
+
+ s++;
+ }
+ if (!ok)
+ return -EINVAL;
+ *res = acc;
+ return 0;
+}
+
+int kstrtoull(const char *s, unsigned int base, unsigned long long *res)
+{
+ if (s[0] == '+')
+ s++;
+ return _kstrtoull(s, base, res);
+}
+EXPORT_SYMBOL(kstrtoull);
+
+int kstrtoll(const char *s, unsigned int base, long long *res)
+{
+ unsigned long long tmp;
+ int rv;
+
+ if (s[0] == '-') {
+ rv = _kstrtoull(s + 1, base, &tmp);
+ if (rv < 0)
+ return rv;
+ if ((long long)(-tmp) >= 0)
+ return -EINVAL;
+ *res = -tmp;
+ } else {
+ rv = kstrtoull(s, base, &tmp);
+ if (rv < 0)
+ return rv;
+ if ((long long)tmp < 0)
+ return -EINVAL;
+ *res = tmp;
+ }
+ return 0;
+}
+EXPORT_SYMBOL(kstrtoll);
+
+/* Internal, do not use. */
+int _kstrtoul(const char *s, unsigned int base, unsigned long *res)
+{
+ unsigned long long tmp;
+ int rv;
+
+ rv = kstrtoull(s, base, &tmp);
+ if (rv < 0)
+ return rv;
+ if (tmp != (unsigned long long)(unsigned long)tmp)
+ return -EINVAL;
+ *res = tmp;
+ return 0;
+}
+EXPORT_SYMBOL(_kstrtoul);
+
+/* Internal, do not use. */
+int _kstrtol(const char *s, unsigned int base, long *res)
+{
+ long long tmp;
+ int rv;
+
+ rv = kstrtoll(s, base, &tmp);
+ if (rv < 0)
+ return rv;
+ if (tmp != (long long)(long)tmp)
+ return -EINVAL;
+ *res = tmp;
+ return 0;
+}
+EXPORT_SYMBOL(_kstrtol);
+
+int kstrtouint(const char *s, unsigned int base, unsigned int *res)
+{
+ unsigned long long tmp;
+ int rv;
+
+ rv = kstrtoull(s, base, &tmp);
+ if (rv < 0)
+ return rv;
+ if (tmp != (unsigned long long)(unsigned int)tmp)
+ return -EINVAL;
+ *res = tmp;
+ return 0;
+}
+EXPORT_SYMBOL(kstrtouint);
+
+int kstrtoint(const char *s, unsigned int base, int *res)
+{
+ long long tmp;
+ int rv;
+
+ rv = kstrtoll(s, base, &tmp);
+ if (rv < 0)
+ return rv;
+ if (tmp != (long long)(int)tmp)
+ return -EINVAL;
+ *res = tmp;
+ return 0;
+}
+EXPORT_SYMBOL(kstrtoint);
+
+int kstrtou16(const char *s, unsigned int base, u16 *res)
+{
+ unsigned long long tmp;
+ int rv;
+
+ rv = kstrtoull(s, base, &tmp);
+ if (rv < 0)
+ return rv;
+ if (tmp != (unsigned long long)(u16)tmp)
+ return -EINVAL;
+ *res = tmp;
+ return 0;
+}
+EXPORT_SYMBOL(kstrtou16);
+
+int kstrtos16(const char *s, unsigned int base, s16 *res)
+{
+ long long tmp;
+ int rv;
+
+ rv = kstrtoll(s, base, &tmp);
+ if (rv < 0)
+ return rv;
+ if (tmp != (long long)(s16)tmp)
+ return -EINVAL;
+ *res = tmp;
+ return 0;
+}
+EXPORT_SYMBOL(kstrtos16);
+
+int kstrtou8(const char *s, unsigned int base, u8 *res)
+{
+ unsigned long long tmp;
+ int rv;
+
+ rv = kstrtoull(s, base, &tmp);
+ if (rv < 0)
+ return rv;
+ if (tmp != (unsigned long long)(u8)tmp)
+ return -EINVAL;
+ *res = tmp;
+ return 0;
+}
+EXPORT_SYMBOL(kstrtou8);
+
+int kstrtos8(const char *s, unsigned int base, s8 *res)
+{
+ long long tmp;
+ int rv;
+
+ rv = kstrtoll(s, base, &tmp);
+ if (rv < 0)
+ return rv;
+ if (tmp != (long long)(s8)tmp)
+ return -EINVAL;
+ *res = tmp;
+ return 0;
+}
+EXPORT_SYMBOL(kstrtos8);
diff --git a/lib/test-kstrtox.c b/lib/test-kstrtox.c
new file mode 100644
index 0000000..325c2f9
--- /dev/null
+++ b/lib/test-kstrtox.c
@@ -0,0 +1,739 @@
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+
+#define for_each_test(i, test) \
+ for (i = 0; i < sizeof(test) / sizeof(test[0]); i++)
+
+struct test_fail {
+ const char *str;
+ unsigned int base;
+};
+
+#define DEFINE_TEST_FAIL(test) \
+ const struct test_fail test[] __initdata
+
+#define DECLARE_TEST_OK(type, test_type) \
+ test_type { \
+ const char *str; \
+ unsigned int base; \
+ type expected_res; \
+ }
+
+#define DEFINE_TEST_OK(type, test) \
+ const type test[] __initdata
+
+#define TEST_FAIL(fn, type, fmt, test) \
+{ \
+ unsigned int i; \
+ \
+ for_each_test(i, test) { \
+ const struct test_fail *t = &test[i]; \
+ type tmp; \
+ int rv; \
+ \
+ tmp = 0; \
+ rv = fn(t->str, t->base, &tmp); \
+ if (rv >= 0) { \
+ WARN(1, "str '%s', base %u, expected -E, got %d/" fmt "\n", \
+ t->str, t->base, rv, tmp); \
+ continue; \
+ } \
+ } \
+}
+
+#define TEST_OK(fn, type, fmt, test) \
+{ \
+ unsigned int i; \
+ \
+ for_each_test(i, test) { \
+ const typeof(test[0]) *t = &test[i]; \
+ type res; \
+ int rv; \
+ \
+ rv = fn(t->str, t->base, &res); \
+ if (rv != 0) { \
+ WARN(1, "str '%s', base %u, expected 0/" fmt ", got %d\n", \
+ t->str, t->base, t->expected_res, rv); \
+ continue; \
+ } \
+ if (res != t->expected_res) { \
+ WARN(1, "str '%s', base %u, expected " fmt ", got " fmt "\n", \
+ t->str, t->base, t->expected_res, res); \
+ continue; \
+ } \
+ } \
+}
+
+static void __init test_kstrtoull_ok(void)
+{
+ DECLARE_TEST_OK(unsigned long long, struct test_ull);
+ static DEFINE_TEST_OK(struct test_ull, test_ull_ok) = {
+ {"0", 10, 0ULL},
+ {"1", 10, 1ULL},
+ {"127", 10, 127ULL},
+ {"128", 10, 128ULL},
+ {"129", 10, 129ULL},
+ {"255", 10, 255ULL},
+ {"256", 10, 256ULL},
+ {"257", 10, 257ULL},
+ {"32767", 10, 32767ULL},
+ {"32768", 10, 32768ULL},
+ {"32769", 10, 32769ULL},
+ {"65535", 10, 65535ULL},
+ {"65536", 10, 65536ULL},
+ {"65537", 10, 65537ULL},
+ {"2147483647", 10, 2147483647ULL},
+ {"2147483648", 10, 2147483648ULL},
+ {"2147483649", 10, 2147483649ULL},
+ {"4294967295", 10, 4294967295ULL},
+ {"4294967296", 10, 4294967296ULL},
+ {"4294967297", 10, 4294967297ULL},
+ {"9223372036854775807", 10, 9223372036854775807ULL},
+ {"9223372036854775808", 10, 9223372036854775808ULL},
+ {"9223372036854775809", 10, 9223372036854775809ULL},
+ {"18446744073709551614", 10, 18446744073709551614ULL},
+ {"18446744073709551615", 10, 18446744073709551615ULL},
+
+ {"00", 8, 00ULL},
+ {"01", 8, 01ULL},
+ {"0177", 8, 0177ULL},
+ {"0200", 8, 0200ULL},
+ {"0201", 8, 0201ULL},
+ {"0377", 8, 0377ULL},
+ {"0400", 8, 0400ULL},
+ {"0401", 8, 0401ULL},
+ {"077777", 8, 077777ULL},
+ {"0100000", 8, 0100000ULL},
+ {"0100001", 8, 0100001ULL},
+ {"0177777", 8, 0177777ULL},
+ {"0200000", 8, 0200000ULL},
+ {"0200001", 8, 0200001ULL},
+ {"017777777777", 8, 017777777777ULL},
+ {"020000000000", 8, 020000000000ULL},
+ {"020000000001", 8, 020000000001ULL},
+ {"037777777777", 8, 037777777777ULL},
+ {"040000000000", 8, 040000000000ULL},
+ {"040000000001", 8, 040000000001ULL},
+ {"0777777777777777777777", 8, 0777777777777777777777ULL},
+ {"01000000000000000000000", 8, 01000000000000000000000ULL},
+ {"01000000000000000000001", 8, 01000000000000000000001ULL},
+ {"01777777777777777777776", 8, 01777777777777777777776ULL},
+ {"01777777777777777777777", 8, 01777777777777777777777ULL},
+
+ {"0x0", 16, 0x0ULL},
+ {"0x1", 16, 0x1ULL},
+ {"0x7f", 16, 0x7fULL},
+ {"0x80", 16, 0x80ULL},
+ {"0x81", 16, 0x81ULL},
+ {"0xff", 16, 0xffULL},
+ {"0x100", 16, 0x100ULL},
+ {"0x101", 16, 0x101ULL},
+ {"0x7fff", 16, 0x7fffULL},
+ {"0x8000", 16, 0x8000ULL},
+ {"0x8001", 16, 0x8001ULL},
+ {"0xffff", 16, 0xffffULL},
+ {"0x10000", 16, 0x10000ULL},
+ {"0x10001", 16, 0x10001ULL},
+ {"0x7fffffff", 16, 0x7fffffffULL},
+ {"0x80000000", 16, 0x80000000ULL},
+ {"0x80000001", 16, 0x80000001ULL},
+ {"0xffffffff", 16, 0xffffffffULL},
+ {"0x100000000", 16, 0x100000000ULL},
+ {"0x100000001", 16, 0x100000001ULL},
+ {"0x7fffffffffffffff", 16, 0x7fffffffffffffffULL},
+ {"0x8000000000000000", 16, 0x8000000000000000ULL},
+ {"0x8000000000000001", 16, 0x8000000000000001ULL},
+ {"0xfffffffffffffffe", 16, 0xfffffffffffffffeULL},
+ {"0xffffffffffffffff", 16, 0xffffffffffffffffULL},
+
+ {"0\n", 0, 0ULL},
+ };
+ TEST_OK(kstrtoull, unsigned long long, "%llu", test_ull_ok);
+}
+
+static void __init test_kstrtoull_fail(void)
+{
+ static DEFINE_TEST_FAIL(test_ull_fail) = {
+ {"", 0},
+ {"", 8},
+ {"", 10},
+ {"", 16},
+ {"\n", 0},
+ {"\n", 8},
+ {"\n", 10},
+ {"\n", 16},
+ {"\n0", 0},
+ {"\n0", 8},
+ {"\n0", 10},
+ {"\n0", 16},
+ {"+", 0},
+ {"+", 8},
+ {"+", 10},
+ {"+", 16},
+ {"-", 0},
+ {"-", 8},
+ {"-", 10},
+ {"-", 16},
+ {"0x", 0},
+ {"0x", 16},
+ {"0X", 0},
+ {"0X", 16},
+ {"0 ", 0},
+ {"1+", 0},
+ {"1-", 0},
+ {" 2", 0},
+ /* base autodetection */
+ {"0x0z", 0},
+ {"0z", 0},
+ {"a", 0},
+ /* digit >= base */
+ {"2", 2},
+ {"8", 8},
+ {"a", 10},
+ {"A", 10},
+ {"g", 16},
+ {"G", 16},
+ /* overflow */
+ {"10000000000000000000000000000000000000000000000000000000000000000", 2},
+ {"2000000000000000000000", 8},
+ {"18446744073709551616", 10},
+ {"10000000000000000", 16},
+ /* negative */
+ {"-0", 0},
+ {"-0", 8},
+ {"-0", 10},
+ {"-0", 16},
+ {"-1", 0},
+ {"-1", 8},
+ {"-1", 10},
+ {"-1", 16},
+ /* sign is first character if any */
+ {"-+1", 0},
+ {"-+1", 8},
+ {"-+1", 10},
+ {"-+1", 16},
+ /* nothing after \n */
+ {"0\n0", 0},
+ {"0\n0", 8},
+ {"0\n0", 10},
+ {"0\n0", 16},
+ {"0\n+", 0},
+ {"0\n+", 8},
+ {"0\n+", 10},
+ {"0\n+", 16},
+ {"0\n-", 0},
+ {"0\n-", 8},
+ {"0\n-", 10},
+ {"0\n-", 16},
+ {"0\n ", 0},
+ {"0\n ", 8},
+ {"0\n ", 10},
+ {"0\n ", 16},
+ };
+ TEST_FAIL(kstrtoull, unsigned long long, "%llu", test_ull_fail);
+}
+
+static void __init test_kstrtoll_ok(void)
+{
+ DECLARE_TEST_OK(long long, struct test_ll);
+ static DEFINE_TEST_OK(struct test_ll, test_ll_ok) = {
+ {"0", 10, 0LL},
+ {"1", 10, 1LL},
+ {"127", 10, 127LL},
+ {"128", 10, 128LL},
+ {"129", 10, 129LL},
+ {"255", 10, 255LL},
+ {"256", 10, 256LL},
+ {"257", 10, 257LL},
+ {"32767", 10, 32767LL},
+ {"32768", 10, 32768LL},
+ {"32769", 10, 32769LL},
+ {"65535", 10, 65535LL},
+ {"65536", 10, 65536LL},
+ {"65537", 10, 65537LL},
+ {"2147483647", 10, 2147483647LL},
+ {"2147483648", 10, 2147483648LL},
+ {"2147483649", 10, 2147483649LL},
+ {"4294967295", 10, 4294967295LL},
+ {"4294967296", 10, 4294967296LL},
+ {"4294967297", 10, 4294967297LL},
+ {"9223372036854775807", 10, 9223372036854775807LL},
+
+ {"-1", 10, -1LL},
+ {"-2", 10, -2LL},
+ {"-9223372036854775808", 10, LLONG_MIN},
+ };
+ TEST_OK(kstrtoll, long long, "%lld", test_ll_ok);
+}
+
+static void __init test_kstrtoll_fail(void)
+{
+ static DEFINE_TEST_FAIL(test_ll_fail) = {
+ {"9223372036854775808", 10},
+ {"9223372036854775809", 10},
+ {"18446744073709551614", 10},
+ {"18446744073709551615", 10},
+ {"-9223372036854775809", 10},
+ {"-18446744073709551614", 10},
+ {"-18446744073709551615", 10},
+ /* negative zero isn't an integer in Linux */
+ {"-0", 0},
+ {"-0", 8},
+ {"-0", 10},
+ {"-0", 16},
+ /* sign is first character if any */
+ {"-+1", 0},
+ {"-+1", 8},
+ {"-+1", 10},
+ {"-+1", 16},
+ };
+ TEST_FAIL(kstrtoll, long long, "%lld", test_ll_fail);
+}
+
+static void __init test_kstrtou64_ok(void)
+{
+ DECLARE_TEST_OK(u64, struct test_u64);
+ static DEFINE_TEST_OK(struct test_u64, test_u64_ok) = {
+ {"0", 10, 0},
+ {"1", 10, 1},
+ {"126", 10, 126},
+ {"127", 10, 127},
+ {"128", 10, 128},
+ {"129", 10, 129},
+ {"254", 10, 254},
+ {"255", 10, 255},
+ {"256", 10, 256},
+ {"257", 10, 257},
+ {"32766", 10, 32766},
+ {"32767", 10, 32767},
+ {"32768", 10, 32768},
+ {"32769", 10, 32769},
+ {"65534", 10, 65534},
+ {"65535", 10, 65535},
+ {"65536", 10, 65536},
+ {"65537", 10, 65537},
+ {"2147483646", 10, 2147483646},
+ {"2147483647", 10, 2147483647},
+ {"2147483648", 10, 2147483648},
+ {"2147483649", 10, 2147483649},
+ {"4294967294", 10, 4294967294},
+ {"4294967295", 10, 4294967295},
+ {"4294967296", 10, 4294967296},
+ {"4294967297", 10, 4294967297},
+ {"9223372036854775806", 10, 9223372036854775806ULL},
+ {"9223372036854775807", 10, 9223372036854775807ULL},
+ {"9223372036854775808", 10, 9223372036854775808ULL},
+ {"9223372036854775809", 10, 9223372036854775809ULL},
+ {"18446744073709551614", 10, 18446744073709551614ULL},
+ {"18446744073709551615", 10, 18446744073709551615ULL},
+ };
+ TEST_OK(kstrtou64, u64, "%llu", test_u64_ok);
+}
+
+static void __init test_kstrtou64_fail(void)
+{
+ static DEFINE_TEST_FAIL(test_u64_fail) = {
+ {"-2", 10},
+ {"-1", 10},
+ {"18446744073709551616", 10},
+ {"18446744073709551617", 10},
+ };
+ TEST_FAIL(kstrtou64, u64, "%llu", test_u64_fail);
+}
+
+static void __init test_kstrtos64_ok(void)
+{
+ DECLARE_TEST_OK(s64, struct test_s64);
+ static DEFINE_TEST_OK(struct test_s64, test_s64_ok) = {
+ {"-128", 10, -128},
+ {"-127", 10, -127},
+ {"-1", 10, -1},
+ {"0", 10, 0},
+ {"1", 10, 1},
+ {"126", 10, 126},
+ {"127", 10, 127},
+ {"128", 10, 128},
+ {"129", 10, 129},
+ {"254", 10, 254},
+ {"255", 10, 255},
+ {"256", 10, 256},
+ {"257", 10, 257},
+ {"32766", 10, 32766},
+ {"32767", 10, 32767},
+ {"32768", 10, 32768},
+ {"32769", 10, 32769},
+ {"65534", 10, 65534},
+ {"65535", 10, 65535},
+ {"65536", 10, 65536},
+ {"65537", 10, 65537},
+ {"2147483646", 10, 2147483646},
+ {"2147483647", 10, 2147483647},
+ {"2147483648", 10, 2147483648},
+ {"2147483649", 10, 2147483649},
+ {"4294967294", 10, 4294967294},
+ {"4294967295", 10, 4294967295},
+ {"4294967296", 10, 4294967296},
+ {"4294967297", 10, 4294967297},
+ {"9223372036854775806", 10, 9223372036854775806LL},
+ {"9223372036854775807", 10, 9223372036854775807LL},
+ };
+ TEST_OK(kstrtos64, s64, "%lld", test_s64_ok);
+}
+
+static void __init test_kstrtos64_fail(void)
+{
+ static DEFINE_TEST_FAIL(test_s64_fail) = {
+ {"9223372036854775808", 10},
+ {"9223372036854775809", 10},
+ {"18446744073709551614", 10},
+ {"18446744073709551615", 10},
+ {"18446744073709551616", 10},
+ {"18446744073709551617", 10},
+ };
+ TEST_FAIL(kstrtos64, s64, "%lld", test_s64_fail);
+}
+
+static void __init test_kstrtou32_ok(void)
+{
+ DECLARE_TEST_OK(u32, struct test_u32);
+ static DEFINE_TEST_OK(struct test_u32, test_u32_ok) = {
+ {"0", 10, 0},
+ {"1", 10, 1},
+ {"126", 10, 126},
+ {"127", 10, 127},
+ {"128", 10, 128},
+ {"129", 10, 129},
+ {"254", 10, 254},
+ {"255", 10, 255},
+ {"256", 10, 256},
+ {"257", 10, 257},
+ {"32766", 10, 32766},
+ {"32767", 10, 32767},
+ {"32768", 10, 32768},
+ {"32769", 10, 32769},
+ {"65534", 10, 65534},
+ {"65535", 10, 65535},
+ {"65536", 10, 65536},
+ {"65537", 10, 65537},
+ {"2147483646", 10, 2147483646},
+ {"2147483647", 10, 2147483647},
+ {"2147483648", 10, 2147483648},
+ {"2147483649", 10, 2147483649},
+ {"4294967294", 10, 4294967294},
+ {"4294967295", 10, 4294967295},
+ };
+ TEST_OK(kstrtou32, u32, "%u", test_u32_ok);
+}
+
+static void __init test_kstrtou32_fail(void)
+{
+ static DEFINE_TEST_FAIL(test_u32_fail) = {
+ {"-2", 10},
+ {"-1", 10},
+ {"4294967296", 10},
+ {"4294967297", 10},
+ {"9223372036854775806", 10},
+ {"9223372036854775807", 10},
+ {"9223372036854775808", 10},
+ {"9223372036854775809", 10},
+ {"18446744073709551614", 10},
+ {"18446744073709551615", 10},
+ {"18446744073709551616", 10},
+ {"18446744073709551617", 10},
+ };
+ TEST_FAIL(kstrtou32, u32, "%u", test_u32_fail);
+}
+
+static void __init test_kstrtos32_ok(void)
+{
+ DECLARE_TEST_OK(s32, struct test_s32);
+ static DEFINE_TEST_OK(struct test_s32, test_s32_ok) = {
+ {"-128", 10, -128},
+ {"-127", 10, -127},
+ {"-1", 10, -1},
+ {"0", 10, 0},
+ {"1", 10, 1},
+ {"126", 10, 126},
+ {"127", 10, 127},
+ {"128", 10, 128},
+ {"129", 10, 129},
+ {"254", 10, 254},
+ {"255", 10, 255},
+ {"256", 10, 256},
+ {"257", 10, 257},
+ {"32766", 10, 32766},
+ {"32767", 10, 32767},
+ {"32768", 10, 32768},
+ {"32769", 10, 32769},
+ {"65534", 10, 65534},
+ {"65535", 10, 65535},
+ {"65536", 10, 65536},
+ {"65537", 10, 65537},
+ {"2147483646", 10, 2147483646},
+ {"2147483647", 10, 2147483647},
+ };
+ TEST_OK(kstrtos32, s32, "%d", test_s32_ok);
+}
+
+static void __init test_kstrtos32_fail(void)
+{
+ static DEFINE_TEST_FAIL(test_s32_fail) = {
+ {"2147483648", 10},
+ {"2147483649", 10},
+ {"4294967294", 10},
+ {"4294967295", 10},
+ {"4294967296", 10},
+ {"4294967297", 10},
+ {"9223372036854775806", 10},
+ {"9223372036854775807", 10},
+ {"9223372036854775808", 10},
+ {"9223372036854775809", 10},
+ {"18446744073709551614", 10},
+ {"18446744073709551615", 10},
+ {"18446744073709551616", 10},
+ {"18446744073709551617", 10},
+ };
+ TEST_FAIL(kstrtos32, s32, "%d", test_s32_fail);
+}
+
+static void __init test_kstrtou16_ok(void)
+{
+ DECLARE_TEST_OK(u16, struct test_u16);
+ static DEFINE_TEST_OK(struct test_u16, test_u16_ok) = {
+ {"0", 10, 0},
+ {"1", 10, 1},
+ {"126", 10, 126},
+ {"127", 10, 127},
+ {"128", 10, 128},
+ {"129", 10, 129},
+ {"254", 10, 254},
+ {"255", 10, 255},
+ {"256", 10, 256},
+ {"257", 10, 257},
+ {"32766", 10, 32766},
+ {"32767", 10, 32767},
+ {"32768", 10, 32768},
+ {"32769", 10, 32769},
+ {"65534", 10, 65534},
+ {"65535", 10, 65535},
+ };
+ TEST_OK(kstrtou16, u16, "%hu", test_u16_ok);
+}
+
+static void __init test_kstrtou16_fail(void)
+{
+ static DEFINE_TEST_FAIL(test_u16_fail) = {
+ {"-2", 10},
+ {"-1", 10},
+ {"65536", 10},
+ {"65537", 10},
+ {"2147483646", 10},
+ {"2147483647", 10},
+ {"2147483648", 10},
+ {"2147483649", 10},
+ {"4294967294", 10},
+ {"4294967295", 10},
+ {"4294967296", 10},
+ {"4294967297", 10},
+ {"9223372036854775806", 10},
+ {"9223372036854775807", 10},
+ {"9223372036854775808", 10},
+ {"9223372036854775809", 10},
+ {"18446744073709551614", 10},
+ {"18446744073709551615", 10},
+ {"18446744073709551616", 10},
+ {"18446744073709551617", 10},
+ };
+ TEST_FAIL(kstrtou16, u16, "%hu", test_u16_fail);
+}
+
+static void __init test_kstrtos16_ok(void)
+{
+ DECLARE_TEST_OK(s16, struct test_s16);
+ static DEFINE_TEST_OK(struct test_s16, test_s16_ok) = {
+ {"-130", 10, -130},
+ {"-129", 10, -129},
+ {"-128", 10, -128},
+ {"-127", 10, -127},
+ {"-1", 10, -1},
+ {"0", 10, 0},
+ {"1", 10, 1},
+ {"126", 10, 126},
+ {"127", 10, 127},
+ {"128", 10, 128},
+ {"129", 10, 129},
+ {"254", 10, 254},
+ {"255", 10, 255},
+ {"256", 10, 256},
+ {"257", 10, 257},
+ {"32766", 10, 32766},
+ {"32767", 10, 32767},
+ };
+ TEST_OK(kstrtos16, s16, "%hd", test_s16_ok);
+}
+
+static void __init test_kstrtos16_fail(void)
+{
+ static DEFINE_TEST_FAIL(test_s16_fail) = {
+ {"32768", 10},
+ {"32769", 10},
+ {"65534", 10},
+ {"65535", 10},
+ {"65536", 10},
+ {"65537", 10},
+ {"2147483646", 10},
+ {"2147483647", 10},
+ {"2147483648", 10},
+ {"2147483649", 10},
+ {"4294967294", 10},
+ {"4294967295", 10},
+ {"4294967296", 10},
+ {"4294967297", 10},
+ {"9223372036854775806", 10},
+ {"9223372036854775807", 10},
+ {"9223372036854775808", 10},
+ {"9223372036854775809", 10},
+ {"18446744073709551614", 10},
+ {"18446744073709551615", 10},
+ {"18446744073709551616", 10},
+ {"18446744073709551617", 10},
+ };
+ TEST_FAIL(kstrtos16, s16, "%hd", test_s16_fail);
+}
+
+static void __init test_kstrtou8_ok(void)
+{
+ DECLARE_TEST_OK(u8, struct test_u8);
+ static DEFINE_TEST_OK(struct test_u8, test_u8_ok) = {
+ {"0", 10, 0},
+ {"1", 10, 1},
+ {"126", 10, 126},
+ {"127", 10, 127},
+ {"128", 10, 128},
+ {"129", 10, 129},
+ {"254", 10, 254},
+ {"255", 10, 255},
+ };
+ TEST_OK(kstrtou8, u8, "%hhu", test_u8_ok);
+}
+
+static void __init test_kstrtou8_fail(void)
+{
+ static DEFINE_TEST_FAIL(test_u8_fail) = {
+ {"-2", 10},
+ {"-1", 10},
+ {"256", 10},
+ {"257", 10},
+ {"32766", 10},
+ {"32767", 10},
+ {"32768", 10},
+ {"32769", 10},
+ {"65534", 10},
+ {"65535", 10},
+ {"65536", 10},
+ {"65537", 10},
+ {"2147483646", 10},
+ {"2147483647", 10},
+ {"2147483648", 10},
+ {"2147483649", 10},
+ {"4294967294", 10},
+ {"4294967295", 10},
+ {"4294967296", 10},
+ {"4294967297", 10},
+ {"9223372036854775806", 10},
+ {"9223372036854775807", 10},
+ {"9223372036854775808", 10},
+ {"9223372036854775809", 10},
+ {"18446744073709551614", 10},
+ {"18446744073709551615", 10},
+ {"18446744073709551616", 10},
+ {"18446744073709551617", 10},
+ };
+ TEST_FAIL(kstrtou8, u8, "%hhu", test_u8_fail);
+}
+
+static void __init test_kstrtos8_ok(void)
+{
+ DECLARE_TEST_OK(s8, struct test_s8);
+ static DEFINE_TEST_OK(struct test_s8, test_s8_ok) = {
+ {"-128", 10, -128},
+ {"-127", 10, -127},
+ {"-1", 10, -1},
+ {"0", 10, 0},
+ {"1", 10, 1},
+ {"126", 10, 126},
+ {"127", 10, 127},
+ };
+ TEST_OK(kstrtos8, s8, "%hhd", test_s8_ok);
+}
+
+static void __init test_kstrtos8_fail(void)
+{
+ static DEFINE_TEST_FAIL(test_s8_fail) = {
+ {"-130", 10},
+ {"-129", 10},
+ {"128", 10},
+ {"129", 10},
+ {"254", 10},
+ {"255", 10},
+ {"256", 10},
+ {"257", 10},
+ {"32766", 10},
+ {"32767", 10},
+ {"32768", 10},
+ {"32769", 10},
+ {"65534", 10},
+ {"65535", 10},
+ {"65536", 10},
+ {"65537", 10},
+ {"2147483646", 10},
+ {"2147483647", 10},
+ {"2147483648", 10},
+ {"2147483649", 10},
+ {"4294967294", 10},
+ {"4294967295", 10},
+ {"4294967296", 10},
+ {"4294967297", 10},
+ {"9223372036854775806", 10},
+ {"9223372036854775807", 10},
+ {"9223372036854775808", 10},
+ {"9223372036854775809", 10},
+ {"18446744073709551614", 10},
+ {"18446744073709551615", 10},
+ {"18446744073709551616", 10},
+ {"18446744073709551617", 10},
+ };
+ TEST_FAIL(kstrtos8, s8, "%hhd", test_s8_fail);
+}
+
+static int __init test_kstrtox_init(void)
+{
+ test_kstrtoull_ok();
+ test_kstrtoull_fail();
+ test_kstrtoll_ok();
+ test_kstrtoll_fail();
+
+ test_kstrtou64_ok();
+ test_kstrtou64_fail();
+ test_kstrtos64_ok();
+ test_kstrtos64_fail();
+
+ test_kstrtou32_ok();
+ test_kstrtou32_fail();
+ test_kstrtos32_ok();
+ test_kstrtos32_fail();
+
+ test_kstrtou16_ok();
+ test_kstrtou16_fail();
+ test_kstrtos16_ok();
+ test_kstrtos16_fail();
+
+ test_kstrtou8_ok();
+ test_kstrtou8_fail();
+ test_kstrtos8_ok();
+ test_kstrtos8_fail();
+ return -EINVAL;
+}
+module_init(test_kstrtox_init);
+MODULE_LICENSE("Dual BSD/GPL");
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index c150d3d..490a820 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -120,147 +120,6 @@ long long simple_strtoll(const char *cp, char **endp, unsigned int base)
}
EXPORT_SYMBOL(simple_strtoll);

-/**
- * strict_strtoul - convert a string to an unsigned long strictly
- * @cp: The string to be converted
- * @base: The number base to use
- * @res: The converted result value
- *
- * strict_strtoul converts a string to an unsigned long only if the
- * string is really an unsigned long string, any string containing
- * any invalid char at the tail will be rejected and -EINVAL is returned,
- * only a newline char at the tail is acceptible because people generally
- * change a module parameter in the following way:
- *
- * echo 1024 > /sys/module/e1000/parameters/copybreak
- *
- * echo will append a newline to the tail.
- *
- * It returns 0 if conversion is successful and *res is set to the converted
- * value, otherwise it returns -EINVAL and *res is set to 0.
- *
- * simple_strtoul just ignores the successive invalid characters and
- * return the converted value of prefix part of the string.
- */
-int strict_strtoul(const char *cp, unsigned int base, unsigned long *res)
-{
- char *tail;
- unsigned long val;
-
- *res = 0;
- if (!*cp)
- return -EINVAL;
-
- val = simple_strtoul(cp, &tail, base);
- if (tail == cp)
- return -EINVAL;
-
- if ((tail[0] == '\0') || (tail[0] == '\n' && tail[1] == '\0')) {
- *res = val;
- return 0;
- }
-
- return -EINVAL;
-}
-EXPORT_SYMBOL(strict_strtoul);
-
-/**
- * strict_strtol - convert a string to a long strictly
- * @cp: The string to be converted
- * @base: The number base to use
- * @res: The converted result value
- *
- * strict_strtol is similiar to strict_strtoul, but it allows the first
- * character of a string is '-'.
- *
- * It returns 0 if conversion is successful and *res is set to the converted
- * value, otherwise it returns -EINVAL and *res is set to 0.
- */
-int strict_strtol(const char *cp, unsigned int base, long *res)
-{
- int ret;
- if (*cp == '-') {
- ret = strict_strtoul(cp + 1, base, (unsigned long *)res);
- if (!ret)
- *res = -(*res);
- } else {
- ret = strict_strtoul(cp, base, (unsigned long *)res);
- }
-
- return ret;
-}
-EXPORT_SYMBOL(strict_strtol);
-
-/**
- * strict_strtoull - convert a string to an unsigned long long strictly
- * @cp: The string to be converted
- * @base: The number base to use
- * @res: The converted result value
- *
- * strict_strtoull converts a string to an unsigned long long only if the
- * string is really an unsigned long long string, any string containing
- * any invalid char at the tail will be rejected and -EINVAL is returned,
- * only a newline char at the tail is acceptible because people generally
- * change a module parameter in the following way:
- *
- * echo 1024 > /sys/module/e1000/parameters/copybreak
- *
- * echo will append a newline to the tail of the string.
- *
- * It returns 0 if conversion is successful and *res is set to the converted
- * value, otherwise it returns -EINVAL and *res is set to 0.
- *
- * simple_strtoull just ignores the successive invalid characters and
- * return the converted value of prefix part of the string.
- */
-int strict_strtoull(const char *cp, unsigned int base, unsigned long long *res)
-{
- char *tail;
- unsigned long long val;
-
- *res = 0;
- if (!*cp)
- return -EINVAL;
-
- val = simple_strtoull(cp, &tail, base);
- if (tail == cp)
- return -EINVAL;
- if ((tail[0] == '\0') || (tail[0] == '\n' && tail[1] == '\0')) {
- *res = val;
- return 0;
- }
-
- return -EINVAL;
-}
-EXPORT_SYMBOL(strict_strtoull);
-
-/**
- * strict_strtoll - convert a string to a long long strictly
- * @cp: The string to be converted
- * @base: The number base to use
- * @res: The converted result value
- *
- * strict_strtoll is similiar to strict_strtoull, but it allows the first
- * character of a string is '-'.
- *
- * It returns 0 if conversion is successful and *res is set to the converted
- * value, otherwise it returns -EINVAL and *res is set to 0.
- */
-int strict_strtoll(const char *cp, unsigned int base, long long *res)
-{
- int ret;
- if (*cp == '-') {
- ret = strict_strtoull(cp + 1, base, (unsigned long long *)res);
- if (!ret)
- *res = -(*res);
- } else {
- ret = strict_strtoull(cp, base, (unsigned long long *)res);
- }
-
- return ret;
-}
-EXPORT_SYMBOL(strict_strtoll);
-
static noinline_for_stack
int skip_atoi(const char **s)
{
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e3c7fc0..645e9f9 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2799,9 +2799,9 @@ sub process {
WARN("consider using a completion\n" . $herecurr);

}
-# recommend strict_strto* over simple_strto*
+# recommend kstrto* over simple_strto*
if ($line =~ /\bsimple_(strto.*?)\s*\(/) {
- WARN("consider using strict_$1 in preference to simple_$1\n" . $herecurr);
+ WARN("consider using kstrto* in preference to simple_$1\n" . $herecurr);
}
# check for __initcall(), use device_initcall() explicitly please
if ($line =~ /^.\s*__initcall\s*\(/) {
--
1.7.2.2


2010-12-05 17:50:25

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 06/45] kstrtox: convert mm/

In mm/vmscan.c:
make "scan_unevictable_pages" write-only.

Signed-off-by: Alexey Dobriyan <[email protected]>
---
include/linux/slub_def.h | 2 +-
mm/hugetlb.c | 12 ++++++------
mm/kmemleak.c | 4 ++--
mm/ksm.c | 28 ++++++++++------------------
mm/slub.c | 19 ++++++++++---------
mm/vmscan.c | 25 ++++++++++---------------
6 files changed, 39 insertions(+), 51 deletions(-)

diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
index e4f5ed1..37f439d 100644
--- a/include/linux/slub_def.h
+++ b/include/linux/slub_def.h
@@ -95,7 +95,7 @@ struct kmem_cache {
/*
* Defragmentation by allocating from a remote node.
*/
- int remote_node_defrag_ratio;
+ unsigned int remote_node_defrag_ratio;
#endif
struct kmem_cache_node *node[MAX_NUMNODES];
};
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 8585524..a9a5460 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1438,9 +1438,9 @@ static ssize_t nr_hugepages_store_common(bool obey_mempolicy,
struct hstate *h;
NODEMASK_ALLOC(nodemask_t, nodes_allowed, GFP_KERNEL | __GFP_NORETRY);

- err = strict_strtoul(buf, 10, &count);
- if (err)
- return 0;
+ err = kstrtoul(buf, 10, &count);
+ if (err < 0)
+ return err;

h = kobj_to_hstate(kobj, &nid);
if (nid == NUMA_NO_NODE) {
@@ -1517,9 +1517,9 @@ static ssize_t nr_overcommit_hugepages_store(struct kobject *kobj,
unsigned long input;
struct hstate *h = kobj_to_hstate(kobj, NULL);

- err = strict_strtoul(buf, 10, &input);
- if (err)
- return 0;
+ err = kstrtoul(buf, 10, &input);
+ if (err < 0)
+ return err;

spin_lock(&hugetlb_lock);
h->nr_overcommit_huge_pages = input;
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index bd9bc21..b3fb3f5 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -1557,9 +1557,9 @@ static ssize_t kmemleak_write(struct file *file, const char __user *user_buf,
else if (strncmp(buf, "scan=off", 8) == 0)
stop_scan_thread();
else if (strncmp(buf, "scan=", 5) == 0) {
- unsigned long secs;
+ unsigned int secs;

- ret = strict_strtoul(buf + 5, 0, &secs);
+ ret = kstrtouint(buf + 5, 0, &secs);
if (ret < 0)
goto out;
stop_scan_thread();
diff --git a/mm/ksm.c b/mm/ksm.c
index 43bc893..c03345b 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -1773,15 +1773,11 @@ static ssize_t sleep_millisecs_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
- unsigned long msecs;
int err;

- err = strict_strtoul(buf, 10, &msecs);
- if (err || msecs > UINT_MAX)
- return -EINVAL;
-
- ksm_thread_sleep_millisecs = msecs;
-
+ err = kstrtouint(buf, 10, &ksm_thread_sleep_millisecs);
+ if (err < 0)
+ return err;
return count;
}
KSM_ATTR(sleep_millisecs);
@@ -1797,14 +1793,10 @@ static ssize_t pages_to_scan_store(struct kobject *kobj,
const char *buf, size_t count)
{
int err;
- unsigned long nr_pages;
-
- err = strict_strtoul(buf, 10, &nr_pages);
- if (err || nr_pages > UINT_MAX)
- return -EINVAL;
-
- ksm_thread_pages_to_scan = nr_pages;

+ err = kstrtouint(buf, 10, &ksm_thread_pages_to_scan);
+ if (err < 0)
+ return err;
return count;
}
KSM_ATTR(pages_to_scan);
@@ -1819,11 +1811,11 @@ static ssize_t run_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t count)
{
int err;
- unsigned long flags;
+ unsigned int flags;

- err = strict_strtoul(buf, 10, &flags);
- if (err || flags > UINT_MAX)
- return -EINVAL;
+ err = kstrtouint(buf, 10, &flags);
+ if (err < 0)
+ return err;
if (flags > KSM_RUN_UNMERGE)
return -EINVAL;

diff --git a/mm/slub.c b/mm/slub.c
index 981fb73..3170e52 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3928,11 +3928,11 @@ SLAB_ATTR_RO(objs_per_slab);
static ssize_t order_store(struct kmem_cache *s,
const char *buf, size_t length)
{
- unsigned long order;
+ int order;
int err;

- err = strict_strtoul(buf, 10, &order);
- if (err)
+ err = kstrtoint(buf, 10, &order);
+ if (err < 0)
return err;

if (order > slub_max_order || order < slub_min_order)
@@ -3959,7 +3959,7 @@ static ssize_t min_partial_store(struct kmem_cache *s, const char *buf,
unsigned long min;
int err;

- err = strict_strtoul(buf, 10, &min);
+ err = kstrtoul(buf, 10, &min);
if (err)
return err;

@@ -4219,21 +4219,22 @@ SLAB_ATTR(shrink);
#ifdef CONFIG_NUMA
static ssize_t remote_node_defrag_ratio_show(struct kmem_cache *s, char *buf)
{
- return sprintf(buf, "%d\n", s->remote_node_defrag_ratio / 10);
+ return sprintf(buf, "%u\n", s->remote_node_defrag_ratio / 10);
}

static ssize_t remote_node_defrag_ratio_store(struct kmem_cache *s,
const char *buf, size_t length)
{
- unsigned long ratio;
+ unsigned int ratio;
int err;

- err = strict_strtoul(buf, 10, &ratio);
+ err = kstrtouint(buf, 10, &ratio);
if (err)
return err;
+ if (ratio > 100)
+ return -EINVAL;

- if (ratio <= 100)
- s->remote_node_defrag_ratio = ratio * 10;
+ s->remote_node_defrag_ratio = ratio * 10;

return length;
}
diff --git a/mm/vmscan.c b/mm/vmscan.c
index d31d7ce..61acce3 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -3055,37 +3055,32 @@ int scan_unevictable_handler(struct ctl_table *table, int write,
* per node 'scan_unevictable_pages' attribute. On demand re-scan of
* a specified node's per zone unevictable lists for evictable pages.
*/
-
-static ssize_t read_scan_unevictable_node(struct sys_device *dev,
- struct sysdev_attribute *attr,
- char *buf)
-{
- return sprintf(buf, "0\n"); /* always zero; should fit... */
-}
-
static ssize_t write_scan_unevictable_node(struct sys_device *dev,
struct sysdev_attribute *attr,
const char *buf, size_t count)
{
struct zone *node_zones = NODE_DATA(dev->id)->node_zones;
struct zone *zone;
- unsigned long res;
- unsigned long req = strict_strtoul(buf, 10, &res);
+ unsigned long val;
+ int rv;

- if (!req)
- return 1; /* zero is no-op */
+ rv = kstrtoul(buf, 10, &val);
+ if (rv < 0)
+ return rv;
+ if (val == 0)
+ return count;

for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) {
if (!populated_zone(zone))
continue;
scan_zone_unevictable_pages(zone);
}
- return 1;
+ return count;
}


-static SYSDEV_ATTR(scan_unevictable_pages, S_IRUGO | S_IWUSR,
- read_scan_unevictable_node,
+static SYSDEV_ATTR(scan_unevictable_pages, S_IWUSR,
+ NULL,
write_scan_unevictable_node);

int scan_unevictable_register_node(struct node *node)
--
1.7.2.2

2010-12-05 17:50:20

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 03/45] kstrtox: convert arch/arm/

In arch/arm/mach-omap2/board-omap3touchbook.c:
remove "tbr" parameter, it's unused.

Signed-off-by: Alexey Dobriyan <[email protected]>
---
arch/arm/mach-omap2/board-omap3touchbook.c | 11 -----------
arch/arm/mach-omap2/mux.c | 15 ++++++---------
arch/arm/mach-pxa/balloon3.c | 2 +-
arch/arm/mach-pxa/viper.c | 3 +--
arch/arm/mach-s3c2412/mach-jive.c | 2 +-
arch/arm/mach-ux500/mbox.c | 27 ++++++++-------------------
arch/arm/mach-w90x900/cpu.c | 5 +++--
arch/arm/plat-omap/mcbsp.c | 4 ++--
8 files changed, 22 insertions(+), 47 deletions(-)

diff --git a/arch/arm/mach-omap2/board-omap3touchbook.c b/arch/arm/mach-omap2/board-omap3touchbook.c
index 41104bb..6e57bda 100644
--- a/arch/arm/mach-omap2/board-omap3touchbook.c
+++ b/arch/arm/mach-omap2/board-omap3touchbook.c
@@ -62,8 +62,6 @@
#define TB_BL_PWM_TIMER 9
#define TB_KILL_POWER_GPIO 168

-static unsigned long touchbook_revision;
-
static struct mtd_partition omap3touchbook_nand_partitions[] = {
/* All the partition sizes are listed in terms of NAND block size */
{
@@ -495,15 +493,6 @@ static void omap3_touchbook_poweroff(void)
gpio_direction_output(TB_KILL_POWER_GPIO, 0);
}

-static int __init early_touchbook_revision(char *p)
-{
- if (!p)
- return 0;
-
- return strict_strtoul(p, 10, &touchbook_revision);
-}
-early_param("tbr", early_touchbook_revision);
-
static struct omap_musb_board_data musb_board_data = {
.interface_type = MUSB_INTERFACE_ULPI,
.mode = MUSB_OTG,
diff --git a/arch/arm/mach-omap2/mux.c b/arch/arm/mach-omap2/mux.c
index 074536a..5e2886d 100644
--- a/arch/arm/mach-omap2/mux.c
+++ b/arch/arm/mach-omap2/mux.c
@@ -336,7 +336,7 @@ static ssize_t omap_mux_dbg_signal_write(struct file *file,
char buf[OMAP_MUX_MAX_ARG_CHAR];
struct seq_file *seqf;
struct omap_mux *m;
- unsigned long val;
+ u16 val;
int buf_size, ret;

if (count > OMAP_MUX_MAX_ARG_CHAR)
@@ -348,17 +348,14 @@ static ssize_t omap_mux_dbg_signal_write(struct file *file,
if (copy_from_user(buf, user_buf, buf_size))
return -EFAULT;

- ret = strict_strtoul(buf, 0x10, &val);
+ ret = kstrtou16(buf, 0x10, &val);
if (ret < 0)
return ret;

- if (val > 0xffff)
- return -EINVAL;
-
seqf = file->private_data;
m = seqf->private;

- omap_mux_write((u16)val, m->reg_offset);
+ omap_mux_write(val, m->reg_offset);
*ppos += count;

return count;
@@ -535,18 +532,18 @@ static void __init omap_mux_set_cmdline_signals(void)

while ((token = strsep(&next_opt, ",")) != NULL) {
char *keyval, *name;
- unsigned long val;

keyval = token;
name = strsep(&keyval, "=");
if (name) {
+ u16 val;
int res;

- res = strict_strtoul(keyval, 0x10, &val);
+ res = kstrtou16(keyval, 0x10, &val);
if (res < 0)
continue;

- omap_mux_init_signal(name, (u16)val);
+ omap_mux_init_signal(name, val);
}
}

diff --git a/arch/arm/mach-pxa/balloon3.c b/arch/arm/mach-pxa/balloon3.c
index 21e1889..3748d65 100644
--- a/arch/arm/mach-pxa/balloon3.c
+++ b/arch/arm/mach-pxa/balloon3.c
@@ -91,7 +91,7 @@ int __init parse_balloon3_features(char *arg)
if (!arg)
return 0;

- return strict_strtoul(arg, 0, &balloon3_features_present);
+ return kstrtoul(arg, 0, &balloon3_features_present);
}
early_param("balloon3_features", parse_balloon3_features);

diff --git a/arch/arm/mach-pxa/viper.c b/arch/arm/mach-pxa/viper.c
index 438fc9a..d99ee1b 100644
--- a/arch/arm/mach-pxa/viper.c
+++ b/arch/arm/mach-pxa/viper.c
@@ -767,8 +767,7 @@ static unsigned long viper_tpm;

static int __init viper_tpm_setup(char *str)
{
- strict_strtoul(str, 10, &viper_tpm);
- return 1;
+ return !kstrtoul(str, 10, &viper_tpm);
}

__setup("tpm=", viper_tpm_setup);
diff --git a/arch/arm/mach-s3c2412/mach-jive.c b/arch/arm/mach-s3c2412/mach-jive.c
index 923e01b..a21b119 100644
--- a/arch/arm/mach-s3c2412/mach-jive.c
+++ b/arch/arm/mach-s3c2412/mach-jive.c
@@ -240,7 +240,7 @@ static int __init jive_mtdset(char *options)
if (options == NULL || options[0] == '\0')
return 0;

- if (strict_strtoul(options, 10, &set)) {
+ if (kstrtoul(options, 10, &set)) {
printk(KERN_ERR "failed to parse mtdset=%s\n", options);
return 0;
}
diff --git a/arch/arm/mach-ux500/mbox.c b/arch/arm/mach-ux500/mbox.c
index 6343538..946a6f5 100644
--- a/arch/arm/mach-ux500/mbox.c
+++ b/arch/arm/mach-ux500/mbox.c
@@ -122,29 +122,18 @@ static ssize_t mbox_write_fifo(struct device *dev,
const char *buf,
size_t count)
{
- unsigned long mbox_mess;
- unsigned long nbr_sends;
- unsigned long i;
- char int_buf[16];
- char *token;
- char *val;
-
struct mbox *mbox = (struct mbox *) dev->platform_data;
+ unsigned int mbox_mess, nbr_sends;
+ unsigned int i;

- strncpy((char *) &int_buf, buf, sizeof(int_buf));
- token = (char *) &int_buf;
-
- /* Parse message */
- val = strsep(&token, " ");
- if ((val == NULL) || (strict_strtoul(val, 16, &mbox_mess) != 0))
- mbox_mess = 0xDEADBEEF;
-
- val = strsep(&token, " ");
- if ((val == NULL) || (strict_strtoul(val, 10, &nbr_sends) != 0))
+ if (sscanf(buf, "%u %u", &mbox_mess, &nbr_sends) != 2) {
nbr_sends = 1;
+ if (sscanf(buf, "%u", &mbox_mess) != 1)
+ return -EINVAL;
+ }

- dev_dbg(dev, "Will write 0x%lX %ld times using data struct at 0x%X\n",
- mbox_mess, nbr_sends, (u32) mbox);
+ dev_dbg(dev, "Will write 0x%X %u times using data struct at %p\n",
+ mbox_mess, nbr_sends, mbox);

for (i = 0; i < nbr_sends; i++)
mbox_send(mbox, mbox_mess, true);
diff --git a/arch/arm/mach-w90x900/cpu.c b/arch/arm/mach-w90x900/cpu.c
index 83c5632..67f015c 100644
--- a/arch/arm/mach-w90x900/cpu.c
+++ b/arch/arm/mach-w90x900/cpu.c
@@ -170,12 +170,13 @@ static int __init nuc900_set_clkval(unsigned int cpufreq)
}
static int __init nuc900_set_cpufreq(char *str)
{
- unsigned long cpufreq, val;
+ unsigned int cpufreq, val;

if (!*str)
return 0;

- strict_strtoul(str, 0, &cpufreq);
+ if (kstrtouint(str, 0, &cpufreq) < 0)
+ return 0;

nuc900_clock_source(NULL, "ext");

diff --git a/arch/arm/plat-omap/mcbsp.c b/arch/arm/plat-omap/mcbsp.c
index eac4b97..e049ad3 100644
--- a/arch/arm/plat-omap/mcbsp.c
+++ b/arch/arm/plat-omap/mcbsp.c
@@ -1483,10 +1483,10 @@ static ssize_t prop##_store(struct device *dev, \
const char *buf, size_t size) \
{ \
struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); \
- unsigned long val; \
+ u16 val; \
int status; \
\
- status = strict_strtoul(buf, 0, &val); \
+ status = kstrtou16(buf, 0, &val); \
if (status) \
return status; \
\
--
1.7.2.2

2010-12-05 17:50:31

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 08/45] kstrtox: convert fs/nfs/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
fs/nfs/callback.c | 8 +++--
fs/nfs/idmap.c | 12 +++------
fs/nfs/internal.h | 8 +++---
fs/nfs/super.c | 73 ++++++++++++++++++++++++-----------------------------
4 files changed, 46 insertions(+), 55 deletions(-)

diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
index 93a8b3b..05a9f3d 100644
--- a/fs/nfs/callback.c
+++ b/fs/nfs/callback.c
@@ -46,13 +46,15 @@ unsigned short nfs_callback_tcpport6;

static int param_set_portnr(const char *val, const struct kernel_param *kp)
{
- unsigned long num;
+ unsigned int num;
int ret;

if (!val)
return -EINVAL;
- ret = strict_strtoul(val, 0, &num);
- if (ret == -EINVAL || num > NFS_CALLBACK_MAXPORTNR)
+ ret = kstrtouint(val, 0, &num);
+ if (ret < 0)
+ return ret;
+ if (num > NFS_CALLBACK_MAXPORTNR)
return -EINVAL;
*((unsigned int *)kp->arg) = num;
return 0;
diff --git a/fs/nfs/idmap.c b/fs/nfs/idmap.c
index 4e2d9b6..b3a915a 100644
--- a/fs/nfs/idmap.c
+++ b/fs/nfs/idmap.c
@@ -205,17 +205,13 @@ static int nfs_idmap_lookup_id(const char *name, size_t namelen,
const char *type, __u32 *id)
{
char id_str[NFS_UINT_MAXLEN];
- long id_long;
ssize_t data_size;
- int ret = 0;
+ int ret;

data_size = nfs_idmap_request_key(name, namelen, type, id_str, NFS_UINT_MAXLEN);
- if (data_size <= 0) {
- ret = -EINVAL;
- } else {
- ret = strict_strtol(id_str, 10, &id_long);
- *id = (__u32)id_long;
- }
+ ret = -EINVAL;
+ if (data_size > 0)
+ ret = kstrtou32(id_str, 10, id);
return ret;
}

diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index e6356b7..f12ef9f 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -73,11 +73,11 @@ struct nfs_clone_mount {
*/
struct nfs_parsed_mount_data {
int flags;
- int rsize, wsize;
- int timeo, retrans;
- int acregmin, acregmax,
+ unsigned int rsize, wsize;
+ unsigned int timeo, retrans;
+ unsigned int acregmin, acregmax,
acdirmin, acdirmax;
- int namlen;
+ unsigned int namlen;
unsigned int options;
unsigned int bsize;
unsigned int auth_flavor_len;
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index 3c04504..ddfdc3c 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -1013,7 +1013,8 @@ static int nfs_parse_mount_options(char *raw,

while ((p = strsep(&raw, ",")) != NULL) {
substring_t args[MAX_OPT_ARGS];
- unsigned long option;
+ unsigned int val_uint;
+ u16 val_u16;
int token;

if (!*p)
@@ -1130,154 +1131,146 @@ static int nfs_parse_mount_options(char *raw,
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- rc = strict_strtoul(string, 10, &option);
+ rc = kstrtou16(string, 10, &val_u16);
kfree(string);
- if (rc != 0 || option > USHRT_MAX)
+ if (rc != 0)
goto out_invalid_value;
- mnt->nfs_server.port = option;
+ mnt->nfs_server.port = val_u16;
break;
case Opt_rsize:
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- rc = strict_strtoul(string, 10, &option);
+ rc = kstrtouint(string, 10, &mnt->rsize);
kfree(string);
if (rc != 0)
goto out_invalid_value;
- mnt->rsize = option;
break;
case Opt_wsize:
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- rc = strict_strtoul(string, 10, &option);
+ rc = kstrtouint(string, 10, &mnt->wsize);
kfree(string);
if (rc != 0)
goto out_invalid_value;
- mnt->wsize = option;
break;
case Opt_bsize:
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- rc = strict_strtoul(string, 10, &option);
+ rc = kstrtouint(string, 10, &mnt->bsize);
kfree(string);
if (rc != 0)
goto out_invalid_value;
- mnt->bsize = option;
break;
case Opt_timeo:
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- rc = strict_strtoul(string, 10, &option);
+ rc = kstrtouint(string, 10, &val_uint);
kfree(string);
- if (rc != 0 || option == 0)
+ if (rc != 0 || val_uint == 0)
goto out_invalid_value;
- mnt->timeo = option;
+ mnt->timeo = val_uint;
break;
case Opt_retrans:
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- rc = strict_strtoul(string, 10, &option);
+ rc = kstrtouint(string, 10, &val_uint);
kfree(string);
- if (rc != 0 || option == 0)
+ if (rc != 0 || val_uint == 0)
goto out_invalid_value;
- mnt->retrans = option;
+ mnt->retrans = val_uint;
break;
case Opt_acregmin:
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- rc = strict_strtoul(string, 10, &option);
+ rc = kstrtouint(string, 10, &mnt->acregmin);
kfree(string);
if (rc != 0)
goto out_invalid_value;
- mnt->acregmin = option;
break;
case Opt_acregmax:
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- rc = strict_strtoul(string, 10, &option);
+ rc = kstrtouint(string, 10, &mnt->acregmax);
kfree(string);
if (rc != 0)
goto out_invalid_value;
- mnt->acregmax = option;
break;
case Opt_acdirmin:
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- rc = strict_strtoul(string, 10, &option);
+ rc = kstrtouint(string, 10, &mnt->acdirmin);
kfree(string);
if (rc != 0)
goto out_invalid_value;
- mnt->acdirmin = option;
break;
case Opt_acdirmax:
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- rc = strict_strtoul(string, 10, &option);
+ rc = kstrtouint(string, 10, &mnt->acdirmax);
kfree(string);
if (rc != 0)
goto out_invalid_value;
- mnt->acdirmax = option;
break;
case Opt_actimeo:
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- rc = strict_strtoul(string, 10, &option);
+ rc = kstrtouint(string, 10, &val_uint);
kfree(string);
if (rc != 0)
goto out_invalid_value;
mnt->acregmin = mnt->acregmax =
- mnt->acdirmin = mnt->acdirmax = option;
+ mnt->acdirmin = mnt->acdirmax = val_uint;
break;
case Opt_namelen:
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- rc = strict_strtoul(string, 10, &option);
+ rc = kstrtouint(string, 10, &mnt->namlen);
kfree(string);
if (rc != 0)
goto out_invalid_value;
- mnt->namlen = option;
break;
case Opt_mountport:
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- rc = strict_strtoul(string, 10, &option);
+ rc = kstrtou16(string, 10, &val_u16);
kfree(string);
- if (rc != 0 || option > USHRT_MAX)
+ if (rc != 0)
goto out_invalid_value;
- mnt->mount_server.port = option;
+ mnt->mount_server.port = val_u16;
break;
case Opt_mountvers:
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- rc = strict_strtoul(string, 10, &option);
+ rc = kstrtouint(string, 10, &val_uint);
kfree(string);
if (rc != 0 ||
- option < NFS_MNT_VERSION ||
- option > NFS_MNT3_VERSION)
+ val_uint < NFS_MNT_VERSION ||
+ val_uint > NFS_MNT3_VERSION)
goto out_invalid_value;
- mnt->mount_server.version = option;
+ mnt->mount_server.version = val_uint;
break;
case Opt_nfsvers:
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- rc = strict_strtoul(string, 10, &option);
+ rc = kstrtouint(string, 10, &val_uint);
kfree(string);
if (rc != 0)
goto out_invalid_value;
- switch (option) {
+ switch (val_uint) {
case NFS2_VERSION:
mnt->flags &= ~NFS_MOUNT_VER3;
mnt->version = 2;
@@ -1300,13 +1293,13 @@ static int nfs_parse_mount_options(char *raw,
string = match_strdup(args);
if (string == NULL)
goto out_nomem;
- rc = strict_strtoul(string, 10, &option);
+ rc = kstrtouint(string, 10, &val_uint);
kfree(string);
if (rc != 0)
goto out_invalid_value;
- if (option > NFS4_MAX_MINOR_VERSION)
+ if (val_uint > NFS4_MAX_MINOR_VERSION)
goto out_invalid_value;
- mnt->minorversion = option;
+ mnt->minorversion = val_uint;
break;

/*
--
1.7.2.2

2010-12-05 17:50:36

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 10/45] kstrtox: convert security/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
security/apparmor/lsm.c | 2 +-
security/integrity/ima/ima_audit.c | 2 +-
security/integrity/ima/ima_policy.c | 15 ++++-----------
security/selinux/hooks.c | 4 ++--
security/selinux/selinuxfs.c | 2 +-
security/tomoyo/common.c | 8 +++++---
6 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index b7106f1..990ff86 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -754,7 +754,7 @@ module_param_named(enabled, apparmor_enabled, aabool, S_IRUSR);
static int __init apparmor_enabled_setup(char *str)
{
unsigned long enabled;
- int error = strict_strtoul(str, 0, &enabled);
+ int error = kstrtoul(str, 0, &enabled);
if (!error)
apparmor_enabled = enabled ? 1 : 0;
return 1;
diff --git a/security/integrity/ima/ima_audit.c b/security/integrity/ima/ima_audit.c
index c5c5a72..b4a203c 100644
--- a/security/integrity/ima/ima_audit.c
+++ b/security/integrity/ima/ima_audit.c
@@ -24,7 +24,7 @@ static int __init ima_audit_setup(char *str)
{
unsigned long audit;

- if (!strict_strtoul(str, 0, &audit))
+ if (!kstrtoul(str, 0, &audit))
ima_audit = audit ? 1 : 0;
return 1;
}
diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c
index aef8c0a..7958938 100644
--- a/security/integrity/ima/ima_policy.c
+++ b/security/integrity/ima/ima_policy.c
@@ -276,7 +276,6 @@ static int ima_parse_rule(char *rule, struct ima_measure_rule_entry *entry)
while ((p = strsep(&rule, " \t")) != NULL) {
substring_t args[MAX_OPT_ARGS];
int token;
- unsigned long lnum;

if (result < 0)
break;
@@ -347,8 +346,7 @@ static int ima_parse_rule(char *rule, struct ima_measure_rule_entry *entry)
break;
}

- result = strict_strtoul(args[0].from, 16,
- &entry->fsmagic);
+ result = kstrtoul(args[0].from, 16, &entry->fsmagic);
if (!result)
entry->flags |= IMA_FSMAGIC;
break;
@@ -360,14 +358,9 @@ static int ima_parse_rule(char *rule, struct ima_measure_rule_entry *entry)
break;
}

- result = strict_strtoul(args[0].from, 10, &lnum);
- if (!result) {
- entry->uid = (uid_t) lnum;
- if (entry->uid != lnum)
- result = -EINVAL;
- else
- entry->flags |= IMA_UID;
- }
+ result = kstrtou32(args[0].from, 10, &entry->uid);
+ if (!result)
+ entry->flags |= IMA_UID;
break;
case Opt_obj_user:
ima_log_string(ab, "obj_user", args[0].from);
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 65fa8bf..4ee09bd 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -101,7 +101,7 @@ int selinux_enforcing;
static int __init enforcing_setup(char *str)
{
unsigned long enforcing;
- if (!strict_strtoul(str, 0, &enforcing))
+ if (!kstrtoul(str, 0, &enforcing))
selinux_enforcing = enforcing ? 1 : 0;
return 1;
}
@@ -114,7 +114,7 @@ int selinux_enabled = CONFIG_SECURITY_SELINUX_BOOTPARAM_VALUE;
static int __init selinux_enabled_setup(char *str)
{
unsigned long enabled;
- if (!strict_strtoul(str, 0, &enabled))
+ if (!kstrtoul(str, 0, &enabled))
selinux_enabled = enabled ? 1 : 0;
return 1;
}
diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
index 073fd5b..cdaf958 100644
--- a/security/selinux/selinuxfs.c
+++ b/security/selinux/selinuxfs.c
@@ -50,7 +50,7 @@ unsigned int selinux_checkreqprot = CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE;
static int __init checkreqprot_setup(char *str)
{
unsigned long checkreqprot;
- if (!strict_strtoul(str, 0, &checkreqprot))
+ if (!kstrtoul(str, 0, &checkreqprot))
selinux_checkreqprot = checkreqprot ? 1 : 0;
return 1;
}
diff --git a/security/tomoyo/common.c b/security/tomoyo/common.c
index 7556315..1096c81 100644
--- a/security/tomoyo/common.c
+++ b/security/tomoyo/common.c
@@ -1091,14 +1091,16 @@ static int tomoyo_write_domain_profile(struct tomoyo_io_buffer *head)
char *data = head->write_buf;
char *cp = strchr(data, ' ');
struct tomoyo_domain_info *domain;
- unsigned long profile;
+ unsigned int profile;
+ int rv;

if (!cp)
return -EINVAL;
*cp = '\0';
domain = tomoyo_find_domain(cp + 1);
- if (strict_strtoul(data, 10, &profile))
- return -EINVAL;
+ rv = kstrtouint(data, 10, &profile);
+ if (rv < 0)
+ return rv;
if (domain && profile < TOMOYO_MAX_PROFILES
&& (tomoyo_profile_ptr[profile] || !tomoyo_policy_loaded))
domain->profile = (u8) profile;
--
1.7.2.2

2010-12-05 17:50:41

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 13/45] kstrtox: convert drivers/ata/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/ata/libata-scsi.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 66aa4be..83d3cc0 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -204,7 +204,7 @@ static ssize_t ata_scsi_park_store(struct device *device,
unsigned long flags;
int rc;

- rc = strict_strtol(buf, 10, &input);
+ rc = kstrtol(buf, 10, &input);
if (rc || input < -2)
return -EINVAL;
if (input > ATA_TMOUT_MAX_PARK) {
--
1.7.2.2

2010-12-05 17:50:45

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 14/45] kstrtox: convert drivers/base/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/base/core.c | 6 +++---
drivers/base/memory.c | 10 ++++++----
drivers/base/power/sysfs.c | 9 +++++----
include/linux/device.h | 2 +-
4 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 6ed6454..f4862a4 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -28,13 +28,13 @@

#ifdef CONFIG_SYSFS_DEPRECATED
#ifdef CONFIG_SYSFS_DEPRECATED_V2
-long sysfs_deprecated = 1;
+int sysfs_deprecated = 1;
#else
-long sysfs_deprecated = 0;
+int sysfs_deprecated = 0;
#endif
static __init int sysfs_deprecated_setup(char *arg)
{
- return strict_strtol(arg, 10, &sysfs_deprecated);
+ return kstrtoint(arg, 10, &sysfs_deprecated);
}
early_param("sysfs.deprecated", sysfs_deprecated_setup);
#endif
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index cafeaaf..2dc57aa 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -380,8 +380,9 @@ store_soft_offline_page(struct class *class,
u64 pfn;
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
- if (strict_strtoull(buf, 0, &pfn) < 0)
- return -EINVAL;
+ ret = kstrtou64(buf, 0, &pfn);
+ if (ret < 0)
+ return ret;
pfn >>= PAGE_SHIFT;
if (!pfn_valid(pfn))
return -ENXIO;
@@ -399,8 +400,9 @@ store_hard_offline_page(struct class *class,
u64 pfn;
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
- if (strict_strtoull(buf, 0, &pfn) < 0)
- return -EINVAL;
+ ret = kstrtou64(buf, 0, &pfn);
+ if (ret < 0)
+ return ret;
pfn >>= PAGE_SHIFT;
ret = __memory_failure(pfn, 0, 0);
return ret ? ret : count;
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index 0b1e46b..1397768 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -197,14 +197,15 @@ static ssize_t autosuspend_delay_ms_show(struct device *dev,
static ssize_t autosuspend_delay_ms_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t n)
{
- long delay;
+ int delay;
+ int rv;

if (!dev->power.use_autosuspend)
return -EIO;

- if (strict_strtol(buf, 10, &delay) != 0 || delay != (int) delay)
- return -EINVAL;
-
+ rv = kstrtoint(buf, 10, &delay);
+ if (rv < 0)
+ return rv;
pm_runtime_set_autosuspend_delay(dev, delay);
return n;
}
diff --git a/include/linux/device.h b/include/linux/device.h
index dd48953..f3474dc 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -753,7 +753,7 @@ do { \
MODULE_ALIAS("char-major-" __stringify(major) "-*")

#ifdef CONFIG_SYSFS_DEPRECATED
-extern long sysfs_deprecated;
+extern int sysfs_deprecated;
#else
#define sysfs_deprecated 0
#endif
--
1.7.2.2

2010-12-05 17:50:51

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 15/45] kstrtox: convert drivers/block/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/block/osdblk.c | 10 ++--------
drivers/block/rbd.c | 8 +-------
2 files changed, 3 insertions(+), 15 deletions(-)

diff --git a/drivers/block/osdblk.c b/drivers/block/osdblk.c
index 87311eb..9a645ed 100644
--- a/drivers/block/osdblk.c
+++ b/drivers/block/osdblk.c
@@ -596,18 +596,12 @@ static ssize_t class_osdblk_remove(struct class *c,
{
struct osdblk_device *osdev = NULL;
int target_id, rc;
- unsigned long ul;
struct list_head *tmp;

- rc = strict_strtoul(buf, 10, &ul);
- if (rc)
+ rc = kstrtoint(buf, 10, &target_id);
+ if (rc < 0)
return rc;

- /* convert to int; abort if we lost anything in the conversion */
- target_id = (int) ul;
- if (target_id != ul)
- return -EINVAL;
-
/* remove object from list immediately */
mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 008d4a0..e3baf92 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -1855,18 +1855,12 @@ static ssize_t rbd_remove(struct bus_type *bus,
{
struct rbd_device *rbd_dev = NULL;
int target_id, rc;
- unsigned long ul;
int ret = count;

- rc = strict_strtoul(buf, 10, &ul);
+ rc = kstrtoint(buf, 10, &target_id);
if (rc)
return rc;

- /* convert to int; abort if we lost anything in the conversion */
- target_id = (int) ul;
- if (target_id != ul)
- return -EINVAL;
-
mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);

rbd_dev = __rbd_get_dev(target_id);
--
1.7.2.2

2010-12-05 17:50:56

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 17/45] kstrtox: convert drivers/clocksource/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/clocksource/acpi_pm.c | 14 ++++++--------
1 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/clocksource/acpi_pm.c b/drivers/clocksource/acpi_pm.c
index cfb0f52..2e77b1d 100644
--- a/drivers/clocksource/acpi_pm.c
+++ b/drivers/clocksource/acpi_pm.c
@@ -229,15 +229,13 @@ fs_initcall(init_acpi_pm_clocksource);
*/
static int __init parse_pmtmr(char *arg)
{
- unsigned long base;
+ u32 base;
+ int rv;

- if (strict_strtoul(arg, 16, &base))
- return -EINVAL;
-#ifdef CONFIG_X86_64
- if (base > UINT_MAX)
- return -ERANGE;
-#endif
- printk(KERN_INFO "PMTMR IOPort override: 0x%04x -> 0x%04lx\n",
+ rv = kstrtou32(arg, 16, &base);
+ if (rv < 0)
+ return rv;
+ printk(KERN_INFO "PMTMR IOPort override: 0x%04x -> 0x%04x\n",
pmtmr_ioport, base);
pmtmr_ioport = base;

--
1.7.2.2

2010-12-05 17:51:01

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 18/45] kstrtox: convert drivers/edac/

In amd64_edac_inj.c, make "inject_write", "inject_read" attributes write-only.

Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/edac/amd64_edac_inj.c | 144 ++++++++++++++++-------------------------
drivers/edac/edac_mc_sysfs.c | 23 +++----
drivers/edac/i7core_edac.c | 41 ++++++------
drivers/edac/mce_amd_inj.c | 33 ++++------
4 files changed, 104 insertions(+), 137 deletions(-)

diff --git a/drivers/edac/amd64_edac_inj.c b/drivers/edac/amd64_edac_inj.c
index 29f1f7a..c66556c 100644
--- a/drivers/edac/amd64_edac_inj.c
+++ b/drivers/edac/amd64_edac_inj.c
@@ -16,23 +16,19 @@ static ssize_t amd64_inject_section_store(struct mem_ctl_info *mci,
const char *data, size_t count)
{
struct amd64_pvt *pvt = mci->pvt_info;
- unsigned long value;
- int ret = 0;
-
- ret = strict_strtoul(data, 10, &value);
- if (ret != -EINVAL) {
-
- if (value > 3) {
- amd64_printk(KERN_WARNING,
- "%s: invalid section 0x%lx\n",
- __func__, value);
- return -EINVAL;
- }
-
- pvt->injection.section = (u32) value;
- return count;
+ u32 value;
+ int ret;
+
+ ret = kstrtou32(data, 10, &value);
+ if (ret < 0)
+ return ret;
+ if (value > 3) {
+ amd64_printk(KERN_ERR, "%s: invalid section 0x%x\n",
+ __func__, value);
+ return -EINVAL;
}
- return ret;
+ pvt->injection.section = value;
+ return count;
}

static ssize_t amd64_inject_word_show(struct mem_ctl_info *mci, char *buf)
@@ -51,23 +47,19 @@ static ssize_t amd64_inject_word_store(struct mem_ctl_info *mci,
const char *data, size_t count)
{
struct amd64_pvt *pvt = mci->pvt_info;
- unsigned long value;
- int ret = 0;
-
- ret = strict_strtoul(data, 10, &value);
- if (ret != -EINVAL) {
-
- if (value > 8) {
- amd64_printk(KERN_WARNING,
- "%s: invalid word 0x%lx\n",
- __func__, value);
- return -EINVAL;
- }
-
- pvt->injection.word = (u32) value;
- return count;
+ u32 value;
+ int ret;
+
+ ret = kstrtou32(data, 10, &value);
+ if (ret < 0)
+ return ret;
+ if (value > 8) {
+ amd64_printk(KERN_ERR, "%s: invalid word 0x%x\n",
+ __func__, value);
+ return -EINVAL;
}
- return ret;
+ pvt->injection.word = value;
+ return count;
}

static ssize_t amd64_inject_ecc_vector_show(struct mem_ctl_info *mci, char *buf)
@@ -85,23 +77,19 @@ static ssize_t amd64_inject_ecc_vector_store(struct mem_ctl_info *mci,
const char *data, size_t count)
{
struct amd64_pvt *pvt = mci->pvt_info;
- unsigned long value;
- int ret = 0;
-
- ret = strict_strtoul(data, 16, &value);
- if (ret != -EINVAL) {
-
- if (value & 0xFFFF0000) {
- amd64_printk(KERN_WARNING,
- "%s: invalid EccVector: 0x%lx\n",
- __func__, value);
- return -EINVAL;
- }
-
- pvt->injection.bit_map = (u32) value;
- return count;
+ u32 value;
+ int ret;
+
+ ret = kstrtou32(data, 16, &value);
+ if (ret < 0)
+ return ret;
+ if (value & 0xFFFF0000) {
+ amd64_printk(KERN_ERR, "%s: invalid EccVector: 0x%x\n",
+ __func__, value);
+ return -EINVAL;
}
- return ret;
+ pvt->injection.bit_map = value;
+ return count;
}

/*
@@ -112,31 +100,22 @@ static ssize_t amd64_inject_read_store(struct mem_ctl_info *mci,
const char *data, size_t count)
{
struct amd64_pvt *pvt = mci->pvt_info;
- unsigned long value;
u32 section, word_bits;
- int ret = 0;
-
- ret = strict_strtoul(data, 10, &value);
- if (ret != -EINVAL) {

- /* Form value to choose 16-byte section of cacheline */
- section = F10_NB_ARRAY_DRAM_ECC |
- SET_NB_ARRAY_ADDRESS(pvt->injection.section);
- pci_write_config_dword(pvt->misc_f3_ctl,
- F10_NB_ARRAY_ADDR, section);
+ /* Form value to choose 16-byte section of cacheline */
+ section = F10_NB_ARRAY_DRAM_ECC |
+ SET_NB_ARRAY_ADDRESS(pvt->injection.section);
+ pci_write_config_dword(pvt->misc_f3_ctl, F10_NB_ARRAY_ADDR, section);

- word_bits = SET_NB_DRAM_INJECTION_READ(pvt->injection.word,
- pvt->injection.bit_map);
+ word_bits = SET_NB_DRAM_INJECTION_READ(pvt->injection.word,
+ pvt->injection.bit_map);

- /* Issue 'word' and 'bit' along with the READ request */
- pci_write_config_dword(pvt->misc_f3_ctl,
- F10_NB_ARRAY_DATA, word_bits);
+ /* Issue 'word' and 'bit' along with the READ request */
+ pci_write_config_dword(pvt->misc_f3_ctl, F10_NB_ARRAY_DATA, word_bits);

- debugf0("section=0x%x word_bits=0x%x\n", section, word_bits);
+ debugf0("section=0x%x word_bits=0x%x\n", section, word_bits);

- return count;
- }
- return ret;
+ return count;
}

/*
@@ -147,31 +126,22 @@ static ssize_t amd64_inject_write_store(struct mem_ctl_info *mci,
const char *data, size_t count)
{
struct amd64_pvt *pvt = mci->pvt_info;
- unsigned long value;
u32 section, word_bits;
- int ret = 0;

- ret = strict_strtoul(data, 10, &value);
- if (ret != -EINVAL) {
+ /* Form value to choose 16-byte section of cacheline */
+ section = F10_NB_ARRAY_DRAM_ECC |
+ SET_NB_ARRAY_ADDRESS(pvt->injection.section);
+ pci_write_config_dword(pvt->misc_f3_ctl, F10_NB_ARRAY_ADDR, section);

- /* Form value to choose 16-byte section of cacheline */
- section = F10_NB_ARRAY_DRAM_ECC |
- SET_NB_ARRAY_ADDRESS(pvt->injection.section);
- pci_write_config_dword(pvt->misc_f3_ctl,
- F10_NB_ARRAY_ADDR, section);
-
- word_bits = SET_NB_DRAM_INJECTION_WRITE(pvt->injection.word,
+ word_bits = SET_NB_DRAM_INJECTION_WRITE(pvt->injection.word,
pvt->injection.bit_map);

- /* Issue 'word' and 'bit' along with the READ request */
- pci_write_config_dword(pvt->misc_f3_ctl,
- F10_NB_ARRAY_DATA, word_bits);
+ /* Issue 'word' and 'bit' along with the READ request */
+ pci_write_config_dword(pvt->misc_f3_ctl, F10_NB_ARRAY_DATA, word_bits);

- debugf0("section=0x%x word_bits=0x%x\n", section, word_bits);
+ debugf0("section=0x%x word_bits=0x%x\n", section, word_bits);

- return count;
- }
- return ret;
+ return count;
}

/*
@@ -206,7 +176,7 @@ struct mcidev_sysfs_attribute amd64_inj_attrs[] = {
{
.attr = {
.name = "inject_write",
- .mode = (S_IRUGO | S_IWUSR)
+ .mode = S_IWUSR,
},
.show = NULL,
.store = amd64_inject_write_store,
@@ -214,7 +184,7 @@ struct mcidev_sysfs_attribute amd64_inj_attrs[] = {
{
.attr = {
.name = "inject_read",
- .mode = (S_IRUGO | S_IWUSR)
+ .mode = S_IWUSR,
},
.show = NULL,
.store = amd64_inject_read_store,
diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
index dce61f7..644a5b6 100644
--- a/drivers/edac/edac_mc_sysfs.c
+++ b/drivers/edac/edac_mc_sysfs.c
@@ -48,19 +48,17 @@ int edac_mc_get_poll_msec(void)

static int edac_set_poll_msec(const char *val, struct kernel_param *kp)
{
- long l;
int ret;

if (!val)
return -EINVAL;

- ret = strict_strtol(val, 0, &l);
- if (ret == -EINVAL || ((int)l != l))
- return -EINVAL;
- *((int *)kp->arg) = l;
+ ret = kstrtoint(val, 0, (int *)kp->arg);
+ if (ret < 0)
+ return ret;

/* notify edac_mc engine to reset the poll period */
- edac_mc_reset_delay_period(l);
+ edac_mc_reset_delay_period(*(int *)kp->arg);

return 0;
}
@@ -440,7 +438,7 @@ static ssize_t mci_reset_counters_store(struct mem_ctl_info *mci,
static ssize_t mci_sdram_scrub_rate_store(struct mem_ctl_info *mci,
const char *data, size_t count)
{
- unsigned long bandwidth = 0;
+ u32 bandwidth;
int err;

if (!mci->set_sdram_scrub_rate) {
@@ -449,18 +447,19 @@ static ssize_t mci_sdram_scrub_rate_store(struct mem_ctl_info *mci,
return -EINVAL;
}

- if (strict_strtoul(data, 10, &bandwidth) < 0)
- return -EINVAL;
+ err = kstrtou32(data, 10, &bandwidth);
+ if (err < 0)
+ return err;

- err = mci->set_sdram_scrub_rate(mci, (u32)bandwidth);
+ err = mci->set_sdram_scrub_rate(mci, bandwidth);
if (err) {
edac_printk(KERN_DEBUG, EDAC_MC,
- "Failed setting scrub rate to %lu\n", bandwidth);
+ "Failed setting scrub rate to %u\n", bandwidth);
return -EINVAL;
}
else {
edac_printk(KERN_DEBUG, EDAC_MC,
- "Scrub rate set to: %lu\n", bandwidth);
+ "Scrub rate set to: %u\n", bandwidth);
return count;
}
}
diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
index 362861c..3e580e0 100644
--- a/drivers/edac/i7core_edac.c
+++ b/drivers/edac/i7core_edac.c
@@ -774,17 +774,19 @@ static ssize_t i7core_inject_section_store(struct mem_ctl_info *mci,
const char *data, size_t count)
{
struct i7core_pvt *pvt = mci->pvt_info;
- unsigned long value;
+ u32 value;
int rc;

if (pvt->inject.enable)
disable_inject(mci);

- rc = strict_strtoul(data, 10, &value);
- if ((rc < 0) || (value > 3))
+ rc = kstrtou32(data, 10, &value);
+ if (rc < 0)
+ return rc;
+ if (value > 3)
return -EIO;

- pvt->inject.section = (u32) value;
+ pvt->inject.section = value;
return count;
}

@@ -807,17 +809,19 @@ static ssize_t i7core_inject_type_store(struct mem_ctl_info *mci,
const char *data, size_t count)
{
struct i7core_pvt *pvt = mci->pvt_info;
- unsigned long value;
+ u32 value;
int rc;

if (pvt->inject.enable)
disable_inject(mci);

- rc = strict_strtoul(data, 10, &value);
- if ((rc < 0) || (value > 7))
+ rc = kstrtou32(data, 10, &value);
+ if (rc < 0)
+ return rc;
+ if (value > 7)
return -EIO;

- pvt->inject.type = (u32) value;
+ pvt->inject.type = value;
return count;
}

@@ -842,17 +846,14 @@ static ssize_t i7core_inject_eccmask_store(struct mem_ctl_info *mci,
const char *data, size_t count)
{
struct i7core_pvt *pvt = mci->pvt_info;
- unsigned long value;
int rc;

if (pvt->inject.enable)
disable_inject(mci);

- rc = strict_strtoul(data, 10, &value);
+ rc = kstrtou32(data, 10, &pvt->inject.eccmask);
if (rc < 0)
- return -EIO;
-
- pvt->inject.eccmask = (u32) value;
+ return rc;
return count;
}

@@ -892,8 +893,10 @@ static ssize_t i7core_inject_store_##param( \
if (!strcasecmp(data, "any") || !strcasecmp(data, "any\n"))\
value = -1; \
else { \
- rc = strict_strtoul(data, 10, &value); \
- if ((rc < 0) || (value >= limit)) \
+ rc = kstrtoul(data, 10, &value); \
+ if (rc < 0) \
+ return rc; \
+ if (value >= limit) \
return -EIO; \
} \
\
@@ -985,14 +988,14 @@ static ssize_t i7core_inject_enable_store(struct mem_ctl_info *mci,
u32 injectmask;
u64 mask = 0;
int rc;
- long enable;
+ unsigned long enable;

if (!pvt->pci_ch[pvt->inject.channel][0])
return 0;

- rc = strict_strtoul(data, 10, &enable);
- if ((rc < 0))
- return 0;
+ rc = kstrtoul(data, 10, &enable);
+ if (rc < 0)
+ return rc;

if (enable) {
pvt->inject.enable = 1;
diff --git a/drivers/edac/mce_amd_inj.c b/drivers/edac/mce_amd_inj.c
index 39faded..794be1a 100644
--- a/drivers/edac/mce_amd_inj.c
+++ b/drivers/edac/mce_amd_inj.c
@@ -39,15 +39,13 @@ static ssize_t edac_inject_##reg##_store(struct kobject *kobj, \
struct edac_mce_attr *attr, \
const char *data, size_t count)\
{ \
- int ret = 0; \
- unsigned long value; \
+ int ret; \
\
- ret = strict_strtoul(data, 16, &value); \
- if (ret < 0) \
+ ret = kstrtou64(data, 16, &i_mce.reg); \
+ if (ret < 0) { \
printk(KERN_ERR "Error writing MCE " #reg " field.\n"); \
- \
- i_mce.reg = value; \
- \
+ return ret; \
+ } \
return count; \
}

@@ -79,21 +77,18 @@ static ssize_t edac_inject_bank_store(struct kobject *kobj,
struct edac_mce_attr *attr,
const char *data, size_t count)
{
- int ret = 0;
- unsigned long value;
-
- ret = strict_strtoul(data, 10, &value);
- if (ret < 0) {
- printk(KERN_ERR "Invalid bank value!\n");
- return -EINVAL;
- }
-
- if (value > 5) {
- printk(KERN_ERR "Non-existant MCE bank: %lu\n", value);
+ u8 bank;
+ int ret;
+
+ ret = kstrtou8(data, 10, &bank);
+ if (ret < 0)
+ return ret;
+ if (bank > 5) {
+ printk(KERN_ERR "Non-existant MCE bank: %hhu\n", bank);
return -EINVAL;
}

- i_mce.bank = value;
+ i_mce.bank = bank;

amd_decode_mce(NULL, 0, &i_mce);

--
1.7.2.2

2010-12-05 17:51:06

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 20/45] kstrtox: convert drivers/gpu/drm/nouveau/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/gpu/drm/nouveau/nouveau_pm.c | 16 ++++++++++------
1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_pm.c b/drivers/gpu/drm/nouveau/nouveau_pm.c
index 9f7b158..a2cdef5 100644
--- a/drivers/gpu/drm/nouveau/nouveau_pm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_pm.c
@@ -315,10 +315,12 @@ nouveau_hwmon_set_max_temp(struct device *d, struct device_attribute *a,
struct drm_nouveau_private *dev_priv = dev->dev_private;
struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
struct nouveau_pm_threshold_temp *temp = &pm->threshold_temp;
- long value;
+ int value;
+ int rv;

- if (strict_strtol(buf, 10, &value) == -EINVAL)
- return count;
+ rv = kstrtoint(buf, 10, &value);
+ if (rv < 0)
+ return rv;

temp->down_clock = value/1000;

@@ -350,10 +352,12 @@ nouveau_hwmon_set_critical_temp(struct device *d, struct device_attribute *a,
struct drm_nouveau_private *dev_priv = dev->dev_private;
struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
struct nouveau_pm_threshold_temp *temp = &pm->threshold_temp;
- long value;
+ int value;
+ int rv;

- if (strict_strtol(buf, 10, &value) == -EINVAL)
- return count;
+ rv = kstrtoint(buf, 10, &value);
+ if (rv < 0)
+ return rv;

temp->critical = value/1000;

--
1.7.2.2

2010-12-05 17:51:13

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 23/45] kstrtox: convert drivers/ide/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/ide/ide-park.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/ide/ide-park.c b/drivers/ide/ide-park.c
index 88a380c..436ca71 100644
--- a/drivers/ide/ide-park.c
+++ b/drivers/ide/ide-park.c
@@ -113,11 +113,13 @@ ssize_t ide_park_store(struct device *dev, struct device_attribute *attr,
{
#define MAX_PARK_TIMEOUT 30000
ide_drive_t *drive = to_ide_device(dev);
- long int input;
+ int input;
int rc;

- rc = strict_strtol(buf, 10, &input);
- if (rc || input < -2)
+ rc = kstrtoint(buf, 10, &input);
+ if (rc < 0)
+ return rc;
+ if (input < -2)
return -EINVAL;
if (input > MAX_PARK_TIMEOUT) {
input = MAX_PARK_TIMEOUT;
--
1.7.2.2

2010-12-05 17:51:16

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 22/45] kstrtox: convert drivers/hwmon/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/hwmon/adcxx.c | 8 ++-
drivers/hwmon/adm1031.c | 6 +-
drivers/hwmon/adt7411.c | 8 ++-
drivers/hwmon/adt7462.c | 87 ++++++++++++++++-------
drivers/hwmon/adt7470.c | 80 ++++++++++++++-------
drivers/hwmon/adt7475.c | 83 ++++++++++++---------
drivers/hwmon/amc6821.c | 45 ++++++++----
drivers/hwmon/asc7621.c | 83 ++++++++++++++--------
drivers/hwmon/emc1403.c | 17 +++--
drivers/hwmon/emc2103.c | 32 +++++----
drivers/hwmon/f71882fg.c | 62 ++++++++--------
drivers/hwmon/g760a.c | 6 +-
drivers/hwmon/gpio-fan.c | 24 +++++--
drivers/hwmon/ibmaem.c | 4 +-
drivers/hwmon/it87.c | 109 +++++++++++++++++++---------
drivers/hwmon/jc42.c | 34 +++++----
drivers/hwmon/lis3lv02d.c | 8 ++-
drivers/hwmon/lm73.c | 3 +-
drivers/hwmon/lm75.c | 4 +-
drivers/hwmon/lm90.c | 16 ++--
drivers/hwmon/lm95241.c | 176 +++++++++++++++++++++------------------------
drivers/hwmon/pc87427.c | 20 ++++--
drivers/hwmon/tmp102.c | 5 +-
drivers/hwmon/tmp401.c | 37 ++++++----
drivers/hwmon/w83791d.c | 28 +++++---
drivers/hwmon/w83795.c | 109 ++++++++++++++++++----------
26 files changed, 661 insertions(+), 433 deletions(-)

diff --git a/drivers/hwmon/adcxx.c b/drivers/hwmon/adcxx.c
index fbdc765..b6367e8 100644
--- a/drivers/hwmon/adcxx.c
+++ b/drivers/hwmon/adcxx.c
@@ -123,10 +123,12 @@ static ssize_t adcxx_set_max(struct device *dev,
{
struct spi_device *spi = to_spi_device(dev);
struct adcxx *adc = dev_get_drvdata(&spi->dev);
- unsigned long value;
+ u32 value;
+ int rv;

- if (strict_strtoul(buf, 10, &value))
- return -EINVAL;
+ rv = kstrtou32(buf, 10, &value);
+ if (rv < 0)
+ return rv;

if (mutex_lock_interruptible(&adc->lock))
return -ERESTARTSYS;
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c
index 0683e6b..641a7e9 100644
--- a/drivers/hwmon/adm1031.c
+++ b/drivers/hwmon/adm1031.c
@@ -763,12 +763,12 @@ static ssize_t set_update_interval(struct device *dev,
{
struct i2c_client *client = to_i2c_client(dev);
struct adm1031_data *data = i2c_get_clientdata(client);
- unsigned long val;
+ unsigned int val;
int i, err;
u8 reg;

- err = strict_strtoul(buf, 10, &val);
- if (err)
+ err = kstrtouint(buf, 10, &val);
+ if (err < 0)
return err;

/*
diff --git a/drivers/hwmon/adt7411.c b/drivers/hwmon/adt7411.c
index f13c843..dbc35a8 100644
--- a/drivers/hwmon/adt7411.c
+++ b/drivers/hwmon/adt7411.c
@@ -195,10 +195,12 @@ static ssize_t adt7411_set_bit(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7411_data *data = i2c_get_clientdata(client);
int ret;
- unsigned long flag;
+ unsigned int flag;

- ret = strict_strtoul(buf, 0, &flag);
- if (ret || flag > 1)
+ ret = kstrtouint(buf, 0, &flag);
+ if (ret < 0)
+ return ret;
+ if (flag > 1)
return -EINVAL;

ret = adt7411_modify_bit(client, s_attr2->index, s_attr2->nr, flag);
diff --git a/drivers/hwmon/adt7462.c b/drivers/hwmon/adt7462.c
index 2af0c7b..c9a3dcb 100644
--- a/drivers/hwmon/adt7462.c
+++ b/drivers/hwmon/adt7462.c
@@ -832,8 +832,12 @@ static ssize_t set_temp_min(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7462_data *data = i2c_get_clientdata(client);
long temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp) || !temp_enabled(data, attr->index))
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;
+ if (!temp_enabled(data, attr->index))
return -EINVAL;

temp = DIV_ROUND_CLOSEST(temp, 1000) + 64;
@@ -870,8 +874,12 @@ static ssize_t set_temp_max(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7462_data *data = i2c_get_clientdata(client);
long temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp) || !temp_enabled(data, attr->index))
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;
+ if (!temp_enabled(data, attr->index))
return -EINVAL;

temp = DIV_ROUND_CLOSEST(temp, 1000) + 64;
@@ -934,8 +942,12 @@ static ssize_t set_volt_max(struct device *dev,
struct adt7462_data *data = i2c_get_clientdata(client);
int x = voltage_multiplier(data, attr->index);
long temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp) || !x)
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;
+ if (!x)
return -EINVAL;

temp *= 1000; /* convert mV to uV */
@@ -976,8 +988,12 @@ static ssize_t set_volt_min(struct device *dev,
struct adt7462_data *data = i2c_get_clientdata(client);
int x = voltage_multiplier(data, attr->index);
long temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp) || !x)
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;
+ if (!x)
return -EINVAL;

temp *= 1000; /* convert mV to uV */
@@ -1065,9 +1081,12 @@ static ssize_t set_fan_min(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7462_data *data = i2c_get_clientdata(client);
long temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp) || !temp ||
- !fan_enabled(data, attr->index))
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;
+ if (!temp || !fan_enabled(data, attr->index))
return -EINVAL;

temp = FAN_RPM_TO_PERIOD(temp);
@@ -1114,9 +1133,11 @@ static ssize_t set_force_pwm_max(struct device *dev,
struct adt7462_data *data = i2c_get_clientdata(client);
long temp;
u8 reg;
+ int rv;

- if (strict_strtol(buf, 10, &temp))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->lock);
reg = i2c_smbus_read_byte_data(client, ADT7462_REG_CFG2);
@@ -1146,9 +1167,11 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr,
struct i2c_client *client = to_i2c_client(dev);
struct adt7462_data *data = i2c_get_clientdata(client);
long temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;

temp = SENSORS_LIMIT(temp, 0, 255);

@@ -1176,9 +1199,11 @@ static ssize_t set_pwm_max(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7462_data *data = i2c_get_clientdata(client);
long temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;

temp = SENSORS_LIMIT(temp, 0, 255);

@@ -1208,9 +1233,11 @@ static ssize_t set_pwm_min(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7462_data *data = i2c_get_clientdata(client);
long temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;

temp = SENSORS_LIMIT(temp, 0, 255);

@@ -1242,9 +1269,11 @@ static ssize_t set_pwm_hyst(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7462_data *data = i2c_get_clientdata(client);
long temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;

temp = DIV_ROUND_CLOSEST(temp, 1000);
temp = SENSORS_LIMIT(temp, 0, 15);
@@ -1288,9 +1317,11 @@ static ssize_t set_pwm_tmax(struct device *dev,
struct adt7462_data *data = i2c_get_clientdata(client);
int tmin, trange_value;
long trange;
+ int rv;

- if (strict_strtol(buf, 10, &trange))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &trange);
+ if (rv < 0)
+ return rv;

/* trange = tmax - tmin */
tmin = (data->pwm_tmin[attr->index] - 64) * 1000;
@@ -1329,9 +1360,11 @@ static ssize_t set_pwm_tmin(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7462_data *data = i2c_get_clientdata(client);
long temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;

temp = DIV_ROUND_CLOSEST(temp, 1000) + 64;
temp = SENSORS_LIMIT(temp, 0, 255);
@@ -1385,10 +1418,12 @@ static ssize_t set_pwm_auto(struct device *dev,
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct i2c_client *client = to_i2c_client(dev);
struct adt7462_data *data = i2c_get_clientdata(client);
- long temp;
+ int temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp))
- return -EINVAL;
+ rv = kstrtoint(buf, 10, &temp);
+ if (rv < 0)
+ return rv;

switch (temp) {
case 0: /* off */
@@ -1445,9 +1480,11 @@ static ssize_t set_pwm_auto_temp(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7462_data *data = i2c_get_clientdata(client);
long temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;

temp = cvt_auto_temp(temp);
if (temp < 0)
diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
index 87d92a5..1e59699 100644
--- a/drivers/hwmon/adt7470.c
+++ b/drivers/hwmon/adt7470.c
@@ -446,9 +446,11 @@ static ssize_t set_auto_update_interval(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7470_data *data = i2c_get_clientdata(client);
long temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;

temp = SENSORS_LIMIT(temp, 0, 60000);

@@ -475,9 +477,11 @@ static ssize_t set_num_temp_sensors(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7470_data *data = i2c_get_clientdata(client);
long temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;

temp = SENSORS_LIMIT(temp, -1, 10);

@@ -508,9 +512,11 @@ static ssize_t set_temp_min(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7470_data *data = i2c_get_clientdata(client);
long temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;

temp = DIV_ROUND_CLOSEST(temp, 1000);
temp = SENSORS_LIMIT(temp, 0, 255);
@@ -542,9 +548,11 @@ static ssize_t set_temp_max(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7470_data *data = i2c_get_clientdata(client);
long temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;

temp = DIV_ROUND_CLOSEST(temp, 1000);
temp = SENSORS_LIMIT(temp, 0, 255);
@@ -597,8 +605,12 @@ static ssize_t set_fan_max(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7470_data *data = i2c_get_clientdata(client);
long temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp) || !temp)
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;
+ if (!temp)
return -EINVAL;

temp = FAN_RPM_TO_PERIOD(temp);
@@ -634,8 +646,12 @@ static ssize_t set_fan_min(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7470_data *data = i2c_get_clientdata(client);
long temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp) || !temp)
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;
+ if (!temp)
return -EINVAL;

temp = FAN_RPM_TO_PERIOD(temp);
@@ -679,9 +695,11 @@ static ssize_t set_force_pwm_max(struct device *dev,
struct adt7470_data *data = i2c_get_clientdata(client);
long temp;
u8 reg;
+ int rv;

- if (strict_strtol(buf, 10, &temp))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->lock);
data->force_pwm_max = temp;
@@ -711,9 +729,11 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr,
struct i2c_client *client = to_i2c_client(dev);
struct adt7470_data *data = i2c_get_clientdata(client);
long temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;

temp = SENSORS_LIMIT(temp, 0, 255);

@@ -743,9 +763,11 @@ static ssize_t set_pwm_max(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7470_data *data = i2c_get_clientdata(client);
long temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;

temp = SENSORS_LIMIT(temp, 0, 255);

@@ -776,9 +798,11 @@ static ssize_t set_pwm_min(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7470_data *data = i2c_get_clientdata(client);
long temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;

temp = SENSORS_LIMIT(temp, 0, 255);

@@ -819,9 +843,11 @@ static ssize_t set_pwm_tmin(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct adt7470_data *data = i2c_get_clientdata(client);
long temp;
+ int rv;

- if (strict_strtol(buf, 10, &temp))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;

temp = DIV_ROUND_CLOSEST(temp, 1000);
temp = SENSORS_LIMIT(temp, 0, 255);
@@ -854,11 +880,13 @@ static ssize_t set_pwm_auto(struct device *dev,
struct adt7470_data *data = i2c_get_clientdata(client);
int pwm_auto_reg = ADT7470_REG_PWM_CFG(attr->index);
int pwm_auto_reg_mask;
- long temp;
+ u8 temp;
u8 reg;
+ int rv;

- if (strict_strtol(buf, 10, &temp))
- return -EINVAL;
+ rv = kstrtou8(buf, 10, &temp);
+ if (rv < 0)
+ return rv;

if (attr->index % 2)
pwm_auto_reg_mask = ADT7470_PWM2_AUTO_MASK;
@@ -916,9 +944,11 @@ static ssize_t set_pwm_auto_temp(struct device *dev,
int pwm_auto_reg = ADT7470_REG_PWM_AUTO_TEMP(attr->index);
long temp;
u8 reg;
+ int rv;

- if (strict_strtol(buf, 10, &temp))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &temp);
+ if (rv < 0)
+ return rv;

temp = cvt_auto_temp(temp);
if (temp < 0)
diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
index b5fcd87..e1867fc 100644
--- a/drivers/hwmon/adt7475.c
+++ b/drivers/hwmon/adt7475.c
@@ -342,9 +342,11 @@ static ssize_t set_voltage(struct device *dev, struct device_attribute *attr,
struct adt7475_data *data = i2c_get_clientdata(client);
unsigned char reg;
long val;
+ int rv;

- if (strict_strtol(buf, 10, &val))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->lock);

@@ -431,9 +433,11 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
u8 out;
int temp;
long val;
+ int rv;

- if (strict_strtol(buf, 10, &val))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->lock);

@@ -545,9 +549,11 @@ static ssize_t set_point2(struct device *dev, struct device_attribute *attr,
struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
int temp;
long val;
+ int rv;

- if (strict_strtol(buf, 10, &val))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->lock);

@@ -601,9 +607,11 @@ static ssize_t set_tach(struct device *dev, struct device_attribute *attr,
struct i2c_client *client = to_i2c_client(dev);
struct adt7475_data *data = i2c_get_clientdata(client);
unsigned long val;
+ int rv;

- if (strict_strtoul(buf, 10, &val))
- return -EINVAL;
+ rv = kstrtoul(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->lock);

@@ -652,9 +660,11 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
struct adt7475_data *data = i2c_get_clientdata(client);
unsigned char reg = 0;
long val;
+ int rv;

- if (strict_strtol(buf, 10, &val))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->lock);

@@ -755,20 +765,20 @@ static ssize_t set_pwmchan(struct device *dev, struct device_attribute *attr,
struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
struct i2c_client *client = to_i2c_client(dev);
struct adt7475_data *data = i2c_get_clientdata(client);
- int r;
long val;
+ int rv;

- if (strict_strtol(buf, 10, &val))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->lock);
/* Read Modify Write PWM values */
adt7475_read_pwm(client, sattr->index);
- r = hw_set_pwm(client, sattr->index, data->pwmctl[sattr->index], val);
- if (r)
- count = r;
+ rv = hw_set_pwm(client, sattr->index, data->pwmctl[sattr->index], val);
mutex_unlock(&data->lock);
-
+ if (rv < 0)
+ return rv;
return count;
}

@@ -778,20 +788,20 @@ static ssize_t set_pwmctrl(struct device *dev, struct device_attribute *attr,
struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
struct i2c_client *client = to_i2c_client(dev);
struct adt7475_data *data = i2c_get_clientdata(client);
- int r;
long val;
+ int rv;

- if (strict_strtol(buf, 10, &val))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->lock);
/* Read Modify Write PWM values */
adt7475_read_pwm(client, sattr->index);
- r = hw_set_pwm(client, sattr->index, val, data->pwmchan[sattr->index]);
- if (r)
- count = r;
+ rv = hw_set_pwm(client, sattr->index, val, data->pwmchan[sattr->index]);
mutex_unlock(&data->lock);
-
+ if (rv < 0)
+ return rv;
return count;
}

@@ -818,9 +828,11 @@ static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr,
struct adt7475_data *data = i2c_get_clientdata(client);
int out;
long val;
+ int rv;

- if (strict_strtol(buf, 10, &val))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &val);
+ if (rv < 0)
+ return rv;

out = find_nearest(val, pwmfreq_table, ARRAY_SIZE(pwmfreq_table));

@@ -851,10 +863,12 @@ static ssize_t set_pwm_at_crit(struct device *dev,
{
struct i2c_client *client = to_i2c_client(dev);
struct adt7475_data *data = i2c_get_clientdata(client);
- long val;
+ int val;
+ int rv;

- if (strict_strtol(buf, 10, &val))
- return -EINVAL;
+ rv = kstrtoint(buf, 10, &val);
+ if (rv < 0)
+ return rv;
if (val != 0 && val != 1)
return -EINVAL;

@@ -881,14 +895,11 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *devattr,
const char *buf, size_t count)
{
struct adt7475_data *data = dev_get_drvdata(dev);
- long val;
-
- if (strict_strtol(buf, 10, &val))
- return -EINVAL;
- if (val < 0 || val > 255)
- return -EINVAL;
- data->vrm = val;
+ int rv;

+ rv = kstrtou8(buf, 10, &data->vrm);
+ if (rv < 0)
+ return rv;
return count;
}

diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c
index 4033974..b010cf4 100644
--- a/drivers/hwmon/amc6821.c
+++ b/drivers/hwmon/amc6821.c
@@ -237,9 +237,10 @@ static ssize_t set_temp(
struct amc6821_data *data = i2c_get_clientdata(client);
int ix = to_sensor_dev_attr(attr)->index;
long val;
+ int ret;

- int ret = strict_strtol(buf, 10, &val);
- if (ret)
+ ret = kstrtol(buf, 10, &val);
+ if (ret < 0)
return ret;
val = SENSORS_LIMIT(val / 1000, -128, 127);

@@ -327,8 +328,10 @@ static ssize_t set_pwm1(
struct i2c_client *client = to_i2c_client(dev);
struct amc6821_data *data = i2c_get_clientdata(client);
long val;
- int ret = strict_strtol(buf, 10, &val);
- if (ret)
+ int ret;
+
+ ret = kstrtol(buf, 10, &val);
+ if (ret < 0)
return ret;

mutex_lock(&data->update_lock);
@@ -355,9 +358,11 @@ static ssize_t set_pwm1_enable(
{
struct i2c_client *client = to_i2c_client(dev);
struct amc6821_data *data = i2c_get_clientdata(client);
- long val;
- int config = strict_strtol(buf, 10, &val);
- if (config)
+ int val;
+ int config;
+
+ config = kstrtoint(buf, 10, &val);
+ if (config < 0)
return config;

config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF1);
@@ -477,8 +482,10 @@ static ssize_t set_temp_auto_point_temp(
u8 reg;
int dpwm;
long val;
- int ret = strict_strtol(buf, 10, &val);
- if (ret)
+ int ret;
+
+ ret = kstrtol(buf, 10, &val);
+ if (ret < 0)
return ret;

switch (nr) {
@@ -556,8 +563,10 @@ static ssize_t set_pwm1_auto_point_pwm(
struct amc6821_data *data = i2c_get_clientdata(client);
int dpwm;
long val;
- int ret = strict_strtol(buf, 10, &val);
- if (ret)
+ int ret;
+
+ ret = kstrtol(buf, 10, &val);
+ if (ret < 0)
return ret;

mutex_lock(&data->update_lock);
@@ -623,8 +632,10 @@ static ssize_t set_fan(
struct amc6821_data *data = i2c_get_clientdata(client);
long val;
int ix = to_sensor_dev_attr(attr)->index;
- int ret = strict_strtol(buf, 10, &val);
- if (ret)
+ int ret;
+
+ ret = kstrtol(buf, 10, &val);
+ if (ret < 0)
return ret;
val = 1 > val ? 0xFFFF : 6000000/val;

@@ -664,9 +675,11 @@ static ssize_t set_fan1_div(
{
struct i2c_client *client = to_i2c_client(dev);
struct amc6821_data *data = i2c_get_clientdata(client);
- long val;
- int config = strict_strtol(buf, 10, &val);
- if (config)
+ int val;
+ int config;
+
+ config = kstrtoint(buf, 10, &val);
+ if (config < 0)
return config;

config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF4);
diff --git a/drivers/hwmon/asc7621.c b/drivers/hwmon/asc7621.c
index d2596ce..03aa1bd 100644
--- a/drivers/hwmon/asc7621.c
+++ b/drivers/hwmon/asc7621.c
@@ -187,9 +187,11 @@ static ssize_t store_u8(struct device *dev, struct device_attribute *attr,
{
SETUP_STORE_data_param(dev, attr);
long reqval;
+ int rv;

- if (strict_strtol(buf, 10, &reqval))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &reqval);
+ if (rv < 0)
+ return rv;

reqval = SENSORS_LIMIT(reqval, 0, 255);

@@ -220,9 +222,11 @@ static ssize_t store_bitmask(struct device *dev,
SETUP_STORE_data_param(dev, attr);
long reqval;
u8 currval;
+ int rv;

- if (strict_strtol(buf, 10, &reqval))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &reqval);
+ if (rv < 0)
+ return rv;

reqval = SENSORS_LIMIT(reqval, 0, param->mask[0]);

@@ -264,9 +268,11 @@ static ssize_t store_fan16(struct device *dev,
{
SETUP_STORE_data_param(dev, attr);
long reqval;
+ int rv;

- if (strict_strtol(buf, 10, &reqval))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &reqval);
+ if (rv < 0)
+ return rv;

/* If a minimum RPM of zero is requested, then we set the register to
0xffff. This value allows the fan to be stopped completely without
@@ -337,9 +343,11 @@ static ssize_t store_in8(struct device *dev, struct device_attribute *attr,
SETUP_STORE_data_param(dev, attr);
long reqval;
u8 nr = sda->index;
+ int rv;

- if (strict_strtol(buf, 10, &reqval))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &reqval);
+ if (rv < 0)
+ return rv;

reqval = SENSORS_LIMIT(reqval, 0, 0xffff);

@@ -370,9 +378,11 @@ static ssize_t store_temp8(struct device *dev,
SETUP_STORE_data_param(dev, attr);
long reqval;
s8 temp;
+ int rv;

- if (strict_strtol(buf, 10, &reqval))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &reqval);
+ if (rv < 0)
+ return rv;

reqval = SENSORS_LIMIT(reqval, -127000, 127000);

@@ -426,9 +436,11 @@ static ssize_t store_temp62(struct device *dev,
SETUP_STORE_data_param(dev, attr);
long reqval, i, f;
s8 temp;
+ int rv;

- if (strict_strtol(buf, 10, &reqval))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &reqval);
+ if (rv < 0)
+ return rv;

reqval = SENSORS_LIMIT(reqval, -32000, 31750);
i = reqval / 1000;
@@ -481,9 +493,11 @@ static ssize_t store_ap2_temp(struct device *dev,
long reqval, auto_point1;
int i;
u8 currval, newval = 0;
+ int rv;

- if (strict_strtol(buf, 10, &reqval))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &reqval);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->update_lock);
auto_point1 = data->reg[param->msb[1]] * 1000;
@@ -529,7 +543,7 @@ static ssize_t store_pwm_ac(struct device *dev,
const char *buf, size_t count)
{
SETUP_STORE_data_param(dev, attr);
- unsigned long reqval;
+ u8 reqval;
u8 currval, config, altbit, newval;
u16 map[] = {
0x04, 0x00, 0x01, 0xff, 0x02, 0xff, 0x05, 0x06,
@@ -537,10 +551,11 @@ static ssize_t store_pwm_ac(struct device *dev,
0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03,
};
+ int rv;

- if (strict_strtoul(buf, 10, &reqval))
- return -EINVAL;
-
+ rv = kstrtou8(buf, 10, &reqval);
+ if (rv < 0)
+ return rv;
if (reqval > 31)
return -EINVAL;

@@ -598,11 +613,13 @@ static ssize_t store_pwm_enable(struct device *dev,
const char *buf, size_t count)
{
SETUP_STORE_data_param(dev, attr);
- long reqval;
+ int reqval;
u8 currval, config, altbit, newval, minoff = 255;
+ int rv;

- if (strict_strtol(buf, 10, &reqval))
- return -EINVAL;
+ rv = kstrtoint(buf, 10, &reqval);
+ if (rv < 0)
+ return rv;

switch (reqval) {
case 0:
@@ -671,12 +688,14 @@ static ssize_t store_pwm_freq(struct device *dev,
const char *buf, size_t count)
{
SETUP_STORE_data_param(dev, attr);
- unsigned long reqval;
+ u32 reqval;
u8 currval, newval = 255;
int i;
+ int rv;

- if (strict_strtoul(buf, 10, &reqval))
- return -EINVAL;
+ rv = kstrtou32(buf, 10, &reqval);
+ if (rv < 0)
+ return rv;

for (i = 0; i < ARRAY_SIZE(asc7621_pwm_freq_map); i++) {
if (reqval == asc7621_pwm_freq_map[i]) {
@@ -720,12 +739,14 @@ static ssize_t store_pwm_ast(struct device *dev,
const char *buf, size_t count)
{
SETUP_STORE_data_param(dev, attr);
- long reqval;
+ u32 reqval;
u8 currval, newval = 255;
u32 i;
+ int rv;

- if (strict_strtol(buf, 10, &reqval))
- return -EINVAL;
+ rv = kstrtou32(buf, 10, &reqval);
+ if (rv < 0)
+ return rv;

for (i = 0; i < ARRAY_SIZE(asc7621_pwm_auto_spinup_map); i++) {
if (reqval == asc7621_pwm_auto_spinup_map[i]) {
@@ -767,12 +788,14 @@ static ssize_t store_temp_st(struct device *dev,
const char *buf, size_t count)
{
SETUP_STORE_data_param(dev, attr);
- long reqval;
+ u32 reqval;
u8 currval, newval = 255;
u32 i;
+ int rv;

- if (strict_strtol(buf, 10, &reqval))
- return -EINVAL;
+ rv = kstrtou32(buf, 10, &reqval);
+ if (rv < 0)
+ return rv;

for (i = 0; i < ARRAY_SIZE(asc7621_temp_smoothing_time_map); i++) {
if (reqval == asc7621_temp_smoothing_time_map[i]) {
diff --git a/drivers/hwmon/emc1403.c b/drivers/hwmon/emc1403.c
index 8dee3f3..5d6f7ea 100644
--- a/drivers/hwmon/emc1403.c
+++ b/drivers/hwmon/emc1403.c
@@ -80,8 +80,9 @@ static ssize_t store_temp(struct device *dev,
unsigned long val;
int retval;

- if (strict_strtoul(buf, 10, &val))
- return -EINVAL;
+ retval = kstrtoul(buf, 10, &val);
+ if (retval < 0)
+ return retval;
retval = i2c_smbus_write_byte_data(client, sda->index,
DIV_ROUND_CLOSEST(val, 1000));
if (retval < 0)
@@ -95,11 +96,12 @@ static ssize_t store_bit(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct thermal_data *data = i2c_get_clientdata(client);
struct sensor_device_attribute_2 *sda = to_sensor_dev_attr_2(attr);
- unsigned long val;
+ int val;
int retval;

- if (strict_strtoul(buf, 10, &val))
- return -EINVAL;
+ retval = kstrtoint(buf, 10, &val);
+ if (retval < 0)
+ return retval;

mutex_lock(&data->mutex);
retval = i2c_smbus_read_byte_data(client, sda->nr);
@@ -151,8 +153,9 @@ static ssize_t store_hyst(struct device *dev,
int hyst;
unsigned long val;

- if (strict_strtoul(buf, 10, &val))
- return -EINVAL;
+ retval = kstrtoul(buf, 10, &val);
+ if (retval < 0)
+ return retval;

mutex_lock(&data->mutex);
retval = i2c_smbus_read_byte_data(client, sda->index);
diff --git a/drivers/hwmon/emc2103.c b/drivers/hwmon/emc2103.c
index af914ad..72bcc0e 100644
--- a/drivers/hwmon/emc2103.c
+++ b/drivers/hwmon/emc2103.c
@@ -243,10 +243,11 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *da,
struct i2c_client *client = to_i2c_client(dev);
struct emc2103_data *data = i2c_get_clientdata(client);
long val;
+ int result;

- int result = strict_strtol(buf, 10, &val);
+ result = kstrtol(buf, 10, &val);
if (result < 0)
- return -EINVAL;
+ return result;

val = DIV_ROUND_CLOSEST(val, 1000);
if ((val < -63) || (val > 127))
@@ -267,10 +268,11 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *da,
struct i2c_client *client = to_i2c_client(dev);
struct emc2103_data *data = i2c_get_clientdata(client);
long val;
+ int result;

- int result = strict_strtol(buf, 10, &val);
+ result = kstrtol(buf, 10, &val);
if (result < 0)
- return -EINVAL;
+ return result;

val = DIV_ROUND_CLOSEST(val, 1000);
if ((val < -63) || (val > 127))
@@ -313,10 +315,11 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *da,
struct i2c_client *client = to_i2c_client(dev);
int new_range_bits, old_div = 8 / data->fan_multiplier;
long new_div;
+ int status;

- int status = strict_strtol(buf, 10, &new_div);
+ status = kstrtol(buf, 10, &new_div);
if (status < 0)
- return -EINVAL;
+ return status;

if (new_div == old_div) /* No change */
return count;
@@ -386,14 +389,14 @@ static ssize_t set_fan_target(struct device *dev, struct device_attribute *da,
{
struct emc2103_data *data = emc2103_update_device(dev);
struct i2c_client *client = to_i2c_client(dev);
- long rpm_target;
+ unsigned int rpm_target;
+ int result;

- int result = strict_strtol(buf, 10, &rpm_target);
+ result = kstrtouint(buf, 10, &rpm_target);
if (result < 0)
- return -EINVAL;
-
+ return result;
/* Datasheet states 16384 as maximum RPM target (table 3.2) */
- if ((rpm_target < 0) || (rpm_target > 16384))
+ if (rpm_target > 16384)
return -EINVAL;

mutex_lock(&data->update_lock);
@@ -431,12 +434,13 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *da,
{
struct i2c_client *client = to_i2c_client(dev);
struct emc2103_data *data = i2c_get_clientdata(client);
- long new_value;
+ int new_value;
u8 conf_reg;
+ int result;

- int result = strict_strtol(buf, 10, &new_value);
+ result = kstrtoint(buf, 10, &new_value);
if (result < 0)
- return -EINVAL;
+ return result;

mutex_lock(&data->update_lock);
switch (new_value) {
diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c
index 75afb3b..3c02296 100644
--- a/drivers/hwmon/f71882fg.c
+++ b/drivers/hwmon/f71882fg.c
@@ -1134,8 +1134,8 @@ static ssize_t store_fan_full_speed(struct device *dev,
int err, nr = to_sensor_dev_attr_2(devattr)->index;
long val;

- err = strict_strtol(buf, 10, &val);
- if (err)
+ err = kstrtol(buf, 10, &val);
+ if (err < 0)
return err;

val = SENSORS_LIMIT(val, 23, 1500000);
@@ -1168,8 +1168,8 @@ static ssize_t store_fan_beep(struct device *dev, struct device_attribute
int err, nr = to_sensor_dev_attr_2(devattr)->index;
unsigned long val;

- err = strict_strtoul(buf, 10, &val);
- if (err)
+ err = kstrtoul(buf, 10, &val);
+ if (err < 0)
return err;

mutex_lock(&data->update_lock);
@@ -1221,8 +1221,8 @@ static ssize_t store_in_max(struct device *dev, struct device_attribute
int err;
long val;

- err = strict_strtol(buf, 10, &val);
- if (err)
+ err = kstrtol(buf, 10, &val);
+ if (err < 0)
return err;

val /= 8;
@@ -1255,8 +1255,8 @@ static ssize_t store_in_beep(struct device *dev, struct device_attribute
int err, nr = to_sensor_dev_attr_2(devattr)->index;
unsigned long val;

- err = strict_strtoul(buf, 10, &val);
- if (err)
+ err = kstrtoul(buf, 10, &val);
+ if (err < 0)
return err;

mutex_lock(&data->update_lock);
@@ -1325,8 +1325,8 @@ static ssize_t store_temp_max(struct device *dev, struct device_attribute
int err, nr = to_sensor_dev_attr_2(devattr)->index;
long val;

- err = strict_strtol(buf, 10, &val);
- if (err)
+ err = kstrtol(buf, 10, &val);
+ if (err < 0)
return err;

val /= 1000;
@@ -1367,8 +1367,8 @@ static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
u8 reg;
long val;

- err = strict_strtol(buf, 10, &val);
- if (err)
+ err = kstrtol(buf, 10, &val);
+ if (err < 0)
return err;

val /= 1000;
@@ -1410,8 +1410,8 @@ static ssize_t store_temp_crit(struct device *dev, struct device_attribute
int err, nr = to_sensor_dev_attr_2(devattr)->index;
long val;

- err = strict_strtol(buf, 10, &val);
- if (err)
+ err = kstrtol(buf, 10, &val);
+ if (err < 0)
return err;

val /= 1000;
@@ -1471,8 +1471,8 @@ static ssize_t store_temp_beep(struct device *dev, struct device_attribute
int err, nr = to_sensor_dev_attr_2(devattr)->index;
unsigned long val;

- err = strict_strtoul(buf, 10, &val);
- if (err)
+ err = kstrtoul(buf, 10, &val);
+ if (err < 0)
return err;

mutex_lock(&data->update_lock);
@@ -1538,8 +1538,8 @@ static ssize_t store_pwm(struct device *dev,
int err, nr = to_sensor_dev_attr_2(devattr)->index;
long val;

- err = strict_strtol(buf, 10, &val);
- if (err)
+ err = kstrtol(buf, 10, &val);
+ if (err < 0)
return err;

val = SENSORS_LIMIT(val, 0, 255);
@@ -1604,8 +1604,8 @@ static ssize_t store_pwm_enable(struct device *dev, struct device_attribute
int err, nr = to_sensor_dev_attr_2(devattr)->index;
long val;

- err = strict_strtol(buf, 10, &val);
- if (err)
+ err = kstrtol(buf, 10, &val);
+ if (err < 0)
return err;

/* Special case for F8000 pwm channel 3 which only does auto mode */
@@ -1684,8 +1684,8 @@ static ssize_t store_pwm_auto_point_pwm(struct device *dev,
int point = to_sensor_dev_attr_2(devattr)->nr;
long val;

- err = strict_strtol(buf, 10, &val);
- if (err)
+ err = kstrtol(buf, 10, &val);
+ if (err < 0)
return err;

val = SENSORS_LIMIT(val, 0, 255);
@@ -1738,8 +1738,8 @@ static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
u8 reg;
long val;

- err = strict_strtol(buf, 10, &val);
- if (err)
+ err = kstrtol(buf, 10, &val);
+ if (err < 0)
return err;

val /= 1000;
@@ -1784,8 +1784,8 @@ static ssize_t store_pwm_interpolate(struct device *dev,
int err, nr = to_sensor_dev_attr_2(devattr)->index;
unsigned long val;

- err = strict_strtoul(buf, 10, &val);
- if (err)
+ err = kstrtoul(buf, 10, &val);
+ if (err < 0)
return err;

mutex_lock(&data->update_lock);
@@ -1822,10 +1822,10 @@ static ssize_t store_pwm_auto_point_channel(struct device *dev,
{
struct f71882fg_data *data = dev_get_drvdata(dev);
int err, nr = to_sensor_dev_attr_2(devattr)->index;
- long val;
+ u8 val;

- err = strict_strtol(buf, 10, &val);
- if (err)
+ err = kstrtou8(buf, 10, &val);
+ if (err < 0)
return err;

switch (val) {
@@ -1875,8 +1875,8 @@ static ssize_t store_pwm_auto_point_temp(struct device *dev,
int point = to_sensor_dev_attr_2(devattr)->nr;
long val;

- err = strict_strtol(buf, 10, &val);
- if (err)
+ err = kstrtol(buf, 10, &val);
+ if (err < 0)
return err;

val /= 1000;
diff --git a/drivers/hwmon/g760a.c b/drivers/hwmon/g760a.c
index 1d6a6fa..32191de 100644
--- a/drivers/hwmon/g760a.c
+++ b/drivers/hwmon/g760a.c
@@ -165,9 +165,11 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *da,
struct i2c_client *client = to_i2c_client(dev);
struct g760a_data *data = g760a_update_client(dev);
unsigned long val;
+ int rv;

- if (strict_strtoul(buf, 10, &val))
- return -EINVAL;
+ rv = kstrtoul(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->update_lock);
data->set_cnt = PWM_TO_CNT(SENSORS_LIMIT(val, 0, 255));
diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c
index f141a1d..5e7bc1e 100644
--- a/drivers/hwmon/gpio-fan.c
+++ b/drivers/hwmon/gpio-fan.c
@@ -222,11 +222,15 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
struct gpio_fan_data *fan_data = dev_get_drvdata(dev);
unsigned long pwm;
int speed_index;
- int ret = count;
+ int ret;

- if (strict_strtoul(buf, 10, &pwm) || pwm > 255)
+ ret = kstrtoul(buf, 10, &pwm);
+ if (ret < 0)
+ return ret;
+ if (pwm > 255)
return -EINVAL;

+ ret = count;
mutex_lock(&fan_data->lock);

if (!fan_data->pwm_enable) {
@@ -255,9 +259,13 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct gpio_fan_data *fan_data = dev_get_drvdata(dev);
- unsigned long val;
+ int val;
+ int rv;

- if (strict_strtoul(buf, 10, &val) || val > 1)
+ rv = kstrtoint(buf, 10, &val);
+ if (rv < 0)
+ return rv;
+ if (val > 1)
return -EINVAL;

if (fan_data->pwm_enable == val)
@@ -312,11 +320,13 @@ static ssize_t set_rpm(struct device *dev, struct device_attribute *attr,
{
struct gpio_fan_data *fan_data = dev_get_drvdata(dev);
unsigned long rpm;
- int ret = count;
+ int ret;

- if (strict_strtoul(buf, 10, &rpm))
- return -EINVAL;
+ ret = kstrtoul(buf, 10, &rpm);
+ if (ret < 0)
+ return ret;

+ ret = count;
mutex_lock(&fan_data->lock);

if (!fan_data->pwm_enable) {
diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
index eaee546..d84497b 100644
--- a/drivers/hwmon/ibmaem.c
+++ b/drivers/hwmon/ibmaem.c
@@ -920,8 +920,8 @@ static ssize_t aem_set_power_period(struct device *dev,
unsigned long temp;
int res;

- res = strict_strtoul(buf, 10, &temp);
- if (res)
+ res = kstrtoul(buf, 10, &temp);
+ if (res < 0)
return res;

if (temp < AEM_MIN_POWER_INTERVAL)
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index 14a5d98..632e769 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -433,9 +433,11 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,

struct it87_data *data = dev_get_drvdata(dev);
unsigned long val;
+ int rv;

- if (strict_strtoul(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtoul(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->update_lock);
data->in_min[nr] = in_to_reg(data, nr, val);
@@ -452,9 +454,11 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,

struct it87_data *data = dev_get_drvdata(dev);
unsigned long val;
+ int rv;

- if (strict_strtoul(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtoul(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->update_lock);
data->in_max[nr] = in_to_reg(data, nr, val);
@@ -528,9 +532,11 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,

struct it87_data *data = dev_get_drvdata(dev);
long val;
+ int rv;

- if (strict_strtol(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtol(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->update_lock);
data->temp_high[nr] = TEMP_TO_REG(val);
@@ -546,9 +552,11 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,

struct it87_data *data = dev_get_drvdata(dev);
long val;
+ int rv;

- if (strict_strtol(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtol(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->update_lock);
data->temp_low[nr] = TEMP_TO_REG(val);
@@ -591,11 +599,13 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
int nr = sensor_attr->index;

struct it87_data *data = dev_get_drvdata(dev);
- long val;
+ int val;
u8 reg;
+ int rv;

- if (strict_strtol(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtoint(buf, 10, &val);
+ if (rv < 0)
+ return rv;

reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
reg &= ~(1 << nr);
@@ -707,9 +717,11 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
struct it87_data *data = dev_get_drvdata(dev);
long val;
u8 reg;
+ int rv;

- if (strict_strtol(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtol(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->update_lock);
reg = it87_read_value(data, IT87_REG_FAN_DIV);
@@ -740,9 +752,11 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
unsigned long val;
int min;
u8 old;
+ int rv;

- if (strict_strtoul(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtoul(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->update_lock);
old = it87_read_value(data, IT87_REG_FAN_DIV);
@@ -808,9 +822,13 @@ static ssize_t set_pwm_enable(struct device *dev,
int nr = sensor_attr->index;

struct it87_data *data = dev_get_drvdata(dev);
- long val;
+ int val;
+ int rv;

- if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 2)
+ rv = kstrtoint(buf, 10, &val);
+ if (rv < 0)
+ return rv;
+ if (val < 0 || val > 2)
return -EINVAL;

/* Check trip points before switching to automatic mode */
@@ -853,8 +871,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,

struct it87_data *data = dev_get_drvdata(dev);
long val;
+ int rv;

- if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 255)
+ rv = kstrtol(buf, 10, &val);
+ if (rv < 0)
+ return rv;
+ if (val < 0 || val > 255)
return -EINVAL;

mutex_lock(&data->update_lock);
@@ -874,9 +896,11 @@ static ssize_t set_pwm_freq(struct device *dev,
struct it87_data *data = dev_get_drvdata(dev);
unsigned long val;
int i;
+ int rv;

- if (strict_strtoul(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtoul(buf, 10, &val);
+ if (rv < 0)
+ return rv;

/* Search for the nearest available frequency */
for (i = 0; i < 7; i++) {
@@ -914,8 +938,9 @@ static ssize_t set_pwm_temp_map(struct device *dev,
int nr = sensor_attr->index;

struct it87_data *data = dev_get_drvdata(dev);
- long val;
+ int val;
u8 reg;
+ int rv;

/* This check can go away if we ever support automatic fan speed
control on newer chips. */
@@ -924,8 +949,9 @@ static ssize_t set_pwm_temp_map(struct device *dev,
return -EINVAL;
}

- if (strict_strtol(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtoint(buf, 10, &val);
+ if (rv < 0)
+ return rv;

switch (val) {
case (1 << 0):
@@ -975,8 +1001,12 @@ static ssize_t set_auto_pwm(struct device *dev,
int nr = sensor_attr->nr;
int point = sensor_attr->index;
long val;
+ int rv;

- if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 255)
+ rv = kstrtol(buf, 10, &val);
+ if (rv < 0)
+ return rv;
+ if (val < 0 || val > 255)
return -EINVAL;

mutex_lock(&data->update_lock);
@@ -1008,8 +1038,12 @@ static ssize_t set_auto_temp(struct device *dev,
int nr = sensor_attr->nr;
int point = sensor_attr->index;
long val;
+ int rv;

- if (strict_strtol(buf, 10, &val) < 0 || val < -128000 || val > 127000)
+ rv = kstrtol(buf, 10, &val);
+ if (rv < 0)
+ return rv;
+ if (val < -128000 || val > 127000)
return -EINVAL;

mutex_lock(&data->update_lock);
@@ -1100,9 +1134,11 @@ static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr,
int nr = sensor_attr->index;
struct it87_data *data = dev_get_drvdata(dev);
long val;
+ int rv;

- if (strict_strtol(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtol(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->update_lock);
data->fan_min[nr] = FAN16_TO_REG(val);
@@ -1176,10 +1212,13 @@ static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
{
int bitnr = to_sensor_dev_attr(attr)->index;
struct it87_data *data = dev_get_drvdata(dev);
- long val;
+ int val;
+ int rv;

- if (strict_strtol(buf, 10, &val) < 0
- || (val != 0 && val != 1))
+ rv = kstrtoint(buf, 10, &val);
+ if (rv < 0)
+ return rv;
+ if (val != 0 && val != 1)
return -EINVAL;

mutex_lock(&data->update_lock);
@@ -1223,13 +1262,11 @@ static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct it87_data *data = dev_get_drvdata(dev);
- unsigned long val;
-
- if (strict_strtoul(buf, 10, &val) < 0)
- return -EINVAL;
-
- data->vrm = val;
+ int rv;

+ rv = kstrtou8(buf, 10, &data->vrm);
+ if (rv < 0)
+ return rv;
return count;
}
static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
diff --git a/drivers/hwmon/jc42.c b/drivers/hwmon/jc42.c
index 340fc78..2f269f8 100644
--- a/drivers/hwmon/jc42.c
+++ b/drivers/hwmon/jc42.c
@@ -307,17 +307,19 @@ static ssize_t set_##value(struct device *dev, \
{ \
struct i2c_client *client = to_i2c_client(dev); \
struct jc42_data *data = i2c_get_clientdata(client); \
- int err, ret = count; \
- long val; \
- if (strict_strtol(buf, 10, &val) < 0) \
- return -EINVAL; \
+ int val; \
+ int ret; \
+ \
+ ret = kstrtoint(buf, 10, &val); \
+ if (ret < 0) \
+ return ret; \
mutex_lock(&data->update_lock); \
data->value = jc42_temp_to_reg(val, data->extended); \
- err = jc42_write_value(client, reg, data->value); \
- if (err < 0) \
- ret = err; \
+ ret = jc42_write_value(client, reg, data->value); \
mutex_unlock(&data->update_lock); \
- return ret; \
+ if (ret < 0) \
+ return ret; \
+ return count; \
}

set(temp_min, JC42_REG_TEMP_LOWER);
@@ -334,11 +336,11 @@ static ssize_t set_temp_crit_hyst(struct device *dev,
struct jc42_data *data = i2c_get_clientdata(client);
long val;
int diff, hyst;
- int err;
- int ret = count;
+ int ret;

- if (strict_strtoul(buf, 10, &val) < 0)
- return -EINVAL;
+ ret = kstrtoul(buf, 10, &val);
+ if (ret < 0)
+ return ret;

diff = jc42_temp_from_reg(data->temp_crit) - val;
hyst = 0;
@@ -355,11 +357,11 @@ static ssize_t set_temp_crit_hyst(struct device *dev,
data->config = (data->config
& ~(JC42_CFG_HYST_MASK << JC42_CFG_HYST_SHIFT))
| (hyst << JC42_CFG_HYST_SHIFT);
- err = jc42_write_value(client, JC42_REG_CONFIG, data->config);
- if (err < 0)
- ret = err;
+ ret = jc42_write_value(client, JC42_REG_CONFIG, data->config);
mutex_unlock(&data->update_lock);
- return ret;
+ if (ret < 0)
+ return ret;
+ return count;
}

static ssize_t show_alarm(struct device *dev,
diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c
index 0cee73a..c681910 100644
--- a/drivers/hwmon/lis3lv02d.c
+++ b/drivers/hwmon/lis3lv02d.c
@@ -752,10 +752,12 @@ static ssize_t lis3lv02d_rate_set(struct device *dev,
struct device_attribute *attr, const char *buf,
size_t count)
{
- unsigned long rate;
+ int rate;
+ int rv;

- if (strict_strtoul(buf, 0, &rate))
- return -EINVAL;
+ rv = kstrtoint(buf, 0, &rate);
+ if (rv < 0)
+ return rv;

lis3lv02d_sysfs_poweron(&lis3_dev);
if (lis3lv02d_set_odr(rate))
diff --git a/drivers/hwmon/lm73.c b/drivers/hwmon/lm73.c
index 29b9030..0ab02a6 100644
--- a/drivers/hwmon/lm73.c
+++ b/drivers/hwmon/lm73.c
@@ -49,8 +49,9 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
struct i2c_client *client = to_i2c_client(dev);
long temp;
short value;
+ int status;

- int status = strict_strtol(buf, 10, &temp);
+ status = kstrtol(buf, 10, &temp);
if (status < 0)
return status;

diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index f36eb80..dfddb06 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -106,8 +106,8 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
long temp;
int error;

- error = strict_strtol(buf, 10, &temp);
- if (error)
+ error = kstrtol(buf, 10, &temp);
+ if (error < 0)
return error;

mutex_lock(&data->update_lock);
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index 812781c..34907f5 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -708,7 +708,7 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
long val;
int err;

- err = strict_strtol(buf, 10, &val);
+ err = kstrtol(buf, 10, &val);
if (err < 0)
return err;

@@ -776,7 +776,7 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
long val;
int err;

- err = strict_strtol(buf, 10, &val);
+ err = kstrtol(buf, 10, &val);
if (err < 0)
return err;

@@ -837,7 +837,7 @@ static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy,
int err;
int temp;

- err = strict_strtol(buf, 10, &val);
+ err = kstrtol(buf, 10, &val);
if (err < 0)
return err;

@@ -887,11 +887,11 @@ static ssize_t set_update_interval(struct device *dev,
{
struct i2c_client *client = to_i2c_client(dev);
struct lm90_data *data = i2c_get_clientdata(client);
- unsigned long val;
+ unsigned int val;
int err;

- err = strict_strtoul(buf, 10, &val);
- if (err)
+ err = kstrtouint(buf, 10, &val);
+ if (err < 0)
return err;

mutex_lock(&data->update_lock);
@@ -1055,10 +1055,10 @@ static ssize_t set_pec(struct device *dev, struct device_attribute *dummy,
const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
- long val;
+ int val;
int err;

- err = strict_strtol(buf, 10, &val);
+ err = kstrtoint(buf, 10, &val);
if (err < 0)
return err;

diff --git a/drivers/hwmon/lm95241.c b/drivers/hwmon/lm95241.c
index 4546d82..bb88bea 100644
--- a/drivers/hwmon/lm95241.c
+++ b/drivers/hwmon/lm95241.c
@@ -129,9 +129,11 @@ static ssize_t set_interval(struct device *dev, struct device_attribute *attr,
struct i2c_client *client = to_i2c_client(dev);
struct lm95241_data *data = i2c_get_clientdata(client);
unsigned long val;
+ int rv;

- if (strict_strtoul(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtoul(buf, 10, &val);
+ if (rv < 0)
+ return rv;

data->interval = val * HZ / 1000;

@@ -182,106 +184,92 @@ static ssize_t show_max##flag(struct device *dev, \
show_max(1);
show_max(2);

-#define set_type(flag) \
-static ssize_t set_type##flag(struct device *dev, \
- struct device_attribute *attr, \
- const char *buf, size_t count) \
-{ \
- struct i2c_client *client = to_i2c_client(dev); \
- struct lm95241_data *data = i2c_get_clientdata(client); \
-\
- long val; \
-\
- if (strict_strtol(buf, 10, &val) < 0) \
- return -EINVAL; \
-\
- if ((val == 1) || (val == 2)) { \
-\
- mutex_lock(&data->update_lock); \
-\
- data->trutherm &= ~(TT_MASK << TT##flag##_SHIFT); \
- if (val == 1) { \
- data->model |= R##flag##MS_MASK; \
- data->trutherm |= (TT_ON << TT##flag##_SHIFT); \
- } \
- else { \
- data->model &= ~R##flag##MS_MASK; \
- data->trutherm |= (TT_OFF << TT##flag##_SHIFT); \
- } \
-\
- data->valid = 0; \
-\
- i2c_smbus_write_byte_data(client, LM95241_REG_RW_REMOTE_MODEL, \
- data->model); \
- i2c_smbus_write_byte_data(client, LM95241_REG_RW_TRUTHERM, \
- data->trutherm); \
-\
- mutex_unlock(&data->update_lock); \
-\
- } \
- return count; \
+#define set_type(flag) \
+static ssize_t set_type##flag(struct device *dev, \
+ struct device_attribute *attr, \
+ const char *buf, size_t count) \
+{ \
+ struct i2c_client *client = to_i2c_client(dev); \
+ struct lm95241_data *data = i2c_get_clientdata(client); \
+ int val; \
+ int rv; \
+ \
+ rv = kstrtoint(buf, 10, &val); \
+ if (rv < 0) \
+ return rv; \
+ if (val != 1 && val != 2) \
+ return -EINVAL; \
+ \
+ mutex_lock(&data->update_lock); \
+ data->trutherm &= ~(TT_MASK << TT##flag##_SHIFT); \
+ if (val == 1) { \
+ data->model |= R##flag##MS_MASK; \
+ data->trutherm |= (TT_ON << TT##flag##_SHIFT); \
+ } else { \
+ data->model &= ~R##flag##MS_MASK; \
+ data->trutherm |= (TT_OFF << TT##flag##_SHIFT); \
+ } \
+ data->valid = 0; \
+ i2c_smbus_write_byte_data(client, LM95241_REG_RW_REMOTE_MODEL, \
+ data->model); \
+ i2c_smbus_write_byte_data(client, LM95241_REG_RW_TRUTHERM, \
+ data->trutherm); \
+ mutex_unlock(&data->update_lock); \
+ return count; \
}
set_type(1);
set_type(2);

-#define set_min(flag) \
-static ssize_t set_min##flag(struct device *dev, \
- struct device_attribute *devattr, const char *buf, size_t count) \
-{ \
- struct i2c_client *client = to_i2c_client(dev); \
- struct lm95241_data *data = i2c_get_clientdata(client); \
-\
- long val; \
-\
- if (strict_strtol(buf, 10, &val) < 0) \
- return -EINVAL;\
-\
- mutex_lock(&data->update_lock); \
-\
- if (val < 0) \
- data->config |= R##flag##DF_MASK; \
- else \
- data->config &= ~R##flag##DF_MASK; \
-\
- data->valid = 0; \
-\
- i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, \
- data->config); \
-\
- mutex_unlock(&data->update_lock); \
-\
- return count; \
+#define set_min(flag) \
+static ssize_t set_min##flag(struct device *dev, \
+ struct device_attribute *devattr, const char *buf, size_t count) \
+{ \
+ struct i2c_client *client = to_i2c_client(dev); \
+ struct lm95241_data *data = i2c_get_clientdata(client); \
+ long val; \
+ int rv; \
+ \
+ rv = kstrtol(buf, 10, &val); \
+ if (rv < 0) \
+ return rv; \
+ \
+ mutex_lock(&data->update_lock); \
+ if (val < 0) \
+ data->config |= R##flag##DF_MASK; \
+ else \
+ data->config &= ~R##flag##DF_MASK; \
+ data->valid = 0; \
+ i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, \
+ data->config); \
+ mutex_unlock(&data->update_lock); \
+ return count; \
}
set_min(1);
set_min(2);

-#define set_max(flag) \
-static ssize_t set_max##flag(struct device *dev, \
- struct device_attribute *devattr, const char *buf, size_t count) \
-{ \
- struct i2c_client *client = to_i2c_client(dev); \
- struct lm95241_data *data = i2c_get_clientdata(client); \
-\
- long val; \
-\
- if (strict_strtol(buf, 10, &val) < 0) \
- return -EINVAL; \
-\
- mutex_lock(&data->update_lock); \
-\
- if (val <= 127000) \
- data->config |= R##flag##DF_MASK; \
- else \
- data->config &= ~R##flag##DF_MASK; \
-\
- data->valid = 0; \
-\
- i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, \
- data->config); \
-\
- mutex_unlock(&data->update_lock); \
-\
- return count; \
+#define set_max(flag) \
+static ssize_t set_max##flag(struct device *dev, \
+ struct device_attribute *devattr, const char *buf, size_t count) \
+{ \
+ struct i2c_client *client = to_i2c_client(dev); \
+ struct lm95241_data *data = i2c_get_clientdata(client); \
+ long val; \
+ int rv; \
+ \
+ rv = kstrtol(buf, 10, &val); \
+ if (rv < 0) \
+ return rv; \
+ \
+ mutex_lock(&data->update_lock); \
+ if (val <= 127000) \
+ data->config |= R##flag##DF_MASK; \
+ else \
+ data->config &= ~R##flag##DF_MASK; \
+ data->valid = 0; \
+ i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, \
+ data->config); \
+ mutex_unlock(&data->update_lock); \
+ return count; \
}
set_max(1);
set_max(2);
diff --git a/drivers/hwmon/pc87427.c b/drivers/hwmon/pc87427.c
index 9ec4daa..dea7260 100644
--- a/drivers/hwmon/pc87427.c
+++ b/drivers/hwmon/pc87427.c
@@ -415,9 +415,11 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute
int nr = to_sensor_dev_attr(devattr)->index;
unsigned long val;
int iobase = data->address[LD_FAN];
+ int rv;

- if (strict_strtoul(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtoul(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->lock);
outb(BANK_FM(nr), iobase + PC87427_REG_BANK);
@@ -569,8 +571,12 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute
struct pc87427_data *data = dev_get_drvdata(dev);
int nr = to_sensor_dev_attr(devattr)->index;
unsigned long val;
+ int rv;

- if (strict_strtoul(buf, 10, &val) < 0 || val > 2)
+ rv = kstrtoul(buf, 10, &val);
+ if (rv < 0)
+ return rv;
+ if (val > 2)
return -EINVAL;
/* Can't go to automatic mode if it isn't configured */
if (val == 2 && !(data->pwm_auto_ok & (1 << nr)))
@@ -598,12 +604,14 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute
{
struct pc87427_data *data = dev_get_drvdata(dev);
int nr = to_sensor_dev_attr(devattr)->index;
- unsigned long val;
+ u8 val;
int iobase = data->address[LD_FAN];
u8 mode;
+ int rv;

- if (strict_strtoul(buf, 10, &val) < 0 || val > 0xff)
- return -EINVAL;
+ rv = kstrtou8(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->lock);
pc87427_readall_pwm(data, nr);
diff --git a/drivers/hwmon/tmp102.c b/drivers/hwmon/tmp102.c
index 93187c3..f839a78 100644
--- a/drivers/hwmon/tmp102.c
+++ b/drivers/hwmon/tmp102.c
@@ -124,8 +124,9 @@ static ssize_t tmp102_set_temp(struct device *dev,
long val;
int status;

- if (strict_strtol(buf, 10, &val) < 0)
- return -EINVAL;
+ status = kstrtol(buf, 10, &val);
+ if (status < 0)
+ return status;
val = SENSORS_LIMIT(val, -256000, 255000);

mutex_lock(&tmp102->lock);
diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c
index ad8d535..6e67bdb 100644
--- a/drivers/hwmon/tmp401.c
+++ b/drivers/hwmon/tmp401.c
@@ -333,9 +333,11 @@ static ssize_t store_temp_min(struct device *dev, struct device_attribute
struct tmp401_data *data = tmp401_update_device(dev);
long val;
u16 reg;
+ int rv;

- if (strict_strtol(buf, 10, &val))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &val);
+ if (rv < 0)
+ return rv;

reg = tmp401_temp_to_register(val, data->config);

@@ -360,9 +362,11 @@ static ssize_t store_temp_max(struct device *dev, struct device_attribute
struct tmp401_data *data = tmp401_update_device(dev);
long val;
u16 reg;
+ int rv;

- if (strict_strtol(buf, 10, &val))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &val);
+ if (rv < 0)
+ return rv;

reg = tmp401_temp_to_register(val, data->config);

@@ -387,9 +391,11 @@ static ssize_t store_temp_crit(struct device *dev, struct device_attribute
struct tmp401_data *data = tmp401_update_device(dev);
long val;
u8 reg;
+ int rv;

- if (strict_strtol(buf, 10, &val))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &val);
+ if (rv < 0)
+ return rv;

reg = tmp401_crit_temp_to_register(val, data->config);

@@ -412,9 +418,11 @@ static ssize_t store_temp_crit_hyst(struct device *dev, struct device_attribute
struct tmp401_data *data = tmp401_update_device(dev);
long val;
u8 reg;
+ int rv;

- if (strict_strtol(buf, 10, &val))
- return -EINVAL;
+ rv = kstrtol(buf, 10, &val);
+ if (rv < 0)
+ return rv;

if (data->config & TMP401_CONFIG_RANGE)
val = SENSORS_LIMIT(val, -64000, 191000);
@@ -445,18 +453,19 @@ static ssize_t store_temp_crit_hyst(struct device *dev, struct device_attribute
static ssize_t reset_temp_history(struct device *dev,
struct device_attribute *devattr, const char *buf, size_t count)
{
- long val;
-
- if (strict_strtol(buf, 10, &val))
- return -EINVAL;
+ int val;
+ int rv;

+ rv = kstrtoint(buf, 10, &val);
+ if (rv < 0)
+ return rv;
if (val != 1) {
- dev_err(dev, "temp_reset_history value %ld not"
+ dev_err(dev, "temp_reset_history value %d not"
" supported. Use 1 to reset the history!\n", val);
return -EINVAL;
}
i2c_smbus_write_byte_data(to_i2c_client(dev),
- TMP411_TEMP_LOWEST_MSB[0], val);
+ TMP411_TEMP_LOWEST_MSB[0], 1);

return count;
}
diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
index 400a88b..c588a76 100644
--- a/drivers/hwmon/w83791d.c
+++ b/drivers/hwmon/w83791d.c
@@ -710,9 +710,11 @@ static ssize_t store_pwm(struct device *dev, struct device_attribute *attr,
struct w83791d_data *data = i2c_get_clientdata(client);
int nr = sensor_attr->index;
unsigned long val;
+ int rv;

- if (strict_strtoul(buf, 10, &val))
- return -EINVAL;
+ rv = kstrtoul(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->update_lock);
data->pwm[nr] = SENSORS_LIMIT(val, 0, 255);
@@ -750,15 +752,17 @@ static ssize_t store_pwmenable(struct device *dev,
struct i2c_client *client = to_i2c_client(dev);
struct w83791d_data *data = i2c_get_clientdata(client);
int nr = sensor_attr->index;
- unsigned long val;
+ u8 val;
u8 reg_cfg_tmp;
u8 reg_idx = 0;
u8 val_shift = 0;
u8 keep_mask = 0;
+ int ret;

- int ret = strict_strtoul(buf, 10, &val);
-
- if (ret || val < 1 || val > 3)
+ ret = kstrtou8(buf, 10, &val);
+ if (ret < 0)
+ return ret;
+ if (val < 1 || val > 3)
return -EINVAL;

mutex_lock(&data->update_lock);
@@ -818,9 +822,11 @@ static ssize_t store_temp_target(struct device *dev,
int nr = sensor_attr->index;
unsigned long val;
u8 target_mask;
+ int rv;

- if (strict_strtoul(buf, 10, &val))
- return -EINVAL;
+ rv = kstrtoul(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->update_lock);
data->temp_target[nr] = TARGET_TEMP_TO_REG(val);
@@ -862,9 +868,11 @@ static ssize_t store_temp_tolerance(struct device *dev,
u8 reg_idx = 0;
u8 val_shift = 0;
u8 keep_mask = 0;
+ int rv;

- if (strict_strtoul(buf, 10, &val))
- return -EINVAL;
+ rv = kstrtoul(buf, 10, &val);
+ if (rv < 0)
+ return rv;

switch (nr) {
case 0:
diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c
index cdbc744..29f63fe 100644
--- a/drivers/hwmon/w83795.c
+++ b/drivers/hwmon/w83795.c
@@ -728,10 +728,12 @@ store_beep(struct device *dev, struct device_attribute *attr,
int index = sensor_attr->index >> 3;
int shift = sensor_attr->index & 0x07;
u8 beep_bit = 1 << shift;
- unsigned long val;
+ unsigned int val;
+ int rv;

- if (strict_strtoul(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtouint(buf, 10, &val);
+ if (rv < 0)
+ return rv;
if (val != 0 && val != 1)
return -EINVAL;

@@ -753,9 +755,13 @@ store_chassis_clear(struct device *dev,
{
struct i2c_client *client = to_i2c_client(dev);
struct w83795_data *data = i2c_get_clientdata(client);
- unsigned long val;
+ u8 val;
+ int rv;

- if (strict_strtoul(buf, 10, &val) < 0 || val != 0)
+ rv = kstrtou8(buf, 10, &val);
+ if (rv < 0)
+ return rv;
+ if (val != 0)
return -EINVAL;

mutex_lock(&data->update_lock);
@@ -800,9 +806,11 @@ store_fan_min(struct device *dev, struct device_attribute *attr,
struct i2c_client *client = to_i2c_client(dev);
struct w83795_data *data = i2c_get_clientdata(client);
unsigned long val;
+ int rv;

- if (strict_strtoul(buf, 10, &val))
- return -EINVAL;
+ rv = kstrtoul(buf, 10, &val);
+ if (rv < 0)
+ return rv;
val = fan_to_reg(val);

mutex_lock(&data->update_lock);
@@ -862,9 +870,11 @@ store_pwm(struct device *dev, struct device_attribute *attr,
int nr = sensor_attr->nr;
int index = sensor_attr->index;
unsigned long val;
+ int rv;

- if (strict_strtoul(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtoul(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->update_lock);
switch (nr) {
@@ -921,16 +931,18 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr,
struct sensor_device_attribute_2 *sensor_attr =
to_sensor_dev_attr_2(attr);
int index = sensor_attr->index;
- unsigned long val;
- int i;
+ int val;
+ int rv;

- if (strict_strtoul(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtoint(buf, 10, &val);
+ if (rv < 0)
+ return rv;
if (val < 1 || val > 2)
return -EINVAL;

mutex_lock(&data->update_lock);
switch (val) {
+ int i;
case 1:
/* Clear speed cruise mode bits */
data->pwm_fcms[0] &= ~(1 << index);
@@ -1018,11 +1030,14 @@ store_temp_src(struct device *dev, struct device_attribute *attr,
to_sensor_dev_attr_2(attr);
int index = sensor_attr->index;
int tmp;
- unsigned long channel;
+ u8 channel;
u8 val = index / 2;
+ int rv;

- if (strict_strtoul(buf, 10, &channel) < 0 ||
- channel < 1 || channel > 14)
+ rv = kstrtou8(buf, 10, &channel);
+ if (rv < 0)
+ return rv;
+ if (channel < 1 || channel > 14)
return -EINVAL;

/* Check if request can be fulfilled */
@@ -1087,9 +1102,11 @@ store_temp_pwm_enable(struct device *dev, struct device_attribute *attr,
int nr = sensor_attr->nr;
int index = sensor_attr->index;
unsigned long tmp;
+ int rv;

- if (strict_strtoul(buf, 10, &tmp) < 0)
- return -EINVAL;
+ rv = kstrtoul(buf, 10, &tmp);
+ if (rv < 0)
+ return rv;

switch (nr) {
case TEMP_PWM_ENABLE:
@@ -1148,9 +1165,11 @@ store_fanin(struct device *dev, struct device_attribute *attr,
int nr = sensor_attr->nr;
int index = sensor_attr->index;
unsigned long val;
+ int rv;

- if (strict_strtoul(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtoul(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->update_lock);
switch (nr) {
@@ -1197,9 +1216,11 @@ store_temp_pwm(struct device *dev, struct device_attribute *attr,
int index = sensor_attr->index;
unsigned long val;
u8 tmp;
+ int rv;

- if (strict_strtoul(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtoul(buf, 10, &val);
+ if (rv < 0)
+ return rv;
val /= 1000;

mutex_lock(&data->update_lock);
@@ -1256,9 +1277,11 @@ store_sf4_pwm(struct device *dev, struct device_attribute *attr,
int nr = sensor_attr->nr;
int index = sensor_attr->index;
unsigned long val;
+ int rv;

- if (strict_strtoul(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtoul(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->update_lock);
w83795_write(client, W83795_REG_SF4_PWM(index, nr), val);
@@ -1292,9 +1315,11 @@ store_sf4_temp(struct device *dev, struct device_attribute *attr,
int nr = sensor_attr->nr;
int index = sensor_attr->index;
unsigned long val;
+ int rv;

- if (strict_strtoul(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtoul(buf, 10, &val);
+ if (rv < 0)
+ return rv;
val /= 1000;

mutex_lock(&data->update_lock);
@@ -1332,9 +1357,11 @@ store_temp(struct device *dev, struct device_attribute *attr,
struct i2c_client *client = to_i2c_client(dev);
struct w83795_data *data = i2c_get_clientdata(client);
long tmp;
+ int rv;

- if (strict_strtol(buf, 10, &tmp) < 0)
- return -EINVAL;
+ rv = kstrtol(buf, 10, &tmp);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->update_lock);
data->temp[index][nr] = temp_to_reg(tmp, -128, 127);
@@ -1393,9 +1420,11 @@ store_dts_ext(struct device *dev, struct device_attribute *attr,
struct i2c_client *client = to_i2c_client(dev);
struct w83795_data *data = i2c_get_clientdata(client);
long tmp;
+ int rv;

- if (strict_strtol(buf, 10, &tmp) < 0)
- return -EINVAL;
+ rv = kstrtol(buf, 10, &tmp);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->update_lock);
data->dts_ext[nr] = temp_to_reg(tmp, -128, 127);
@@ -1433,11 +1462,13 @@ store_temp_mode(struct device *dev, struct device_attribute *attr,
to_sensor_dev_attr_2(attr);
int index = sensor_attr->index;
int reg_shift;
- unsigned long val;
+ u8 val;
u8 tmp;
+ int rv;

- if (strict_strtoul(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtou8(buf, 10, &val);
+ if (rv < 0)
+ return rv;
if ((val != 4) && (val != 3))
return -EINVAL;

@@ -1511,9 +1542,11 @@ store_in(struct device *dev, struct device_attribute *attr,
unsigned long val;
u8 tmp;
u8 lsb_idx;
+ int rv;

- if (strict_strtoul(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtoul(buf, 10, &val);
+ if (rv < 0)
+ return rv;
val = in_to_reg(index, val);

if ((index >= 17) &&
@@ -1568,9 +1601,11 @@ store_sf_setup(struct device *dev, struct device_attribute *attr,
struct i2c_client *client = to_i2c_client(dev);
struct w83795_data *data = i2c_get_clientdata(client);
unsigned long val;
+ int rv;

- if (strict_strtoul(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtoul(buf, 10, &val);
+ if (rv < 0)
+ return rv;

switch (nr) {
case SETUP_PWM_DEFAULT:
--
1.7.2.2

2010-12-05 17:51:24

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 26/45] kstrtox: convert drivers/isdn/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/isdn/gigaset/ev-layer.c | 12 ++++++------
drivers/isdn/hysdn/hysdn_proclog.c | 11 ++++-------
2 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/drivers/isdn/gigaset/ev-layer.c b/drivers/isdn/gigaset/ev-layer.c
index a141876..7a9a07c 100644
--- a/drivers/isdn/gigaset/ev-layer.c
+++ b/drivers/isdn/gigaset/ev-layer.c
@@ -390,12 +390,12 @@ static const struct zsau_resp_t {
*/
static int cid_of_response(char *s)
{
- unsigned long cid;
+ unsigned int cid;
int rc;

if (s[-1] != ';')
return 0; /* no CID separator */
- rc = strict_strtoul(s, 10, &cid);
+ rc = kstrtouint(s, 10, &cid);
if (rc)
return 0; /* CID not numeric */
if (cid < 1 || cid > 65535)
@@ -566,10 +566,10 @@ void gigaset_handle_modem_response(struct cardstate *cs)
case RT_ZCAU:
event->parameter = -1;
if (curarg + 1 < params) {
- unsigned long type, value;
+ u8 type, value;

- i = strict_strtoul(argv[curarg++], 16, &type);
- j = strict_strtoul(argv[curarg++], 16, &value);
+ i = kstrtou8(argv[curarg++], 16, &type);
+ j = kstrtou8(argv[curarg++], 16, &value);

if (i == 0 && type < 256 &&
j == 0 && value < 256)
@@ -583,7 +583,7 @@ void gigaset_handle_modem_response(struct cardstate *cs)
unsigned long res;
int rc;

- rc = strict_strtoul(argv[curarg++], 10, &res);
+ rc = kstrtoul(argv[curarg++], 10, &res);
if (rc == 0)
event->parameter = res;
}
diff --git a/drivers/isdn/hysdn/hysdn_proclog.c b/drivers/isdn/hysdn/hysdn_proclog.c
index 2ee93d0..236cc7d 100644
--- a/drivers/isdn/hysdn/hysdn_proclog.c
+++ b/drivers/isdn/hysdn/hysdn_proclog.c
@@ -155,7 +155,6 @@ put_log_buffer(hysdn_card * card, char *cp)
static ssize_t
hysdn_log_write(struct file *file, const char __user *buf, size_t count, loff_t * off)
{
- unsigned long u = 0;
int rc;
unsigned char valbuf[128];
hysdn_card *card = file->private_data;
@@ -167,12 +166,10 @@ hysdn_log_write(struct file *file, const char __user *buf, size_t count, loff_t

valbuf[count] = 0; /* terminating 0 */

- rc = strict_strtoul(valbuf, 0, &u);
-
- if (rc == 0) {
- card->debug_flags = u; /* remember debug flags */
- hysdn_addlog(card, "debug set to 0x%lx", card->debug_flags);
- }
+ rc = kstrtoul(valbuf, 0, &card->debug_flags);
+ if (rc < 0)
+ return rc;
+ hysdn_addlog(card, "debug set to 0x%lx", card->debug_flags);
return (count);
} /* hysdn_log_write */

--
1.7.2.2

2010-12-05 17:51:29

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 28/45] kstrtox: convert drivers/md/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/md/bitmap.c | 12 ++++----
drivers/md/md.c | 82 ++++++++++++++++++++++++++++++++++----------------
drivers/md/raid5.c | 16 ++++++----
3 files changed, 72 insertions(+), 38 deletions(-)

diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 5a1ffe3..99ad322 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -1881,10 +1881,8 @@ location_store(mddev_t *mddev, const char *buf, size_t len)
return -EINVAL;
} else {
int rv;
- if (buf[0] == '+')
- rv = strict_strtoll(buf+1, 10, &offset);
- else
- rv = strict_strtoll(buf, 10, &offset);
+
+ rv = kstrtoll(buf, 10, &offset);
if (rv)
return rv;
if (offset == 0)
@@ -1980,7 +1978,9 @@ static ssize_t
backlog_store(mddev_t *mddev, const char *buf, size_t len)
{
unsigned long backlog;
- int rv = strict_strtoul(buf, 10, &backlog);
+ int rv;
+
+ rv = kstrtoul(buf, 10, &backlog);
if (rv)
return rv;
if (backlog > COUNTER_MAX)
@@ -2006,7 +2006,7 @@ chunksize_store(mddev_t *mddev, const char *buf, size_t len)
unsigned long csize;
if (mddev->bitmap)
return -EBUSY;
- rv = strict_strtoul(buf, 10, &csize);
+ rv = kstrtoul(buf, 10, &csize);
if (rv)
return rv;
if (csize < 512 ||
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 84c46a1..86dd989 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -2549,13 +2549,15 @@ static int overlaps(sector_t s1, sector_t l1, sector_t s2, sector_t l2)
return 1;
}

-static int strict_blocks_to_sectors(const char *buf, sector_t *sectors)
+static int kstr_blocks_to_sector_t(const char *buf, sector_t *sectors)
{
unsigned long long blocks;
sector_t new;
+ int rv;

- if (strict_strtoull(buf, 10, &blocks) < 0)
- return -EINVAL;
+ rv = kstrtoull(buf, 10, &blocks);
+ if (rv < 0)
+ return rv;

if (blocks & 1ULL << (8 * sizeof(blocks) - 1))
return -EINVAL; /* sector conversion overflow */
@@ -2568,15 +2570,31 @@ static int strict_blocks_to_sectors(const char *buf, sector_t *sectors)
return 0;
}

+static int kstrto_sector_t(const char *buf, unsigned int base, sector_t *res)
+{
+ unsigned long long tmp;
+ int rv;
+
+ rv = kstrtoull(buf, base, &tmp);
+ if (rv < 0)
+ return rv;
+ if (tmp != (unsigned long long)(sector_t)tmp)
+ return -EINVAL;
+ *res = tmp;
+ return 0;
+}
+
static ssize_t
rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len)
{
mddev_t *my_mddev = rdev->mddev;
sector_t oldsectors = rdev->sectors;
sector_t sectors;
+ int rv;

- if (strict_blocks_to_sectors(buf, &sectors) < 0)
- return -EINVAL;
+ rv = kstr_blocks_to_sector_t(buf, &sectors);
+ if (rv < 0)
+ return rv;
if (my_mddev->pers && rdev->raid_disk >= 0) {
if (my_mddev->persistent) {
sectors = super_types[my_mddev->major_version].
@@ -2654,12 +2672,17 @@ static ssize_t recovery_start_show(mdk_rdev_t *rdev, char *page)

static ssize_t recovery_start_store(mdk_rdev_t *rdev, const char *buf, size_t len)
{
- unsigned long long recovery_start;
+ sector_t recovery_start;

if (cmd_match(buf, "none"))
recovery_start = MaxSector;
- else if (strict_strtoull(buf, 10, &recovery_start))
- return -EINVAL;
+ else {
+ int rv;
+
+ rv = kstrto_sector_t(buf, 10, &recovery_start);
+ if (rv < 0)
+ return rv;
+ }

if (rdev->mddev->pers &&
rdev->raid_disk >= 0)
@@ -2992,7 +3015,7 @@ level_store(mddev_t *mddev, const char *buf, size_t len)
char clevel[16];
ssize_t rv = len;
struct mdk_personality *pers;
- long level;
+ int level;
void *priv;
mdk_rdev_t *rdev;

@@ -3029,11 +3052,8 @@ level_store(mddev_t *mddev, const char *buf, size_t len)
/* Now find the new personality */
if (len == 0 || len >= sizeof(clevel))
return -EINVAL;
- strncpy(clevel, buf, len);
- if (clevel[len-1] == '\n')
- len--;
- clevel[len] = 0;
- if (strict_strtol(clevel, 10, &level))
+ strlcpy(clevel, buf, sizeof(clevel));
+ if (kstrtoint(clevel, 10, &level))
level = LEVEL_NONE;

if (request_module("md-%s", clevel) != 0)
@@ -3629,8 +3649,9 @@ size_store(mddev_t *mddev, const char *buf, size_t len)
* If array is active, we can try an on-line resize
*/
sector_t sectors;
- int err = strict_blocks_to_sectors(buf, &sectors);
+ int err;

+ err = kstr_blocks_to_sector_t(buf, &sectors);
if (err < 0)
return err;
if (mddev->pers) {
@@ -3874,11 +3895,12 @@ sync_force_parallel_show(mddev_t *mddev, char *page)
static ssize_t
sync_force_parallel_store(mddev_t *mddev, const char *buf, size_t len)
{
- long n;
-
- if (strict_strtol(buf, 10, &n))
- return -EINVAL;
+ int n;
+ int rv;

+ rv = kstrtoint(buf, 10, &n);
+ if (rv < 0)
+ return rv;
if (n != 0 && n != 1)
return -EINVAL;

@@ -3938,8 +3960,10 @@ min_sync_show(mddev_t *mddev, char *page)
static ssize_t
min_sync_store(mddev_t *mddev, const char *buf, size_t len)
{
- unsigned long long min;
- if (strict_strtoull(buf, 10, &min))
+ sector_t min;
+ int rv;
+
+ rv = kstrto_sector_t(buf, 10, &min);
return -EINVAL;
if (min > mddev->resync_max)
return -EINVAL;
@@ -3975,9 +3999,12 @@ max_sync_store(mddev_t *mddev, const char *buf, size_t len)
if (strncmp(buf, "max", 3) == 0)
mddev->resync_max = MaxSector;
else {
- unsigned long long max;
- if (strict_strtoull(buf, 10, &max))
- return -EINVAL;
+ sector_t max;
+ int rv;
+
+ rv = kstrto_sector_t(buf, 10, &max);
+ if (rv < 0)
+ return rv;
if (max < mddev->resync_min)
return -EINVAL;
if (max < mddev->resync_max &&
@@ -4112,8 +4139,11 @@ array_size_store(mddev_t *mddev, const char *buf, size_t len)

mddev->external_size = 0;
} else {
- if (strict_blocks_to_sectors(buf, &sectors) < 0)
- return -EINVAL;
+ int rv;
+
+ rv = kstr_blocks_to_sector_t(buf, &sectors);
+ if (rv < 0)
+ return rv;
if (mddev->pers && mddev->pers->size(mddev, 0, 0) < sectors)
return -E2BIG;

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index dc574f3..61d63fb 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -4615,7 +4615,7 @@ static ssize_t
raid5_store_stripe_cache_size(mddev_t *mddev, const char *page, size_t len)
{
raid5_conf_t *conf = mddev->private;
- unsigned long new;
+ unsigned int new;
int err;

if (len >= PAGE_SIZE)
@@ -4623,8 +4623,9 @@ raid5_store_stripe_cache_size(mddev_t *mddev, const char *page, size_t len)
if (!conf)
return -ENODEV;

- if (strict_strtoul(page, 10, &new))
- return -EINVAL;
+ err = kstrtouint(page, 10, &new);
+ if (err < 0)
+ return err;
err = raid5_set_cache_size(mddev, new);
if (err)
return err;
@@ -4650,14 +4651,17 @@ static ssize_t
raid5_store_preread_threshold(mddev_t *mddev, const char *page, size_t len)
{
raid5_conf_t *conf = mddev->private;
- unsigned long new;
+ unsigned int new;
+ int rv;
+
if (len >= PAGE_SIZE)
return -EINVAL;
if (!conf)
return -ENODEV;

- if (strict_strtoul(page, 10, &new))
- return -EINVAL;
+ rv = kstrtouint(page, 10, &new);
+ if (rv < 0)
+ return rv;
if (new > conf->max_nr_stripes)
return -EINVAL;
conf->bypass_threshold = new;
--
1.7.2.2

2010-12-05 17:51:33

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 29/45] kstrtox: convert drivers/mfd/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/mfd/ab3100-core.c | 16 +++----------
drivers/mfd/ab3550-core.c | 48 +++++++++++++++--------------------------
drivers/mfd/ab8500-debugfs.c | 41 +++++++++++++----------------------
3 files changed, 37 insertions(+), 68 deletions(-)

diff --git a/drivers/mfd/ab3100-core.c b/drivers/mfd/ab3100-core.c
index 4193af5..5b1c8ac 100644
--- a/drivers/mfd/ab3100-core.c
+++ b/drivers/mfd/ab3100-core.c
@@ -497,7 +497,7 @@ static ssize_t ab3100_get_set_reg(struct file *file,
char buf[32];
ssize_t buf_size;
int regp;
- unsigned long user_reg;
+ u8 reg;
int err;
int i = 0;

@@ -520,22 +520,19 @@ static ssize_t ab3100_get_set_reg(struct file *file,
/*
* Advance pointer to end of string then terminate
* the register string. This is needed to satisfy
- * the strict_strtoul() function.
+ * the kstrtou8() function.
*/
while ((i < buf_size) && (buf[i] != ' '))
i++;
buf[i] = '\0';

- err = strict_strtoul(&buf[regp], 16, &user_reg);
+ err = kstrtou8(&buf[regp], 16, &reg);
if (err)
return err;
- if (user_reg > 0xff)
- return -EINVAL;

/* Either we read or we write a register here */
if (!priv->mode) {
/* Reading */
- u8 reg = (u8) user_reg;
u8 regvalue;

ab3100_get_register_interruptible(ab3100, reg, &regvalue);
@@ -545,8 +542,6 @@ static ssize_t ab3100_get_set_reg(struct file *file,
reg, regvalue);
} else {
int valp;
- unsigned long user_value;
- u8 reg = (u8) user_reg;
u8 value;
u8 regvalue;

@@ -563,13 +558,10 @@ static ssize_t ab3100_get_set_reg(struct file *file,
i++;
buf[i] = '\0';

- err = strict_strtoul(&buf[valp], 16, &user_value);
+ err = kstrtou8(&buf[valp], 16, &value);
if (err)
return err;
- if (user_reg > 0xff)
- return -EINVAL;

- value = (u8) user_value;
ab3100_set_register_interruptible(ab3100, reg, value);
ab3100_get_register_interruptible(ab3100, reg, &regvalue);

diff --git a/drivers/mfd/ab3550-core.c b/drivers/mfd/ab3550-core.c
index 8a98739..7e471d9 100644
--- a/drivers/mfd/ab3550-core.c
+++ b/drivers/mfd/ab3550-core.c
@@ -73,8 +73,8 @@ struct ab3550 {
u8 startup_events[AB3550_NUM_EVENT_REG];
bool startup_events_read;
#ifdef CONFIG_DEBUG_FS
- unsigned int debug_bank;
- unsigned int debug_address;
+ u8 debug_bank;
+ u8 debug_address;
#endif
};

@@ -865,7 +865,7 @@ static int ab3550_bank_print(struct seq_file *s, void *p)
{
struct ab3550 *ab = s->private;

- seq_printf(s, "%d\n", ab->debug_bank);
+ seq_printf(s, "%hhu\n", ab->debug_bank);
return 0;
}

@@ -881,7 +881,7 @@ static ssize_t ab3550_bank_write(struct file *file,
struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private;
char buf[32];
int buf_size;
- unsigned long user_bank;
+ u8 user_bank;
int err;

/* Get userspace string and assure termination */
@@ -890,7 +890,7 @@ static ssize_t ab3550_bank_write(struct file *file,
return -EFAULT;
buf[buf_size] = 0;

- err = strict_strtoul(buf, 0, &user_bank);
+ err = kstrtou8(buf, 0, &user_bank);
if (err)
return -EINVAL;

@@ -925,7 +925,6 @@ static ssize_t ab3550_address_write(struct file *file,
struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private;
char buf[32];
int buf_size;
- unsigned long user_address;
int err;

/* Get userspace string and assure termination */
@@ -934,15 +933,9 @@ static ssize_t ab3550_address_write(struct file *file,
return -EFAULT;
buf[buf_size] = 0;

- err = strict_strtoul(buf, 0, &user_address);
- if (err)
- return -EINVAL;
- if (user_address > 0xff) {
- dev_err(&ab->i2c_client[0]->dev,
- "debugfs error input > 0xff\n");
- return -EINVAL;
- }
- ab->debug_address = user_address;
+ err = kstrtou8(buf, 0, &ab->debug_address);
+ if (err < 0)
+ return err;
return buf_size;
}

@@ -952,8 +945,8 @@ static int ab3550_val_print(struct seq_file *s, void *p)
int err;
u8 regvalue;

- err = get_register_interruptible(ab, (u8)ab->debug_bank,
- (u8)ab->debug_address, &regvalue);
+ err = get_register_interruptible(ab, ab->debug_bank,
+ ab->debug_address, &regvalue);
if (err)
return -EINVAL;
seq_printf(s, "0x%02X\n", regvalue);
@@ -973,7 +966,7 @@ static ssize_t ab3550_val_write(struct file *file,
struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private;
char buf[32];
int buf_size;
- unsigned long user_val;
+ u8 user_val;
int err;
u8 regvalue;

@@ -983,22 +976,17 @@ static ssize_t ab3550_val_write(struct file *file,
return -EFAULT;
buf[buf_size] = 0;

- err = strict_strtoul(buf, 0, &user_val);
- if (err)
- return -EINVAL;
- if (user_val > 0xff) {
- dev_err(&ab->i2c_client[0]->dev,
- "debugfs error input > 0xff\n");
- return -EINVAL;
- }
+ err = kstrtou8(buf, 0, &user_val);
+ if (err < 0)
+ return err;
err = mask_and_set_register_interruptible(
- ab, (u8)ab->debug_bank,
- (u8)ab->debug_address, 0xFF, (u8)user_val);
+ ab, ab->debug_bank,
+ ab->debug_address, 0xFF, user_val);
if (err)
return -EINVAL;

- get_register_interruptible(ab, (u8)ab->debug_bank,
- (u8)ab->debug_address, &regvalue);
+ get_register_interruptible(ab, ab->debug_bank,
+ ab->debug_address, &regvalue);
if (err)
return -EINVAL;

diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
index 8d1e05a..2a4c317 100644
--- a/drivers/mfd/ab8500-debugfs.c
+++ b/drivers/mfd/ab8500-debugfs.c
@@ -14,8 +14,8 @@
#include <linux/mfd/abx500.h>
#include <linux/mfd/ab8500.h>

-static u32 debug_bank;
-static u32 debug_address;
+static u8 debug_bank;
+static u8 debug_address;

/**
* struct ab8500_reg_range
@@ -357,7 +357,7 @@ static int ab8500_registers_print(struct seq_file *s, void *p)
{
struct device *dev = s->private;
unsigned int i;
- u32 bank = debug_bank;
+ u8 bank = debug_bank;

seq_printf(s, AB8500_NAME_STRING " register values:\n");

@@ -372,7 +372,7 @@ static int ab8500_registers_print(struct seq_file *s, void *p)
int err;

err = abx500_get_register_interruptible(dev,
- (u8)bank, (u8)reg, &value);
+ bank, (u8)reg, &value);
if (err < 0) {
dev_err(dev, "ab->read fail %d\n", err);
return err;
@@ -406,7 +406,7 @@ static const struct file_operations ab8500_registers_fops = {

static int ab8500_bank_print(struct seq_file *s, void *p)
{
- return seq_printf(s, "%d\n", debug_bank);
+ return seq_printf(s, "%u\n", debug_bank);
}

static int ab8500_bank_open(struct inode *inode, struct file *file)
@@ -421,7 +421,7 @@ static ssize_t ab8500_bank_write(struct file *file,
struct device *dev = ((struct seq_file *)(file->private_data))->private;
char buf[32];
int buf_size;
- unsigned long user_bank;
+ u8 user_bank;
int err;

/* Get userspace string and assure termination */
@@ -430,9 +430,9 @@ static ssize_t ab8500_bank_write(struct file *file,
return -EFAULT;
buf[buf_size] = 0;

- err = strict_strtoul(buf, 0, &user_bank);
+ err = kstrtou8(buf, 0, &user_bank);
if (err)
- return -EINVAL;
+ return err;

if (user_bank >= AB8500_NUM_BANKS) {
dev_err(dev, "debugfs error input > number of banks\n");
@@ -458,10 +458,8 @@ static ssize_t ab8500_address_write(struct file *file,
const char __user *user_buf,
size_t count, loff_t *ppos)
{
- struct device *dev = ((struct seq_file *)(file->private_data))->private;
char buf[32];
int buf_size;
- unsigned long user_address;
int err;

/* Get userspace string and assure termination */
@@ -470,14 +468,9 @@ static ssize_t ab8500_address_write(struct file *file,
return -EFAULT;
buf[buf_size] = 0;

- err = strict_strtoul(buf, 0, &user_address);
+ err = kstrtou8(buf, 0, &debug_address);
if (err)
- return -EINVAL;
- if (user_address > 0xff) {
- dev_err(dev, "debugfs error input > 0xff\n");
- return -EINVAL;
- }
- debug_address = user_address;
+ return err;
return buf_size;
}

@@ -488,7 +481,7 @@ static int ab8500_val_print(struct seq_file *s, void *p)
u8 regvalue;

ret = abx500_get_register_interruptible(dev,
- (u8)debug_bank, (u8)debug_address, &regvalue);
+ debug_bank, debug_address, &regvalue);
if (ret < 0) {
dev_err(dev, "abx500_get_reg fail %d, %d\n",
ret, __LINE__);
@@ -511,7 +504,7 @@ static ssize_t ab8500_val_write(struct file *file,
struct device *dev = ((struct seq_file *)(file->private_data))->private;
char buf[32];
int buf_size;
- unsigned long user_val;
+ u8 user_val;
int err;

/* Get userspace string and assure termination */
@@ -520,15 +513,11 @@ static ssize_t ab8500_val_write(struct file *file,
return -EFAULT;
buf[buf_size] = 0;

- err = strict_strtoul(buf, 0, &user_val);
+ err = kstrtou8(buf, 0, &user_val);
if (err)
- return -EINVAL;
- if (user_val > 0xff) {
- dev_err(dev, "debugfs error input > 0xff\n");
- return -EINVAL;
- }
+ return err;
err = abx500_set_register_interruptible(dev,
- (u8)debug_bank, debug_address, (u8)user_val);
+ debug_bank, debug_address, user_val);
if (err < 0) {
printk(KERN_ERR "abx500_set_reg failed %d, %d", err, __LINE__);
return -EINVAL;
--
1.7.2.2

2010-12-05 17:51:38

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 31/45] kstrtox: convert drivers/mmc/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/mmc/card/mmc_test.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/card/mmc_test.c b/drivers/mmc/card/mmc_test.c
index 21adc27..108b72c 100644
--- a/drivers/mmc/card/mmc_test.c
+++ b/drivers/mmc/card/mmc_test.c
@@ -2173,7 +2173,7 @@ static ssize_t mtf_test_write(struct file *file, const char __user *buf,
struct mmc_card *card = (struct mmc_card *)sf->private;
struct mmc_test_card *test;
char lbuf[12];
- long testcase;
+ int testcase;

if (count >= sizeof(lbuf))
return -EINVAL;
@@ -2182,7 +2182,7 @@ static ssize_t mtf_test_write(struct file *file, const char __user *buf,
return -EFAULT;
lbuf[count] = '\0';

- if (strict_strtol(lbuf, 10, &testcase))
+ if (kstrtoint(lbuf, 10, &testcase))
return -EINVAL;

test = kzalloc(sizeof(struct mmc_test_card), GFP_KERNEL);
--
1.7.2.2

2010-12-05 17:51:42

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 33/45] kstrtox: convert drivers/net/wireless/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/net/wireless/ath/ath9k/debug.c | 22 ++++++----------
drivers/net/wireless/iwlwifi/iwl-agn.c | 36 +++++++++++--------------
drivers/net/wireless/iwlwifi/iwl3945-base.c | 15 ++++------
drivers/net/wireless/libertas/mesh.c | 7 +++--
drivers/net/wireless/wl12xx/wl1271_debugfs.c | 15 +++-------
drivers/net/wireless/wl12xx/wl1271_main.c | 6 +---
6 files changed, 41 insertions(+), 60 deletions(-)

diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
index 43e71a9..3a5aefb 100644
--- a/drivers/net/wireless/ath/ath9k/debug.c
+++ b/drivers/net/wireless/ath/ath9k/debug.c
@@ -51,7 +51,6 @@ static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
{
struct ath_softc *sc = file->private_data;
struct ath_common *common = ath9k_hw_common(sc->sc_ah);
- unsigned long mask;
char buf[32];
ssize_t len;

@@ -60,10 +59,8 @@ static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
return -EFAULT;

buf[len] = '\0';
- if (strict_strtoul(buf, 0, &mask))
+ if (kstrtoint(buf, 0, &common->debug_mask))
return -EINVAL;
-
- common->debug_mask = mask;
return count;
}

@@ -96,7 +93,7 @@ static ssize_t write_file_tx_chainmask(struct file *file, const char __user *use
{
struct ath_softc *sc = file->private_data;
struct ath_common *common = ath9k_hw_common(sc->sc_ah);
- unsigned long mask;
+ u8 mask;
char buf[32];
ssize_t len;

@@ -105,7 +102,7 @@ static ssize_t write_file_tx_chainmask(struct file *file, const char __user *use
return -EFAULT;

buf[len] = '\0';
- if (strict_strtoul(buf, 0, &mask))
+ if (kstrtou8(buf, 0, &mask))
return -EINVAL;

common->tx_chainmask = mask;
@@ -139,7 +136,7 @@ static ssize_t write_file_rx_chainmask(struct file *file, const char __user *use
{
struct ath_softc *sc = file->private_data;
struct ath_common *common = ath9k_hw_common(sc->sc_ah);
- unsigned long mask;
+ u8 mask;
char buf[32];
ssize_t len;

@@ -148,7 +145,7 @@ static ssize_t write_file_rx_chainmask(struct file *file, const char __user *use
return -EFAULT;

buf[len] = '\0';
- if (strict_strtoul(buf, 0, &mask))
+ if (kstrtou8(buf, 0, &mask))
return -EINVAL;

common->rx_chainmask = mask;
@@ -804,7 +801,6 @@ static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
size_t count, loff_t *ppos)
{
struct ath_softc *sc = file->private_data;
- unsigned long regidx;
char buf[32];
ssize_t len;

@@ -813,10 +809,8 @@ static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
return -EFAULT;

buf[len] = '\0';
- if (strict_strtoul(buf, 0, &regidx))
+ if (kstrtou32(buf, 0, &sc->debug.regidx))
return -EINVAL;
-
- sc->debug.regidx = regidx;
return count;
}

@@ -847,7 +841,7 @@ static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
{
struct ath_softc *sc = file->private_data;
struct ath_hw *ah = sc->sc_ah;
- unsigned long regval;
+ u32 regval;
char buf[32];
ssize_t len;

@@ -856,7 +850,7 @@ static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
return -EFAULT;

buf[len] = '\0';
- if (strict_strtoul(buf, 0, &regval))
+ if (kstrtou32(buf, 0, &regval))
return -EINVAL;

REG_WRITE_D(ah, sc->debug.regidx, regval);
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index c2636a7..47334bf 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -1625,19 +1625,16 @@ static ssize_t store_debug_level(struct device *d,
const char *buf, size_t count)
{
struct iwl_priv *priv = dev_get_drvdata(d);
- unsigned long val;
int ret;

- ret = strict_strtoul(buf, 0, &val);
- if (ret)
+ ret = kstrtou32(buf, 0, &priv->debug_level);
+ if (ret) {
IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
- else {
- priv->debug_level = val;
- if (iwl_alloc_traffic_mem(priv))
- IWL_ERR(priv,
- "Not enough memory to generate traffic log\n");
+ return ret;
}
- return strnlen(buf, count);
+ if (iwl_alloc_traffic_mem(priv))
+ IWL_ERR(priv, "Not enough memory to generate traffic log\n");
+ return count;
}

static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
@@ -1676,21 +1673,20 @@ static ssize_t store_tx_power(struct device *d,
const char *buf, size_t count)
{
struct iwl_priv *priv = dev_get_drvdata(d);
- unsigned long val;
+ u8 val;
int ret;

- ret = strict_strtoul(buf, 10, &val);
- if (ret)
+ ret = kstrtou8(buf, 10, &val);
+ if (ret) {
IWL_INFO(priv, "%s is not in decimal form.\n", buf);
- else {
- ret = iwl_set_tx_power(priv, val, false);
- if (ret)
- IWL_ERR(priv, "failed setting tx power (0x%d).\n",
- ret);
- else
- ret = count;
+ return ret;
}
- return ret;
+ ret = iwl_set_tx_power(priv, val, false);
+ if (ret) {
+ IWL_ERR(priv, "failed setting tx power (0x%d).\n", ret);
+ return ret;
+ }
+ return count;
}

static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index 7edf8c2..5dae5bf 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -3455,19 +3455,16 @@ static ssize_t store_debug_level(struct device *d,
const char *buf, size_t count)
{
struct iwl_priv *priv = dev_get_drvdata(d);
- unsigned long val;
int ret;

- ret = strict_strtoul(buf, 0, &val);
- if (ret)
+ ret = kstrtou32(buf, 0, &priv->debug_level);
+ if (ret) {
IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
- else {
- priv->debug_level = val;
- if (iwl_alloc_traffic_mem(priv))
- IWL_ERR(priv,
- "Not enough memory to generate traffic log\n");
+ return ret;
}
- return strnlen(buf, count);
+ if (iwl_alloc_traffic_mem(priv))
+ IWL_ERR(priv, "Not enough memory to generate traffic log\n");
+ return count;
}

static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
diff --git a/drivers/net/wireless/libertas/mesh.c b/drivers/net/wireless/libertas/mesh.c
index acf3bf6..0b61551 100644
--- a/drivers/net/wireless/libertas/mesh.c
+++ b/drivers/net/wireless/libertas/mesh.c
@@ -92,14 +92,15 @@ static ssize_t lbs_prb_rsp_limit_set(struct device *dev,
{
struct lbs_private *priv = to_net_dev(dev)->ml_priv;
struct cmd_ds_mesh_access mesh_access;
+ u32 retry_limit;
int ret;
- unsigned long retry_limit;

memset(&mesh_access, 0, sizeof(mesh_access));
mesh_access.data[0] = cpu_to_le32(CMD_ACT_SET);

- if (!strict_strtoul(buf, 10, &retry_limit))
- return -ENOTSUPP;
+ ret = kstrtou32(buf, 10, &retry_limit);
+ if (ret < 0)
+ return ret;
if (retry_limit > 15)
return -ENOTSUPP;

diff --git a/drivers/net/wireless/wl12xx/wl1271_debugfs.c b/drivers/net/wireless/wl12xx/wl1271_debugfs.c
index 66c2b90..9ba9418 100644
--- a/drivers/net/wireless/wl12xx/wl1271_debugfs.c
+++ b/drivers/net/wireless/wl12xx/wl1271_debugfs.c
@@ -266,27 +266,22 @@ static ssize_t gpio_power_write(struct file *file,
unsigned long value;
int ret;

- mutex_lock(&wl->mutex);
-
len = min(count, sizeof(buf) - 1);
- if (copy_from_user(buf, user_buf, len)) {
- ret = -EFAULT;
- goto out;
- }
+ if (copy_from_user(buf, user_buf, len))
+ return -EFAULT;
buf[len] = '\0';

- ret = strict_strtoul(buf, 0, &value);
+ ret = kstrtoul(buf, 0, &value);
if (ret < 0) {
wl1271_warning("illegal value in gpio_power");
- goto out;
+ return ret;
}

+ mutex_lock(&wl->mutex);
if (value)
wl1271_power_on(wl);
else
wl1271_power_off(wl);
-
-out:
mutex_unlock(&wl->mutex);
return count;
}
diff --git a/drivers/net/wireless/wl12xx/wl1271_main.c b/drivers/net/wireless/wl12xx/wl1271_main.c
index 48a4b99..1a628e0 100644
--- a/drivers/net/wireless/wl12xx/wl1271_main.c
+++ b/drivers/net/wireless/wl12xx/wl1271_main.c
@@ -2327,17 +2327,15 @@ static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev,
unsigned long res;
int ret;

- ret = strict_strtoul(buf, 10, &res);
-
+ ret = kstrtoul(buf, 10, &res);
if (ret < 0) {
wl1271_warning("incorrect value written to bt_coex_mode");
return count;
}
+ res = !!res;

mutex_lock(&wl->mutex);

- res = !!res;
-
if (res == wl->sg_enabled)
goto out;

--
1.7.2.2

2010-12-05 17:51:47

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 34/45] kstrtox: convert drivers/pci/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/pci/hotplug/fakephp.c | 2 +-
drivers/pci/pci-sysfs.c | 45 ++++++++++++++++++++++------------------
2 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/drivers/pci/hotplug/fakephp.c b/drivers/pci/hotplug/fakephp.c
index 17d10e2..aaf2529 100644
--- a/drivers/pci/hotplug/fakephp.c
+++ b/drivers/pci/hotplug/fakephp.c
@@ -49,7 +49,7 @@ static ssize_t legacy_store(struct kobject *kobj, struct attribute *attr,
struct legacy_slot *slot = container_of(kobj, typeof(*slot), kobj);
unsigned long val;

- if (strict_strtoul(buf, 0, &val) < 0)
+ if (kstrtoul(buf, 0, &val) < 0)
return -EINVAL;

if (val)
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 63d5042..1105790 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -61,9 +61,11 @@ static ssize_t broken_parity_status_store(struct device *dev,
{
struct pci_dev *pdev = to_pci_dev(dev);
unsigned long val;
+ int rv;

- if (strict_strtoul(buf, 0, &val) < 0)
- return -EINVAL;
+ rv = kstrtoul(buf, 0, &val);
+ if (rv < 0)
+ return rv;

pdev->broken_parity_status = !!val;

@@ -150,15 +152,16 @@ static ssize_t is_enabled_store(struct device *dev,
{
struct pci_dev *pdev = to_pci_dev(dev);
unsigned long val;
- ssize_t result = strict_strtoul(buf, 0, &val);
-
- if (result < 0)
- return result;
+ int result;

/* this can crash the machine when done on the "wrong" device */
if (!capable(CAP_SYS_ADMIN))
return -EPERM;

+ result = kstrtoul(buf, 0, &val);
+ if (result < 0)
+ return result;
+
if (!val) {
if (pci_is_enabled(pdev))
pci_disable_device(pdev);
@@ -221,14 +224,14 @@ msi_bus_store(struct device *dev, struct device_attribute *attr,
struct pci_dev *pdev = to_pci_dev(dev);
unsigned long val;

- if (strict_strtoul(buf, 0, &val) < 0)
- return -EINVAL;
-
/* bad things may happen if the no_msi flag is changed
* while some drivers are loaded */
if (!capable(CAP_SYS_ADMIN))
return -EPERM;

+ if (kstrtoul(buf, 0, &val) < 0)
+ return -EINVAL;
+
/* Maybe pci devices without subordinate busses shouldn't even have this
* attribute in the first place? */
if (!pdev->subordinate)
@@ -254,7 +257,7 @@ static ssize_t bus_rescan_store(struct bus_type *bus, const char *buf,
unsigned long val;
struct pci_bus *b = NULL;

- if (strict_strtoul(buf, 0, &val) < 0)
+ if (kstrtoul(buf, 0, &val) < 0)
return -EINVAL;

if (val) {
@@ -278,7 +281,7 @@ dev_rescan_store(struct device *dev, struct device_attribute *attr,
unsigned long val;
struct pci_dev *pdev = to_pci_dev(dev);

- if (strict_strtoul(buf, 0, &val) < 0)
+ if (kstrtoul(buf, 0, &val) < 0)
return -EINVAL;

if (val) {
@@ -302,19 +305,21 @@ static ssize_t
remove_store(struct device *dev, struct device_attribute *dummy,
const char *buf, size_t count)
{
- int ret = 0;
unsigned long val;
+ int ret;

- if (strict_strtoul(buf, 0, &val) < 0)
- return -EINVAL;
+ ret = kstrtoul(buf, 0, &val);
+ if (ret < 0)
+ return ret;

/* An attribute cannot be unregistered by one of its own methods,
* so we have to use this roundabout approach.
*/
- if (val)
+ if (val) {
ret = device_schedule_callback(dev, remove_callback);
- if (ret)
- count = ret;
+ if (ret < 0)
+ return ret;
+ }
return count;
}
#endif
@@ -1050,12 +1055,12 @@ static ssize_t reset_store(struct device *dev,
size_t count)
{
struct pci_dev *pdev = to_pci_dev(dev);
- unsigned long val;
- ssize_t result = strict_strtoul(buf, 0, &val);
+ int val;
+ int result;

+ result = kstrtoint(buf, 0, &val);
if (result < 0)
return result;
-
if (val != 1)
return -EINVAL;

--
1.7.2.2

2010-12-05 17:51:51

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 35/45] kstrtox: convert drivers/platform/x86/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/platform/x86/classmate-laptop.c | 2 +-
drivers/platform/x86/compal-laptop.c | 14 ++++++--------
2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/platform/x86/classmate-laptop.c b/drivers/platform/x86/classmate-laptop.c
index 341cbfe..07d7ce6 100644
--- a/drivers/platform/x86/classmate-laptop.c
+++ b/drivers/platform/x86/classmate-laptop.c
@@ -198,7 +198,7 @@ static ssize_t cmpc_accel_sensitivity_store(struct device *dev,
inputdev = dev_get_drvdata(&acpi->dev);
accel = dev_get_drvdata(&inputdev->dev);

- r = strict_strtoul(buf, 0, &sensitivity);
+ r = kstrtoul(buf, 0, &sensitivity);
if (r)
return r;

diff --git a/drivers/platform/x86/compal-laptop.c b/drivers/platform/x86/compal-laptop.c
index 097083c..c4602a4 100644
--- a/drivers/platform/x86/compal-laptop.c
+++ b/drivers/platform/x86/compal-laptop.c
@@ -421,13 +421,12 @@ static ssize_t pwm_enable_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
struct compal_data *data = dev_get_drvdata(dev);
- long val;
+ unsigned int val;
int err;
- err = strict_strtol(buf, 10, &val);
+
+ err = kstrtouint(buf, 10, &val);
if (err)
return err;
- if (val < 0)
- return -EINVAL;

data->pwm_enable = val;

@@ -459,13 +458,12 @@ static ssize_t pwm_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct compal_data *data = dev_get_drvdata(dev);
- long val;
+ u8 val;
int err;
- err = strict_strtol(buf, 10, &val);
+
+ err = kstrtou8(buf, 10, &val);
if (err)
return err;
- if (val < 0 || val > 255)
- return -EINVAL;

data->curr_pwm = val;

--
1.7.2.2

2010-12-05 17:51:57

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 37/45] kstrtox: convert drivers/regulator/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/regulator/virtual.c | 32 ++++++++++++++++++++------------
1 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/drivers/regulator/virtual.c b/drivers/regulator/virtual.c
index 69e550f..6e3eee2 100644
--- a/drivers/regulator/virtual.c
+++ b/drivers/regulator/virtual.c
@@ -118,10 +118,12 @@ static ssize_t set_min_uV(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct virtual_consumer_data *data = dev_get_drvdata(dev);
- long val;
+ int val;
+ int rv;

- if (strict_strtol(buf, 10, &val) != 0)
- return count;
+ rv = kstrtoint(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->lock);

@@ -144,10 +146,12 @@ static ssize_t set_max_uV(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct virtual_consumer_data *data = dev_get_drvdata(dev);
- long val;
+ int val;
+ int rv;

- if (strict_strtol(buf, 10, &val) != 0)
- return count;
+ rv = kstrtoint(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->lock);

@@ -170,10 +174,12 @@ static ssize_t set_min_uA(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct virtual_consumer_data *data = dev_get_drvdata(dev);
- long val;
+ int val;
+ int rv;

- if (strict_strtol(buf, 10, &val) != 0)
- return count;
+ rv = kstrtoint(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->lock);

@@ -196,10 +202,12 @@ static ssize_t set_max_uA(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct virtual_consumer_data *data = dev_get_drvdata(dev);
- long val;
+ int val;
+ int rv;

- if (strict_strtol(buf, 10, &val) != 0)
- return count;
+ rv = kstrtoint(buf, 10, &val);
+ if (rv < 0)
+ return rv;

mutex_lock(&data->lock);

--
1.7.2.2

2010-12-05 17:52:05

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 39/45] kstrtox: convert drivers/scsi/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/scsi/pmcraid.c | 2 +-
drivers/scsi/scsi_sysfs.c | 9 +++++----
2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index 5e76a62..3957c63 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -4217,7 +4217,7 @@ static ssize_t pmcraid_store_log_level(
struct pmcraid_instance *pinstance;
unsigned long val;

- if (strict_strtoul(buf, 10, &val))
+ if (kstrtoul(buf, 10, &val))
return -EINVAL;
/* log-level should be from 0 to 2 */
if (val > 2)
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 76ee2e7..04d99c3 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -757,11 +757,12 @@ sdev_store_queue_ramp_up_period(struct device *dev,
const char *buf, size_t count)
{
struct scsi_device *sdev = to_scsi_device(dev);
- unsigned long period;
-
- if (strict_strtoul(buf, 10, &period))
- return -EINVAL;
+ unsigned int period;
+ int rv;

+ rv = kstrtouint(buf, 10, &period);
+ if (rv < 0)
+ return rv;
sdev->queue_ramp_up_period = msecs_to_jiffies(period);
return period;
}
--
1.7.2.2

2010-12-05 17:52:08

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 41/45] kstrtox: convert drivers/usb/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/usb/gadget/storage_common.c | 7 ++++---
drivers/usb/host/ehci-dbg.c | 6 +++---
drivers/usb/serial/iuu_phoenix.c | 27 ++++++++++-----------------
3 files changed, 17 insertions(+), 23 deletions(-)

diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
index 3b513ba..b7c7df9 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -716,8 +716,9 @@ static ssize_t fsg_store_ro(struct device *dev, struct device_attribute *attr,
struct rw_semaphore *filesem = dev_get_drvdata(dev);
unsigned long ro;

- if (strict_strtoul(buf, 2, &ro))
- return -EINVAL;
+ rc = kstrtoul(buf, 2, &ro);
+ if (rc < 0)
+ return rc;

/*
* Allow the write-enable status to change only while the
@@ -743,7 +744,7 @@ static ssize_t fsg_store_nofua(struct device *dev,
struct fsg_lun *curlun = fsg_lun_from_dev(dev);
unsigned long nofua;

- if (strict_strtoul(buf, 2, &nofua))
+ if (kstrtoul(buf, 2, &nofua))
return -EINVAL;

/* Sync data when switching from async mode to sync */
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index 6e25996..34e263b 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -1000,7 +1000,7 @@ static ssize_t debug_lpm_write(struct file *file, const char __user *user_buf,
buf[len - 1] = '\0';

if (strncmp(buf, "enable", 5) == 0) {
- if (strict_strtoul(buf + 7, 10, &port))
+ if (kstrtoul(buf + 7, 10, &port))
return -EINVAL;
params = ehci_readl(ehci, &ehci->caps->hcs_params);
if (port > HCS_N_PORTS(params)) {
@@ -1018,7 +1018,7 @@ static ssize_t debug_lpm_write(struct file *file, const char __user *user_buf,
printk(KERN_INFO "force enable LPM for port %lu\n", port);
} else if (strncmp(buf, "hird=", 5) == 0) {
unsigned long hird;
- if (strict_strtoul(buf + 5, 16, &hird))
+ if (kstrtoul(buf + 5, 16, &hird))
return -EINVAL;
printk(KERN_INFO "setting hird %s %lu\n", buf + 6, hird);
temp = ehci_readl(ehci, &ehci->regs->command);
@@ -1026,7 +1026,7 @@ static ssize_t debug_lpm_write(struct file *file, const char __user *user_buf,
temp |= hird << 24;
ehci_writel(ehci, temp, &ehci->regs->command);
} else if (strncmp(buf, "disable", 7) == 0) {
- if (strict_strtoul(buf + 8, 10, &port))
+ if (kstrtoul(buf + 8, 10, &port))
return -EINVAL;
params = ehci_readl(ehci, &ehci->caps->hcs_params);
if (port > HCS_N_PORTS(params)) {
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
index 12ed594..0d23f3d 100644
--- a/drivers/usb/serial/iuu_phoenix.c
+++ b/drivers/usb/serial/iuu_phoenix.c
@@ -1227,23 +1227,16 @@ static ssize_t store_vcc_mode(struct device *dev,
{
struct usb_serial_port *port = to_usb_serial_port(dev);
struct iuu_private *priv = usb_get_serial_port_data(port);
- unsigned long v;
-
- if (strict_strtoul(buf, 10, &v)) {
- dev_err(dev, "%s - vcc_mode: %s is not a unsigned long\n",
- __func__, buf);
- goto fail_store_vcc_mode;
- }
-
- dbg("%s: setting vcc_mode = %ld", __func__, v);
-
- if ((v != 3) && (v != 5)) {
- dev_err(dev, "%s - vcc_mode %ld is invalid\n", __func__, v);
- } else {
- iuu_vcc_set(port, v);
- priv->vcc = v;
- }
-fail_store_vcc_mode:
+ int v;
+ int rv;
+
+ rv = kstrtoint(buf, 10, &v);
+ if (rv < 0)
+ return rv;
+ if (v != 3 && v != 5)
+ return -EINVAL;
+ iuu_vcc_set(port, v);
+ priv->vcc = v;
return count;
}

--
1.7.2.2

2010-12-05 17:52:14

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 42/45] kstrtox: convert drivers/video/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/video/backlight/adp5520_bl.c | 13 +-
drivers/video/backlight/adp8860_bl.c | 12 +-
drivers/video/backlight/backlight.c | 4 +-
drivers/video/backlight/s6e63m0.c | 2 +-
drivers/video/fsl-diu-fb.c | 36 +++--
.../video/omap2/displays/panel-tpo-td043mtea1.c | 10 +-
drivers/video/omap2/dss/display.c | 16 +-
drivers/video/via/viafbdev.c | 155 ++++++++++++--------
8 files changed, 151 insertions(+), 97 deletions(-)

diff --git a/drivers/video/backlight/adp5520_bl.c b/drivers/video/backlight/adp5520_bl.c
index 9f436e0..497d0a7 100644
--- a/drivers/video/backlight/adp5520_bl.c
+++ b/drivers/video/backlight/adp5520_bl.c
@@ -18,7 +18,7 @@ struct adp5520_bl {
struct device *master;
struct adp5520_backlight_platform_data *pdata;
struct mutex lock;
- unsigned long cached_daylight_max;
+ u8 cached_daylight_max;
int id;
int current_brightness;
};
@@ -156,11 +156,11 @@ static ssize_t adp5520_store(struct device *dev, const char *buf,
size_t count, int reg)
{
struct adp5520_bl *data = dev_get_drvdata(dev);
- unsigned long val;
+ u8 val;
int ret;

- ret = strict_strtoul(buf, 10, &val);
- if (ret)
+ ret = kstrtou8(buf, 10, &val);
+ if (ret < 0)
return ret;

mutex_lock(&data->lock);
@@ -211,8 +211,11 @@ static ssize_t adp5520_bl_daylight_max_store(struct device *dev,
const char *buf, size_t count)
{
struct adp5520_bl *data = dev_get_drvdata(dev);
+ int rv;

- strict_strtoul(buf, 10, &data->cached_daylight_max);
+ rv = kstrtou8(buf, 10, &data->cached_daylight_max);
+ if (rv < 0)
+ return rv;
return adp5520_store(dev, buf, count, ADP5520_DAYLIGHT_MAX);
}
static DEVICE_ATTR(daylight_max, 0664, adp5520_bl_daylight_max_show,
diff --git a/drivers/video/backlight/adp8860_bl.c b/drivers/video/backlight/adp8860_bl.c
index 734c650..6cfbb5f 100644
--- a/drivers/video/backlight/adp8860_bl.c
+++ b/drivers/video/backlight/adp8860_bl.c
@@ -110,7 +110,7 @@ struct adp8860_bl {
struct adp8860_led *led;
struct adp8860_backlight_platform_data *pdata;
struct mutex lock;
- unsigned long cached_daylight_max;
+ u8 cached_daylight_max;
int id;
int revid;
int current_brightness;
@@ -449,10 +449,10 @@ static ssize_t adp8860_store(struct device *dev, const char *buf,
size_t count, int reg)
{
struct adp8860_bl *data = dev_get_drvdata(dev);
- unsigned long val;
+ u8 val;
int ret;

- ret = strict_strtoul(buf, 10, &val);
+ ret = kstrtou8(buf, 10, &val);
if (ret)
return ret;

@@ -502,7 +502,9 @@ static ssize_t adp8860_bl_l1_daylight_max_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
struct adp8860_bl *data = dev_get_drvdata(dev);
- int ret = strict_strtoul(buf, 10, &data->cached_daylight_max);
+ int ret;
+
+ ret = kstrtou8(buf, 10, &data->cached_daylight_max);
if (ret)
return ret;

@@ -609,7 +611,7 @@ static ssize_t adp8860_bl_ambient_light_zone_store(struct device *dev,
uint8_t reg_val;
int ret;

- ret = strict_strtoul(buf, 10, &val);
+ ret = kstrtoul(buf, 10, &val);
if (ret)
return ret;

diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index 0870329..e6cd673 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -110,7 +110,7 @@ static ssize_t backlight_store_power(struct device *dev,
struct backlight_device *bd = to_backlight_device(dev);
unsigned long power;

- rc = strict_strtoul(buf, 0, &power);
+ rc = kstrtoul(buf, 0, &power);
if (rc)
return rc;

@@ -144,7 +144,7 @@ static ssize_t backlight_store_brightness(struct device *dev,
struct backlight_device *bd = to_backlight_device(dev);
unsigned long brightness;

- rc = strict_strtoul(buf, 0, &brightness);
+ rc = kstrtoul(buf, 0, &brightness);
if (rc)
return rc;

diff --git a/drivers/video/backlight/s6e63m0.c b/drivers/video/backlight/s6e63m0.c
index 5927db0..8bbbc4a 100644
--- a/drivers/video/backlight/s6e63m0.c
+++ b/drivers/video/backlight/s6e63m0.c
@@ -689,7 +689,7 @@ static ssize_t s6e63m0_sysfs_store_gamma_mode(struct device *dev,
struct backlight_device *bd = NULL;
int brightness, rc;

- rc = strict_strtoul(buf, 0, (unsigned long *)&lcd->gamma_mode);
+ rc = kstrtouint(buf, 0, &lcd->gamma_mode);
if (rc < 0)
return rc;

diff --git a/drivers/video/fsl-diu-fb.c b/drivers/video/fsl-diu-fb.c
index 8bbbf08..88ffbac 100644
--- a/drivers/video/fsl-diu-fb.c
+++ b/drivers/video/fsl-diu-fb.c
@@ -182,7 +182,7 @@ static struct fb_videomode __devinitdata fsl_diu_mode_db[] = {
};

static char *fb_mode = "1024x768-32@60";
-static unsigned long default_bpp = 32;
+static unsigned int default_bpp = 32;
static int monitor_port;

#if defined(CONFIG_NOT_COHERENT_CACHE)
@@ -1455,13 +1455,15 @@ static void free_buf(struct device *dev, struct diu_addr *buf, u32 size,
static ssize_t store_monitor(struct device *device,
struct device_attribute *attr, const char *buf, size_t count)
{
- int old_monitor_port;
- unsigned long val;
struct fsl_diu_data *machine_data =
container_of(attr, struct fsl_diu_data, dev_attr);
+ int old_monitor_port;
+ int val;
+ int rv;

- if (strict_strtoul(buf, 10, &val))
- return 0;
+ rv = kstrtoint(buf, 10, &val);
+ if (rv < 0)
+ return rv;

old_monitor_port = machine_data->monitor_port;
machine_data->monitor_port = diu_ops.set_sysfs_monitor_port(val);
@@ -1700,20 +1702,28 @@ static int fsl_diu_remove(struct platform_device *ofdev)
static int __init fsl_diu_setup(char *options)
{
char *opt;
- unsigned long val;

if (!options || !*options)
return 0;

while ((opt = strsep(&options, ",")) != NULL) {
+ int rv;
+
if (!*opt)
continue;
if (!strncmp(opt, "monitor=", 8)) {
- if (!strict_strtoul(opt + 8, 10, &val) && (val <= 2))
- monitor_port = val;
+ int val;
+
+ rv = kstrtoint(opt + 8, 10, &val);
+ if (rv < 0)
+ return rv;
+ if (val < 0 || val > 2)
+ return -EINVAL;
+ monitor_port = val;
} else if (!strncmp(opt, "bpp=", 4)) {
- if (!strict_strtoul(opt + 4, 10, &val))
- default_bpp = val;
+ rv = kstrtouint(opt + 4, 10, &default_bpp);
+ if (rv < 0)
+ return rv;
} else
fb_mode = opt;
}
@@ -1762,7 +1772,9 @@ static int __init fsl_diu_init(void)
*/
if (fb_get_options("fslfb", &option))
return -ENODEV;
- fsl_diu_setup(option);
+ ret = fsl_diu_setup(option);
+ if (ret < 0)
+ return ret;
#endif
printk(KERN_INFO "Freescale DIU driver\n");

@@ -1827,7 +1839,7 @@ MODULE_LICENSE("GPL");
module_param_named(mode, fb_mode, charp, 0);
MODULE_PARM_DESC(mode,
"Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
-module_param_named(bpp, default_bpp, ulong, 0);
+module_param_named(bpp, default_bpp, uint, 0);
MODULE_PARM_DESC(bpp, "Specify bit-per-pixel if not specified mode");
module_param_named(monitor, monitor_port, int, 0);
MODULE_PARM_DESC(monitor,
diff --git a/drivers/video/omap2/displays/panel-tpo-td043mtea1.c b/drivers/video/omap2/displays/panel-tpo-td043mtea1.c
index dbe9d43..77a363b 100644
--- a/drivers/video/omap2/displays/panel-tpo-td043mtea1.c
+++ b/drivers/video/omap2/displays/panel-tpo-td043mtea1.c
@@ -147,7 +147,7 @@ static ssize_t tpo_td043_vmirror_store(struct device *dev,
long val;
int ret;

- ret = strict_strtol(buf, 0, &val);
+ ret = kstrtol(buf, 0, &val);
if (ret < 0)
return ret;

@@ -172,11 +172,13 @@ static ssize_t tpo_td043_mode_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
struct tpo_td043_device *tpo_td043 = dev_get_drvdata(dev);
- long val;
+ u8 val;
int ret;

- ret = strict_strtol(buf, 0, &val);
- if (ret != 0 || val & ~7)
+ ret = kstrtou8(buf, 0, &val);
+ if (ret < 0)
+ return ret;
+ if (val & ~7)
return -EINVAL;

tpo_td043->mode = val;
diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
index 22dd7a4..413b618 100644
--- a/drivers/video/omap2/dss/display.c
+++ b/drivers/video/omap2/dss/display.c
@@ -262,21 +262,21 @@ static ssize_t display_wss_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t size)
{
struct omap_dss_device *dssdev = to_dss_device(dev);
- unsigned long wss;
- int r;
+ u32 wss;
+ int rv;

if (!dssdev->driver->get_wss || !dssdev->driver->set_wss)
return -ENOENT;

- if (strict_strtoul(buf, 0, &wss))
- return -EINVAL;
-
+ rv = kstrtou32(buf, 0, &wss);
+ if (rv < 0)
+ return rv;
if (wss > 0xfffff)
return -EINVAL;

- r = dssdev->driver->set_wss(dssdev, wss);
- if (r)
- return r;
+ rv = dssdev->driver->set_wss(dssdev, wss);
+ if (rv)
+ return rv;

return size;
}
diff --git a/drivers/video/via/viafbdev.c b/drivers/video/via/viafbdev.c
index d298cfc..35d5abb 100644
--- a/drivers/video/via/viafbdev.c
+++ b/drivers/video/via/viafbdev.c
@@ -1129,7 +1129,6 @@ static ssize_t viafb_dvp0_proc_write(struct file *file,
const char __user *buffer, size_t count, loff_t *pos)
{
char buf[20], *value, *pbuf;
- u8 reg_val = 0;
unsigned long length, i;
if (count < 1)
return -EINVAL;
@@ -1141,7 +1140,12 @@ static ssize_t viafb_dvp0_proc_write(struct file *file,
for (i = 0; i < 3; i++) {
value = strsep(&pbuf, " ");
if (value != NULL) {
- strict_strtoul(value, 0, (unsigned long *)&reg_val);
+ u8 reg_val;
+ int rv;
+
+ rv = kstrtou8(value, 0, &reg_val);
+ if (rv < 0)
+ return rv;
DEBUG_MSG(KERN_INFO "DVP0:reg_val[%l]=:%x\n", i,
reg_val);
switch (i) {
@@ -1199,7 +1203,6 @@ static ssize_t viafb_dvp1_proc_write(struct file *file,
const char __user *buffer, size_t count, loff_t *pos)
{
char buf[20], *value, *pbuf;
- u8 reg_val = 0;
unsigned long length, i;
if (count < 1)
return -EINVAL;
@@ -1211,7 +1214,10 @@ static ssize_t viafb_dvp1_proc_write(struct file *file,
for (i = 0; i < 3; i++) {
value = strsep(&pbuf, " ");
if (value != NULL) {
- strict_strtoul(value, 0, (unsigned long *)&reg_val);
+ u8 reg_val;
+ int rv;
+
+ rv = kstrtou8(value, 0, &reg_val);
switch (i) {
case 0:
viafb_write_reg_mask(CR9B, VIACR,
@@ -1261,15 +1267,19 @@ static ssize_t viafb_dfph_proc_write(struct file *file,
const char __user *buffer, size_t count, loff_t *pos)
{
char buf[20];
- u8 reg_val = 0;
+ u8 reg_val;
unsigned long length;
+ int rv;
+
if (count < 1)
return -EINVAL;
length = count > 20 ? 20 : count;
if (copy_from_user(&buf[0], buffer, length))
return -EFAULT;
buf[length - 1] = '\0'; /*Ensure end string */
- strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
+ rv = kstrtou8(&buf[0], 0, &reg_val);
+ if (rv < 0)
+ return rv;
viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f);
return count;
}
@@ -1300,15 +1310,19 @@ static ssize_t viafb_dfpl_proc_write(struct file *file,
const char __user *buffer, size_t count, loff_t *pos)
{
char buf[20];
- u8 reg_val = 0;
+ u8 reg_val;
unsigned long length;
+ int rv;
+
if (count < 1)
return -EINVAL;
length = count > 20 ? 20 : count;
if (copy_from_user(&buf[0], buffer, length))
return -EFAULT;
buf[length - 1] = '\0'; /*Ensure end string */
- strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
+ rv = kstrtou8(&buf[0], 0, &reg_val);
+ if (rv < 0)
+ return rv;
viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
return count;
}
@@ -1365,6 +1379,8 @@ static ssize_t viafb_vt1636_proc_write(struct file *file,
char buf[30], *value, *pbuf;
struct IODATA reg_val;
unsigned long length, i;
+ int rv;
+
if (count < 1)
return -EINVAL;
length = count > 30 ? 30 : count;
@@ -1377,8 +1393,9 @@ static ssize_t viafb_vt1636_proc_write(struct file *file,
for (i = 0; i < 2; i++) {
value = strsep(&pbuf, " ");
if (value != NULL) {
- strict_strtoul(value, 0,
- (unsigned long *)&reg_val.Data);
+ rv = kstrtou8(value, 0, &reg_val.Data);
+ if (rv < 0)
+ return rv;
switch (i) {
case 0:
reg_val.Index = 0x08;
@@ -1414,8 +1431,9 @@ static ssize_t viafb_vt1636_proc_write(struct file *file,
for (i = 0; i < 2; i++) {
value = strsep(&pbuf, " ");
if (value != NULL) {
- strict_strtoul(value, 0,
- (unsigned long *)&reg_val.Data);
+ rv = kstrtou8(value, 0, &reg_val.Data);
+ if (rv < 0)
+ return rv;
switch (i) {
case 0:
reg_val.Index = 0x08;
@@ -1940,6 +1958,8 @@ static int __init viafb_setup(char *options)
return 0;

while ((this_opt = strsep(&options, ",")) != NULL) {
+ int rv;
+
if (!*this_opt)
continue;

@@ -1947,54 +1967,65 @@ static int __init viafb_setup(char *options)
viafb_mode1 = kstrdup(this_opt + 12, GFP_KERNEL);
else if (!strncmp(this_opt, "viafb_mode=", 11))
viafb_mode = kstrdup(this_opt + 11, GFP_KERNEL);
- else if (!strncmp(this_opt, "viafb_bpp1=", 11))
- strict_strtoul(this_opt + 11, 0,
- (unsigned long *)&viafb_bpp1);
- else if (!strncmp(this_opt, "viafb_bpp=", 10))
- strict_strtoul(this_opt + 10, 0,
- (unsigned long *)&viafb_bpp);
- else if (!strncmp(this_opt, "viafb_refresh1=", 15))
- strict_strtoul(this_opt + 15, 0,
- (unsigned long *)&viafb_refresh1);
- else if (!strncmp(this_opt, "viafb_refresh=", 14))
- strict_strtoul(this_opt + 14, 0,
- (unsigned long *)&viafb_refresh);
- else if (!strncmp(this_opt, "viafb_lcd_dsp_method=", 21))
- strict_strtoul(this_opt + 21, 0,
- (unsigned long *)&viafb_lcd_dsp_method);
- else if (!strncmp(this_opt, "viafb_lcd_panel_id=", 19))
- strict_strtoul(this_opt + 19, 0,
- (unsigned long *)&viafb_lcd_panel_id);
- else if (!strncmp(this_opt, "viafb_accel=", 12))
- strict_strtoul(this_opt + 12, 0,
- (unsigned long *)&viafb_accel);
- else if (!strncmp(this_opt, "viafb_SAMM_ON=", 14))
- strict_strtoul(this_opt + 14, 0,
- (unsigned long *)&viafb_SAMM_ON);
- else if (!strncmp(this_opt, "viafb_active_dev=", 17))
+ else if (!strncmp(this_opt, "viafb_bpp1=", 11)) {
+ rv = kstrtoint(this_opt + 11, 0, &viafb_bpp1);
+ if (rv < 0)
+ return rv;
+ } else if (!strncmp(this_opt, "viafb_bpp=", 10)) {
+ rv = kstrtoint(this_opt + 10, 0, &viafb_bpp);
+ if (rv < 0)
+ return rv;
+ } else if (!strncmp(this_opt, "viafb_refresh1=", 15)) {
+ rv = kstrtoint(this_opt + 15, 0, &viafb_refresh1);
+ if (rv < 0)
+ return rv;
+ } else if (!strncmp(this_opt, "viafb_refresh=", 14)) {
+ rv = kstrtoint(this_opt + 14, 0, &viafb_refresh);
+ if (rv < 0)
+ return rv;
+ } else if (!strncmp(this_opt, "viafb_lcd_dsp_method=", 21)) {
+ rv = kstrtoint(this_opt + 21, 0, &viafb_lcd_dsp_method);
+ if (rv < 0)
+ return rv;
+ } else if (!strncmp(this_opt, "viafb_lcd_panel_id=", 19)) {
+ rv = kstrtoint(this_opt + 19, 0, &viafb_lcd_panel_id);
+ if (rv < 0)
+ return rv;
+ } else if (!strncmp(this_opt, "viafb_accel=", 12)) {
+ rv = kstrtoint(this_opt + 12, 0, &viafb_accel);
+ if (rv < 0)
+ return rv;
+ } else if (!strncmp(this_opt, "viafb_SAMM_ON=", 14)) {
+ rv = kstrtoint(this_opt + 14, 0, &viafb_SAMM_ON);
+ if (rv < 0)
+ return rv;
+ } else if (!strncmp(this_opt, "viafb_active_dev=", 17))
viafb_active_dev = kstrdup(this_opt + 17, GFP_KERNEL);
- else if (!strncmp(this_opt,
- "viafb_display_hardware_layout=", 30))
- strict_strtoul(this_opt + 30, 0,
- (unsigned long *)&viafb_display_hardware_layout);
- else if (!strncmp(this_opt, "viafb_second_size=", 18))
- strict_strtoul(this_opt + 18, 0,
- (unsigned long *)&viafb_second_size);
- else if (!strncmp(this_opt,
- "viafb_platform_epia_dvi=", 24))
- strict_strtoul(this_opt + 24, 0,
- (unsigned long *)&viafb_platform_epia_dvi);
- else if (!strncmp(this_opt,
- "viafb_device_lcd_dualedge=", 26))
- strict_strtoul(this_opt + 26, 0,
- (unsigned long *)&viafb_device_lcd_dualedge);
- else if (!strncmp(this_opt, "viafb_bus_width=", 16))
- strict_strtoul(this_opt + 16, 0,
- (unsigned long *)&viafb_bus_width);
- else if (!strncmp(this_opt, "viafb_lcd_mode=", 15))
- strict_strtoul(this_opt + 15, 0,
- (unsigned long *)&viafb_lcd_mode);
- else if (!strncmp(this_opt, "viafb_lcd_port=", 15))
+ else if (!strncmp(this_opt, "viafb_display_hardware_layout=", 30)) {
+ rv = kstrtoint(this_opt + 30, 0, &viafb_display_hardware_layout);
+ if (rv < 0)
+ return rv;
+ } else if (!strncmp(this_opt, "viafb_second_size=", 18)) {
+ rv = kstrtoint(this_opt + 18, 0, &viafb_second_size);
+ if (rv < 0)
+ return rv;
+ } else if (!strncmp(this_opt, "viafb_platform_epia_dvi=", 24)) {
+ rv = kstrtoint(this_opt + 24, 0, &viafb_platform_epia_dvi);
+ if (rv < 0)
+ return rv;
+ } else if (!strncmp(this_opt, "viafb_device_lcd_dualedge=", 26)) {
+ rv = kstrtoint(this_opt + 26, 0, &viafb_device_lcd_dualedge);
+ if (rv < 0)
+ return rv;
+ } else if (!strncmp(this_opt, "viafb_bus_width=", 16)) {
+ rv = kstrtoint(this_opt + 16, 0, &viafb_bus_width);
+ if (rv < 0)
+ return rv;
+ } else if (!strncmp(this_opt, "viafb_lcd_mode=", 15)) {
+ rv = kstrtoint(this_opt + 15, 0, &viafb_lcd_mode);
+ if (rv < 0)
+ return rv;
+ } else if (!strncmp(this_opt, "viafb_lcd_port=", 15))
viafb_lcd_port = kstrdup(this_opt + 15, GFP_KERNEL);
else if (!strncmp(this_opt, "viafb_dvi_port=", 15))
viafb_dvi_port = kstrdup(this_opt + 15, GFP_KERNEL);
@@ -2011,9 +2042,13 @@ int __init viafb_init(void)
u32 dummy;
#ifndef MODULE
char *option = NULL;
+ int rv;
+
if (fb_get_options("viafb", &option))
return -ENODEV;
- viafb_setup(option);
+ rv = viafb_setup(option);
+ if (rv < 0)
+ return rv;
#endif
if (parse_mode(viafb_mode, &dummy, &dummy)
|| parse_mode(viafb_mode1, &dummy, &dummy)
--
1.7.2.2

2010-12-05 17:52:22

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 44/45] kstrtox: convert sound/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
sound/drivers/dummy.c | 2 +-
sound/pci/hda/hda_hwdep.c | 10 ++++------
sound/pci/hda/patch_sigmatel.c | 7 ++-----
sound/soc/codecs/wm8962.c | 4 ++--
sound/soc/soc-core.c | 6 +++---
5 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
index 7f41990..d3b1a02 100644
--- a/sound/drivers/dummy.c
+++ b/sound/drivers/dummy.c
@@ -953,7 +953,7 @@ static void dummy_proc_write(struct snd_info_entry *entry,
if (i >= ARRAY_SIZE(fields))
continue;
snd_info_get_str(item, ptr, sizeof(item));
- if (strict_strtoull(item, 0, &val))
+ if (kstrtoull(item, 0, &val))
continue;
if (fields[i].size == sizeof(int))
*get_dummy_int_ptr(dummy, fields[i].offset) = val;
diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c
index bf3ced5..ecc7edb 100644
--- a/sound/pci/hda/hda_hwdep.c
+++ b/sound/pci/hda/hda_hwdep.c
@@ -293,11 +293,11 @@ static ssize_t type##_store(struct device *dev, \
{ \
struct snd_hwdep *hwdep = dev_get_drvdata(dev); \
struct hda_codec *codec = hwdep->private_data; \
- unsigned long val; \
- int err = strict_strtoul(buf, 0, &val); \
+ int err; \
+ \
+ err = kstrtou32(buf, 0, &codec->type); \
if (err < 0) \
return err; \
- codec->type = val; \
return count; \
}

@@ -699,9 +699,7 @@ static void parse_chip_name_mode(char *buf, struct hda_bus *bus,
static void parse_##name##_mode(char *buf, struct hda_bus *bus, \
struct hda_codec **codecp) \
{ \
- unsigned long val; \
- if (!strict_strtoul(buf, 0, &val)) \
- (*codecp)->name = val; \
+ kstrtou32(buf, 0, &(*codecp)->name); \
}

DEFINE_PARSE_ID_MODE(vendor_id);
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index efa4225..0fedc41 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -4192,16 +4192,13 @@ static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
int enable);

static inline int get_int_hint(struct hda_codec *codec, const char *key,
- int *valp)
+ unsigned int *val)
{
const char *p;
p = snd_hda_get_hint(codec, key);
if (p) {
- unsigned long val;
- if (!strict_strtoul(p, 0, &val)) {
- *valp = val;
+ if (kstrtouint(p, 0, val) == 0)
return 1;
- }
}
return 0;
}
diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c
index e809274..f1f76d8 100644
--- a/sound/soc/codecs/wm8962.c
+++ b/sound/soc/codecs/wm8962.c
@@ -3499,10 +3499,10 @@ static ssize_t wm8962_beep_set(struct device *dev,
const char *buf, size_t count)
{
struct wm8962_priv *wm8962 = dev_get_drvdata(dev);
- long int time;
+ int time;
int ret;

- ret = strict_strtol(buf, 10, &time);
+ ret = kstrtoint(buf, 10, &time);
if (ret != 0)
return ret;

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 441285a..3cdf2d2 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -167,7 +167,7 @@ static ssize_t pmdown_time_set(struct device *dev,
container_of(dev, struct snd_soc_pcm_runtime, dev);
int ret;

- ret = strict_strtol(buf, 10, &rtd->pmdown_time);
+ ret = kstrtol(buf, 10, &rtd->pmdown_time);
if (ret)
return ret;

@@ -204,7 +204,7 @@ static ssize_t codec_reg_write_file(struct file *file,
char buf[32];
int buf_size;
char *start = buf;
- unsigned long reg, value;
+ u32 reg, value;
int step = 1;
struct snd_soc_codec *codec = file->private_data;

@@ -223,7 +223,7 @@ static ssize_t codec_reg_write_file(struct file *file,
return -EINVAL;
while (*start == ' ')
start++;
- if (strict_strtoul(start, 16, &value))
+ if (kstrtou32(start, 16, &value))
return -EINVAL;
codec->driver->write(codec, reg, value);
return buf_size;
--
1.7.2.2

2010-12-05 17:52:34

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 45/45] kstrtox: convert net/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
net/bluetooth/hci_sysfs.c | 16 ++++++++--------
net/dns_resolver/dns_key.c | 5 +++--
net/mac80211/debugfs.c | 10 ++++------
net/rfkill/core.c | 11 +++++------
net/sunrpc/addr.c | 18 +++++++-----------
net/sunrpc/auth.c | 6 +++---
net/sunrpc/xprtsock.c | 8 +++++---
7 files changed, 35 insertions(+), 39 deletions(-)

diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index 5fce3d6..131ce95 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -277,9 +277,9 @@ static ssize_t show_idle_timeout(struct device *dev, struct device_attribute *at
static ssize_t store_idle_timeout(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct hci_dev *hdev = dev_get_drvdata(dev);
- unsigned long val;
+ u32 val;

- if (strict_strtoul(buf, 0, &val) < 0)
+ if (kstrtou32(buf, 0, &val) < 0)
return -EINVAL;

if (val != 0 && (val < 500 || val > 3600000))
@@ -299,12 +299,12 @@ static ssize_t show_sniff_max_interval(struct device *dev, struct device_attribu
static ssize_t store_sniff_max_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct hci_dev *hdev = dev_get_drvdata(dev);
- unsigned long val;
+ u16 val;

- if (strict_strtoul(buf, 0, &val) < 0)
+ if (kstrtou16(buf, 0, &val) < 0)
return -EINVAL;

- if (val < 0x0002 || val > 0xFFFE || val % 2)
+ if (val == 0 || val % 2)
return -EINVAL;

if (val < hdev->sniff_min_interval)
@@ -324,12 +324,12 @@ static ssize_t show_sniff_min_interval(struct device *dev, struct device_attribu
static ssize_t store_sniff_min_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct hci_dev *hdev = dev_get_drvdata(dev);
- unsigned long val;
+ u16 val;

- if (strict_strtoul(buf, 0, &val) < 0)
+ if (kstrtou16(buf, 0, &val) < 0)
return -EINVAL;

- if (val < 0x0002 || val > 0xFFFE || val % 2)
+ if (val == 0 || val % 2)
return -EINVAL;

if (val > hdev->sniff_max_interval)
diff --git a/net/dns_resolver/dns_key.c b/net/dns_resolver/dns_key.c
index 739435a..8cd5294 100644
--- a/net/dns_resolver/dns_key.c
+++ b/net/dns_resolver/dns_key.c
@@ -62,7 +62,6 @@ static int
dns_resolver_instantiate(struct key *key, const void *_data, size_t datalen)
{
struct user_key_payload *upayload;
- unsigned long derrno;
int ret;
size_t result_len = 0;
const char *data = _data, *end, *opt;
@@ -113,11 +112,13 @@ dns_resolver_instantiate(struct key *key, const void *_data, size_t datalen)
* that's to be recorded as the result in this key */
if (opt_nlen == sizeof(DNS_ERRORNO_OPTION) - 1 &&
memcmp(opt, DNS_ERRORNO_OPTION, opt_nlen) == 0) {
+ unsigned long derrno;
+
kdebug("dns error number option");
if (opt_vlen <= 0)
goto bad_option_value;

- ret = strict_strtoul(eq, 10, &derrno);
+ ret = kstrtoul(eq, 10, &derrno);
if (ret < 0)
goto bad_option_value;

diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
index 18260aa..149efdd 100644
--- a/net/mac80211/debugfs.c
+++ b/net/mac80211/debugfs.c
@@ -181,7 +181,7 @@ static ssize_t uapsd_queues_write(struct file *file,
size_t count, loff_t *ppos)
{
struct ieee80211_local *local = file->private_data;
- unsigned long val;
+ unsigned int val;
char buf[10];
size_t len;
int ret;
@@ -191,8 +191,7 @@ static ssize_t uapsd_queues_write(struct file *file,
return -EFAULT;
buf[len] = '\0';

- ret = strict_strtoul(buf, 0, &val);
-
+ ret = kstrtouint(buf, 0, &val);
if (ret)
return -EINVAL;

@@ -228,7 +227,7 @@ static ssize_t uapsd_max_sp_len_write(struct file *file,
size_t count, loff_t *ppos)
{
struct ieee80211_local *local = file->private_data;
- unsigned long val;
+ unsigned int val;
char buf[10];
size_t len;
int ret;
@@ -238,8 +237,7 @@ static ssize_t uapsd_max_sp_len_write(struct file *file,
return -EFAULT;
buf[len] = '\0';

- ret = strict_strtoul(buf, 0, &val);
-
+ ret = kstrtouint(buf, 0, &val);
if (ret)
return -EINVAL;

diff --git a/net/rfkill/core.c b/net/rfkill/core.c
index 04f5990..fd55757 100644
--- a/net/rfkill/core.c
+++ b/net/rfkill/core.c
@@ -652,17 +652,16 @@ static ssize_t rfkill_soft_store(struct device *dev,
const char *buf, size_t count)
{
struct rfkill *rfkill = to_rfkill(dev);
- unsigned long state;
+ unsigned int state;
int err;

if (!capable(CAP_NET_ADMIN))
return -EPERM;

- err = strict_strtoul(buf, 0, &state);
+ err = kstrtouint(buf, 0, &state);
if (err)
return err;
-
- if (state > 1 )
+ if (state > 1)
return -EINVAL;

mutex_lock(&rfkill_global_mutex);
@@ -696,13 +695,13 @@ static ssize_t rfkill_state_store(struct device *dev,
const char *buf, size_t count)
{
struct rfkill *rfkill = to_rfkill(dev);
- unsigned long state;
+ int state;
int err;

if (!capable(CAP_NET_ADMIN))
return -EPERM;

- err = strict_strtoul(buf, 0, &state);
+ err = kstrtoint(buf, 0, &state);
if (err)
return err;

diff --git a/net/sunrpc/addr.c b/net/sunrpc/addr.c
index 1419d0c..36c554c 100644
--- a/net/sunrpc/addr.c
+++ b/net/sunrpc/addr.c
@@ -173,15 +173,15 @@ static int rpc_parse_scope_id(const char *buf, const size_t buflen,
len = (buf + buflen) - delim - 1;
p = kstrndup(delim + 1, len, GFP_KERNEL);
if (p) {
- unsigned long scope_id = 0;
struct net_device *dev;
+ u32 scope_id;

dev = dev_get_by_name(&init_net, p);
if (dev != NULL) {
scope_id = dev->ifindex;
dev_put(dev);
} else {
- if (strict_strtoul(p, 10, &scope_id) == 0) {
+ if (kstrtou32(p, 10, &scope_id) < 0) {
kfree(p);
return 0;
}
@@ -299,7 +299,7 @@ EXPORT_SYMBOL_GPL(rpc_sockaddr2uaddr);
* @sap: buffer into which to plant socket address
* @salen: size of buffer
*
- * @uaddr does not have to be '\0'-terminated, but strict_strtoul() and
+ * @uaddr does not have to be '\0'-terminated, but kstrto*() and
* rpc_pton() require proper string termination to be successful.
*
* Returns the size of the socket address if successful; otherwise
@@ -309,7 +309,7 @@ size_t rpc_uaddr2sockaddr(const char *uaddr, const size_t uaddr_len,
struct sockaddr *sap, const size_t salen)
{
char *c, buf[RPCBIND_MAXUADDRLEN + sizeof('\0')];
- unsigned long portlo, porthi;
+ u8 portlo, porthi;
unsigned short port;

if (uaddr_len > RPCBIND_MAXUADDRLEN)
@@ -321,21 +321,17 @@ size_t rpc_uaddr2sockaddr(const char *uaddr, const size_t uaddr_len,
c = strrchr(buf, '.');
if (unlikely(c == NULL))
return 0;
- if (unlikely(strict_strtoul(c + 1, 10, &portlo) != 0))
- return 0;
- if (unlikely(portlo > 255))
+ if (unlikely(kstrtou8(c + 1, 10, &portlo) != 0))
return 0;

*c = '\0';
c = strrchr(buf, '.');
if (unlikely(c == NULL))
return 0;
- if (unlikely(strict_strtoul(c + 1, 10, &porthi) != 0))
- return 0;
- if (unlikely(porthi > 255))
+ if (unlikely(kstrtou8(c + 1, 10, &porthi) != 0))
return 0;

- port = (unsigned short)((porthi << 8) | portlo);
+ port = (porthi << 8) | portlo;

*c = '\0';
if (rpc_pton(buf, strlen(buf), sap, salen) == 0)
diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
index afe6784..79737b2 100644
--- a/net/sunrpc/auth.c
+++ b/net/sunrpc/auth.c
@@ -47,9 +47,9 @@ static int param_set_hashtbl_sz(const char *val, const struct kernel_param *kp)

if (!val)
goto out_inval;
- ret = strict_strtoul(val, 0, &num);
- if (ret == -EINVAL)
- goto out_inval;
+ ret = kstrtoul(val, 0, &num);
+ if (ret < 0)
+ return ret;
nbits = fls(num);
if (num > (1U << nbits))
nbits++;
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index dfcab5a..04d1496 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -2485,13 +2485,15 @@ static int param_set_uint_minmax(const char *val,
const struct kernel_param *kp,
unsigned int min, unsigned int max)
{
- unsigned long num;
+ unsigned int num;
int ret;

if (!val)
return -EINVAL;
- ret = strict_strtoul(val, 0, &num);
- if (ret == -EINVAL || num < min || num > max)
+ ret = kstrtouint(val, 0, &num);
+ if (ret < 0)
+ return ret;
+ if (num < min || num > max)
return -EINVAL;
*((unsigned int *)kp->arg) = num;
return 0;
--
1.7.2.2

2010-12-05 17:52:50

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 43/45] kstrtox: convert drivers/w1/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/w1/w1.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index b7b5014..cd3d308 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -233,10 +233,10 @@ static ssize_t w1_master_attribute_store_search(struct device * dev,
struct device_attribute *attr,
const char * buf, size_t count)
{
- long tmp;
struct w1_master *md = dev_to_w1_master(dev);
+ int tmp;

- if (strict_strtol(buf, 0, &tmp) == -EINVAL)
+ if (kstrtoint(buf, 0, &tmp) < 0)
return -EINVAL;

mutex_lock(&md->mutex);
@@ -265,10 +265,10 @@ static ssize_t w1_master_attribute_store_pullup(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
- long tmp;
struct w1_master *md = dev_to_w1_master(dev);
+ int tmp;

- if (strict_strtol(buf, 0, &tmp) == -EINVAL)
+ if (kstrtoint(buf, 0, &tmp) < 0)
return -EINVAL;

mutex_lock(&md->mutex);
--
1.7.2.2

2010-12-05 17:53:16

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 40/45] kstrtox: convert drivers/ssb/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/ssb/sprom.c | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/ssb/sprom.c b/drivers/ssb/sprom.c
index 4f7cc8d..fea2ac4 100644
--- a/drivers/ssb/sprom.c
+++ b/drivers/ssb/sprom.c
@@ -38,7 +38,6 @@ static int hex2sprom(u16 *sprom, const char *dump, size_t len,
{
char c, tmp[5] = { 0 };
int err, cnt = 0;
- unsigned long parsed;

/* Strip whitespace at the end. */
while (len) {
@@ -52,12 +51,14 @@ static int hex2sprom(u16 *sprom, const char *dump, size_t len,
return -EINVAL;

while (cnt < sprom_size_words) {
+ u16 parsed;
+
memcpy(tmp, dump, 4);
dump += 4;
- err = strict_strtoul(tmp, 16, &parsed);
+ err = kstrtou16(tmp, 16, &parsed);
if (err)
return err;
- sprom[cnt++] = swab16((u16)parsed);
+ sprom[cnt++] = swab16(parsed);
}

return 0;
--
1.7.2.2

2010-12-05 17:53:32

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 38/45] kstrtox: convert drivers/rtc/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/rtc/rtc-pcf2123.c | 23 +++++++++++------------
1 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/drivers/rtc/rtc-pcf2123.c b/drivers/rtc/rtc-pcf2123.c
index 71bab0e..9e08179 100644
--- a/drivers/rtc/rtc-pcf2123.c
+++ b/drivers/rtc/rtc-pcf2123.c
@@ -87,13 +87,14 @@ static ssize_t pcf2123_show(struct device *dev, struct device_attribute *attr,
struct spi_device *spi = to_spi_device(dev);
struct pcf2123_sysfs_reg *r;
u8 txbuf[1], rxbuf[1];
- unsigned long reg;
+ u8 reg;
int ret;

r = container_of(attr, struct pcf2123_sysfs_reg, attr);

- if (strict_strtoul(r->name, 16, &reg))
- return -EINVAL;
+ ret = kstrtou8(r->name, 16, &reg);
+ if (ret < 0)
+ return ret;

txbuf[0] = PCF2123_READ | reg;
ret = spi_write_then_read(spi, txbuf, 1, rxbuf, 1);
@@ -108,19 +109,17 @@ static ssize_t pcf2123_store(struct device *dev, struct device_attribute *attr,
struct spi_device *spi = to_spi_device(dev);
struct pcf2123_sysfs_reg *r;
u8 txbuf[2];
- unsigned long reg;
- unsigned long val;
-
int ret;

r = container_of(attr, struct pcf2123_sysfs_reg, attr);

- if (strict_strtoul(r->name, 16, &reg)
- || strict_strtoul(buffer, 10, &val))
- return -EINVAL;
-
- txbuf[0] = PCF2123_WRITE | reg;
- txbuf[1] = val;
+ ret = kstrtou8(r->name, 16, &txbuf[0]);
+ if (ret < 0)
+ return ret;
+ txbuf[0] |= PCF2123_WRITE;
+ ret = kstrtou8(buffer, 10, &txbuf[1]);
+ if (ret < 0)
+ return ret;
ret = spi_write(spi, txbuf, sizeof(txbuf));
if (ret < 0)
return -EIO;
--
1.7.2.2

2010-12-05 17:53:48

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 36/45] kstrtox: convert drivers/power/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/power/pcf50633-charger.c | 4 ++--
drivers/power/power_supply_sysfs.c | 6 +-----
2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/power/pcf50633-charger.c b/drivers/power/pcf50633-charger.c
index 4fa52e1..b6d9281 100644
--- a/drivers/power/pcf50633-charger.c
+++ b/drivers/power/pcf50633-charger.c
@@ -191,7 +191,7 @@ static ssize_t set_usblim(struct device *dev,
unsigned long ma;
int ret;

- ret = strict_strtoul(buf, 10, &ma);
+ ret = kstrtoul(buf, 10, &ma);
if (ret)
return -EINVAL;

@@ -228,7 +228,7 @@ static ssize_t set_chglim(struct device *dev,
if (!mbc->pcf->pdata->charger_reference_current_ma)
return -ENODEV;

- ret = strict_strtoul(buf, 10, &ma);
+ ret = kstrtoul(buf, 10, &ma);
if (ret)
return -EINVAL;

diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
index cd1f907..15d2d4a 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -107,15 +107,11 @@ static ssize_t power_supply_store_property(struct device *dev,
struct power_supply *psy = dev_get_drvdata(dev);
const ptrdiff_t off = attr - power_supply_attrs;
union power_supply_propval value;
- long long_val;

/* TODO: support other types than int */
- ret = strict_strtol(buf, 10, &long_val);
+ ret = kstrtoint(buf, 10, &value.intval);
if (ret < 0)
return ret;
-
- value.intval = long_val;
-
ret = psy->set_property(psy, off, &value);
if (ret < 0)
return ret;
--
1.7.2.2

2010-12-05 17:54:18

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 32/45] kstrtox: convert drivers/net/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/net/can/janz-ican3.c | 5 +++--
drivers/net/netxen/netxen_nic_main.c | 4 ++--
drivers/net/qlcnic/qlcnic_main.c | 4 ++--
drivers/net/stmmac/stmmac_main.c | 29 ++++++++++++++++-------------
4 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/drivers/net/can/janz-ican3.c b/drivers/net/can/janz-ican3.c
index 6e533dc..51fd497 100644
--- a/drivers/net/can/janz-ican3.c
+++ b/drivers/net/can/janz-ican3.c
@@ -1617,8 +1617,9 @@ static ssize_t ican3_sysfs_set_term(struct device *dev,
unsigned long enable;
int ret;

- if (strict_strtoul(buf, 0, &enable))
- return -EINVAL;
+ ret = kstrtoul(buf, 0, &enable);
+ if (ret < 0)
+ return ret;

ret = ican3_set_termination(mod, enable);
if (ret)
diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c
index e1d30d7..b2c79e7 100644
--- a/drivers/net/netxen/netxen_nic_main.c
+++ b/drivers/net/netxen/netxen_nic_main.c
@@ -2503,7 +2503,7 @@ netxen_store_bridged_mode(struct device *dev,
if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
goto err_out;

- if (strict_strtoul(buf, 2, &new))
+ if (kstrtoul(buf, 2, &new))
goto err_out;

if (!netxen_config_bridged_mode(adapter, !!new))
@@ -2542,7 +2542,7 @@ netxen_store_diag_mode(struct device *dev,
struct netxen_adapter *adapter = dev_get_drvdata(dev);
unsigned long new;

- if (strict_strtoul(buf, 2, &new))
+ if (kstrtoul(buf, 2, &new))
return -EINVAL;

if (!!new != !!(adapter->flags & NETXEN_NIC_DIAG_ENABLED))
diff --git a/drivers/net/qlcnic/qlcnic_main.c b/drivers/net/qlcnic/qlcnic_main.c
index a3dcd04..5c4e2db 100644
--- a/drivers/net/qlcnic/qlcnic_main.c
+++ b/drivers/net/qlcnic/qlcnic_main.c
@@ -3262,7 +3262,7 @@ qlcnic_store_bridged_mode(struct device *dev,
if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
goto err_out;

- if (strict_strtoul(buf, 2, &new))
+ if (kstrtoul(buf, 2, &new))
goto err_out;

if (!adapter->nic_ops->config_bridged_mode(adapter, !!new))
@@ -3298,7 +3298,7 @@ qlcnic_store_diag_mode(struct device *dev,
struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
unsigned long new;

- if (strict_strtoul(buf, 2, &new))
+ if (kstrtoul(buf, 2, &new))
return -EINVAL;

if (!!new != !!(adapter->flags & QLCNIC_DIAG_ENABLED))
diff --git a/drivers/net/stmmac/stmmac_main.c b/drivers/net/stmmac/stmmac_main.c
index 06bc603..8190289 100644
--- a/drivers/net/stmmac/stmmac_main.c
+++ b/drivers/net/stmmac/stmmac_main.c
@@ -1934,31 +1934,34 @@ static int __init stmmac_cmdline_opt(char *str)
if (!str || !*str)
return -EINVAL;
while ((opt = strsep(&str, ",")) != NULL) {
+ int rv;
+
if (!strncmp(opt, "debug:", 6))
- strict_strtoul(opt + 6, 0, (unsigned long *)&debug);
+ rv = kstrtoint(opt + 6, 0, &debug);
else if (!strncmp(opt, "phyaddr:", 8))
- strict_strtoul(opt + 8, 0, (unsigned long *)&phyaddr);
+ rv = kstrtoint(opt + 8, 0, &phyaddr);
else if (!strncmp(opt, "dma_txsize:", 11))
- strict_strtoul(opt + 11, 0,
- (unsigned long *)&dma_txsize);
+ rv = kstrtoint(opt + 11, 0, &dma_txsize);
else if (!strncmp(opt, "dma_rxsize:", 11))
- strict_strtoul(opt + 11, 0,
- (unsigned long *)&dma_rxsize);
+ rv = kstrtoint(opt + 11, 0, &dma_rxsize);
else if (!strncmp(opt, "buf_sz:", 7))
- strict_strtoul(opt + 7, 0, (unsigned long *)&buf_sz);
+ rv = kstrtoint(opt + 7, 0, &buf_sz);
else if (!strncmp(opt, "tc:", 3))
- strict_strtoul(opt + 3, 0, (unsigned long *)&tc);
+ rv = kstrtoint(opt + 3, 0, &tc);
else if (!strncmp(opt, "watchdog:", 9))
- strict_strtoul(opt + 9, 0, (unsigned long *)&watchdog);
+ rv = kstrtoint(opt + 9, 0, &watchdog);
else if (!strncmp(opt, "flow_ctrl:", 10))
- strict_strtoul(opt + 10, 0,
- (unsigned long *)&flow_ctrl);
+ rv = kstrtoint(opt + 10, 0, &flow_ctrl);
else if (!strncmp(opt, "pause:", 6))
- strict_strtoul(opt + 6, 0, (unsigned long *)&pause);
+ rv = kstrtoint(opt + 6, 0, &pause);
#ifdef CONFIG_STMMAC_TIMER
else if (!strncmp(opt, "tmrate:", 7))
- strict_strtoul(opt + 7, 0, (unsigned long *)&tmrate);
+ rv = kstrtoint(opt + 7, 0, &tmrate);
#endif
+ else
+ rv = -EINVAL;
+ if (rv < 0)
+ return rv;
}
return 0;
}
--
1.7.2.2

2010-12-05 17:54:34

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 19/45] kstrtox: convert drivers/gpio/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/gpio/gpiolib.c | 12 ++++++------
1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 21da9c1..0eb79d9 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -302,7 +302,7 @@ static ssize_t gpio_value_store(struct device *dev,
else {
long value;

- status = strict_strtol(buf, 0, &value);
+ status = kstrtol(buf, 0, &value);
if (status == 0) {
if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
value = !value;
@@ -528,7 +528,7 @@ static ssize_t gpio_active_low_store(struct device *dev,
} else {
long value;

- status = strict_strtol(buf, 0, &value);
+ status = kstrtol(buf, 0, &value);
if (status == 0)
status = sysfs_set_active_low(desc, dev, value != 0);
}
@@ -606,10 +606,10 @@ static ssize_t export_store(struct class *class,
struct class_attribute *attr,
const char *buf, size_t len)
{
- long gpio;
+ unsigned int gpio;
int status;

- status = strict_strtol(buf, 0, &gpio);
+ status = kstrtouint(buf, 0, &gpio);
if (status < 0)
goto done;

@@ -638,10 +638,10 @@ static ssize_t unexport_store(struct class *class,
struct class_attribute *attr,
const char *buf, size_t len)
{
- long gpio;
+ unsigned int gpio;
int status;

- status = strict_strtol(buf, 0, &gpio);
+ status = kstrtouint(buf, 0, &gpio);
if (status < 0)
goto done;

--
1.7.2.2

2010-12-05 17:54:50

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 30/45] kstrtox: convert drivers/misc/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/misc/ad525x_dpot.c | 2 +-
drivers/misc/apds9802als.c | 7 ++-
drivers/misc/apds990x.c | 45 +++++++++++++---------
drivers/misc/bh1770glc.c | 72 ++++++++++++++++++++++--------------
drivers/misc/bh1780gli.c | 4 +-
drivers/misc/bmp085.c | 31 ++++++---------
drivers/misc/ep93xx_pwm.c | 33 ++++++++--------
drivers/misc/hmc6352.c | 7 ++-
drivers/misc/isl29003.c | 28 ++++++++++----
drivers/misc/isl29020.c | 7 ++-
drivers/misc/iwmc3200top/log.c | 76 ++++++++++++++++----------------------
drivers/misc/sgi-gru/gruprocfs.c | 7 ++-
drivers/misc/ti_dac7512.c | 10 +++--
13 files changed, 175 insertions(+), 154 deletions(-)

diff --git a/drivers/misc/ad525x_dpot.c b/drivers/misc/ad525x_dpot.c
index 7cb9110..d0de26a 100644
--- a/drivers/misc/ad525x_dpot.c
+++ b/drivers/misc/ad525x_dpot.c
@@ -472,7 +472,7 @@ static ssize_t sysfs_set_reg(struct device *dev,
!test_bit(DPOT_RDAC_MASK & reg, data->otp_en_mask))
return -EPERM;

- err = strict_strtoul(buf, 10, &value);
+ err = kstrtoul(buf, 10, &value);
if (err)
return err;

diff --git a/drivers/misc/apds9802als.c b/drivers/misc/apds9802als.c
index 644d4cd..e6d0ebc 100644
--- a/drivers/misc/apds9802als.c
+++ b/drivers/misc/apds9802als.c
@@ -123,11 +123,12 @@ static ssize_t als_sensing_range_store(struct device *dev,
{
struct i2c_client *client = to_i2c_client(dev);
struct als_data *data = i2c_get_clientdata(client);
+ unsigned int val;
int ret_val;
- unsigned long val;

- if (strict_strtoul(buf, 10, &val))
- return -EINVAL;
+ ret_val = kstrtouint(buf, 10, &val);
+ if (ret_val < 0)
+ return ret_val;

if (val < 4096)
val = 1;
diff --git a/drivers/misc/apds990x.c b/drivers/misc/apds990x.c
index 200311f..411ab79 100644
--- a/drivers/misc/apds990x.c
+++ b/drivers/misc/apds990x.c
@@ -694,11 +694,12 @@ static ssize_t apds990x_lux_calib_store(struct device *dev,
{
struct apds990x_chip *chip = dev_get_drvdata(dev);
unsigned long value;
+ int rv;

- if (strict_strtoul(buf, 0, &value))
- return -EINVAL;
-
- if (chip->lux_calib > APDS_RANGE)
+ rv = kstrtoul(buf, 0, &value);
+ if (rv < 0)
+ return rv;
+ if (value > APDS_RANGE)
return -EINVAL;

chip->lux_calib = value;
@@ -757,11 +758,12 @@ static ssize_t apds990x_rate_store(struct device *dev,
const char *buf, size_t len)
{
struct apds990x_chip *chip = dev_get_drvdata(dev);
- unsigned long value;
+ unsigned int value;
int ret;

- if (strict_strtoul(buf, 0, &value))
- return -EINVAL;
+ ret = kstrtouint(buf, 0, &value);
+ if (ret < 0)
+ return ret;

mutex_lock(&chip->mutex);
ret = apds990x_set_arate(chip, value);
@@ -814,9 +816,11 @@ static ssize_t apds990x_prox_enable_store(struct device *dev,
{
struct apds990x_chip *chip = dev_get_drvdata(dev);
unsigned long value;
+ int rv;

- if (strict_strtoul(buf, 0, &value))
- return -EINVAL;
+ rv = kstrtoul(buf, 0, &value);
+ if (rv < 0)
+ return rv;

mutex_lock(&chip->mutex);

@@ -893,12 +897,12 @@ static ssize_t apds990x_lux_thresh_below_show(struct device *dev,
static ssize_t apds990x_set_lux_thresh(struct apds990x_chip *chip, u32 *target,
const char *buf)
{
- int ret = 0;
unsigned long thresh;
+ int ret;

- if (strict_strtoul(buf, 0, &thresh))
- return -EINVAL;
-
+ ret = kstrtoul(buf, 0, &thresh);
+ if (ret < 0)
+ return ret;
if (thresh > APDS_RANGE)
return -EINVAL;

@@ -957,11 +961,12 @@ static ssize_t apds990x_prox_threshold_store(struct device *dev,
const char *buf, size_t len)
{
struct apds990x_chip *chip = dev_get_drvdata(dev);
- unsigned long value;
-
- if (strict_strtoul(buf, 0, &value))
- return -EINVAL;
+ unsigned int value;
+ int rv;

+ rv = kstrtouint(buf, 0, &value);
+ if (rv < 0)
+ return rv;
if ((value > APDS_RANGE) || (value == 0) ||
(value < APDS_PROX_HYSTERESIS))
return -EINVAL;
@@ -991,9 +996,11 @@ static ssize_t apds990x_power_state_store(struct device *dev,
{
struct apds990x_chip *chip = dev_get_drvdata(dev);
unsigned long value;
+ int rv;

- if (strict_strtoul(buf, 0, &value))
- return -EINVAL;
+ rv = kstrtoul(buf, 0, &value);
+ if (rv < 0)
+ return rv;
if (value) {
pm_runtime_get_sync(dev);
mutex_lock(&chip->mutex);
diff --git a/drivers/misc/bh1770glc.c b/drivers/misc/bh1770glc.c
index d79a972..e9bd722 100644
--- a/drivers/misc/bh1770glc.c
+++ b/drivers/misc/bh1770glc.c
@@ -649,10 +649,11 @@ static ssize_t bh1770_power_state_store(struct device *dev,
{
struct bh1770_chip *chip = dev_get_drvdata(dev);
unsigned long value;
- ssize_t ret;
+ int ret;

- if (strict_strtoul(buf, 0, &value))
- return -EINVAL;
+ ret = kstrtoul(buf, 0, &value);
+ if (ret < 0)
+ return ret;

mutex_lock(&chip->mutex);
if (value) {
@@ -726,9 +727,11 @@ static ssize_t bh1770_prox_enable_store(struct device *dev,
{
struct bh1770_chip *chip = dev_get_drvdata(dev);
unsigned long value;
+ int rv;

- if (strict_strtoul(buf, 0, &value))
- return -EINVAL;
+ rv = kstrtoul(buf, 0, &value);
+ if (rv < 0)
+ return rv;

mutex_lock(&chip->mutex);
/* Assume no proximity. Sensor will tell real state soon */
@@ -823,10 +826,12 @@ static ssize_t bh1770_set_prox_rate_above(struct device *dev,
const char *buf, size_t count)
{
struct bh1770_chip *chip = dev_get_drvdata(dev);
- unsigned long value;
+ int value;
+ int rv;

- if (strict_strtoul(buf, 0, &value))
- return -EINVAL;
+ rv = kstrtoint(buf, 0, &value);
+ if (rv < 0)
+ return rv;

mutex_lock(&chip->mutex);
chip->prox_rate_threshold = bh1770_prox_rate_validate(value);
@@ -839,10 +844,12 @@ static ssize_t bh1770_set_prox_rate_below(struct device *dev,
const char *buf, size_t count)
{
struct bh1770_chip *chip = dev_get_drvdata(dev);
- unsigned long value;
+ int value;
+ int rv;

- if (strict_strtoul(buf, 0, &value))
- return -EINVAL;
+ rv = kstrtoint(buf, 0, &value);
+ if (rv < 0)
+ return rv;

mutex_lock(&chip->mutex);
chip->prox_rate = bh1770_prox_rate_validate(value);
@@ -862,11 +869,12 @@ static ssize_t bh1770_set_prox_thres(struct device *dev,
const char *buf, size_t count)
{
struct bh1770_chip *chip = dev_get_drvdata(dev);
- unsigned long value;
+ unsigned int value;
int ret;

- if (strict_strtoul(buf, 0, &value))
- return -EINVAL;
+ ret = kstrtouint(buf, 0, &value);
+ if (ret < 0)
+ return ret;
if (value > BH1770_PROX_RANGE)
return -EINVAL;

@@ -892,10 +900,12 @@ static ssize_t bh1770_prox_persistence_store(struct device *dev,
const char *buf, size_t len)
{
struct bh1770_chip *chip = dev_get_drvdata(dev);
- unsigned long value;
+ unsigned int value;
+ int rv;

- if (strict_strtoul(buf, 0, &value))
- return -EINVAL;
+ rv = kstrtouint(buf, 0, &value);
+ if (rv < 0)
+ return rv;

if (value > BH1770_PROX_MAX_PERSISTENCE)
return -EINVAL;
@@ -917,10 +927,12 @@ static ssize_t bh1770_prox_abs_thres_store(struct device *dev,
const char *buf, size_t len)
{
struct bh1770_chip *chip = dev_get_drvdata(dev);
- unsigned long value;
+ unsigned int value;
+ int rv;

- if (strict_strtoul(buf, 0, &value))
- return -EINVAL;
+ rv = kstrtouint(buf, 0, &value);
+ if (rv < 0)
+ return rv;

if (value > BH1770_PROX_RANGE)
return -EINVAL;
@@ -960,12 +972,14 @@ static ssize_t bh1770_lux_calib_store(struct device *dev,
const char *buf, size_t len)
{
struct bh1770_chip *chip = dev_get_drvdata(dev);
- unsigned long value;
+ u32 value;
u32 old_calib;
u32 new_corr;
+ int rv;

- if (strict_strtoul(buf, 0, &value))
- return -EINVAL;
+ rv = kstrtou32(buf, 0, &value);
+ if (rv < 0)
+ return rv;

mutex_lock(&chip->mutex);
old_calib = chip->lux_calib;
@@ -1012,8 +1026,9 @@ static ssize_t bh1770_set_lux_rate(struct device *dev,
unsigned long rate_hz;
int ret, i;

- if (strict_strtoul(buf, 0, &rate_hz))
- return -EINVAL;
+ ret = kstrtoul(buf, 0, &rate_hz);
+ if (ret < 0)
+ return ret;

for (i = 0; i < ARRAY_SIZE(lux_rates_hz) - 1; i++)
if (rate_hz >= lux_rates_hz[i])
@@ -1047,11 +1062,12 @@ static ssize_t bh1770_get_lux_thresh_below(struct device *dev,
static ssize_t bh1770_set_lux_thresh(struct bh1770_chip *chip, u16 *target,
const char *buf)
{
- int ret = 0;
unsigned long thresh;
+ int ret;

- if (strict_strtoul(buf, 0, &thresh))
- return -EINVAL;
+ ret = kstrtoul(buf, 0, &thresh);
+ if (ret < 0)
+ return ret;

if (thresh > BH1770_LUX_RANGE)
return -EINVAL;
diff --git a/drivers/misc/bh1780gli.c b/drivers/misc/bh1780gli.c
index d5f3a3f..5faca8e 100644
--- a/drivers/misc/bh1780gli.c
+++ b/drivers/misc/bh1780gli.c
@@ -103,10 +103,10 @@ static ssize_t bh1780_store_power_state(struct device *dev,
{
struct platform_device *pdev = to_platform_device(dev);
struct bh1780_data *ddata = platform_get_drvdata(pdev);
- unsigned long val;
+ int val;
int error;

- error = strict_strtoul(buf, 0, &val);
+ error = kstrtoint(buf, 0, &val);
if (error)
return error;

diff --git a/drivers/misc/bmp085.c b/drivers/misc/bmp085.c
index 63ee4c1..b656c36 100644
--- a/drivers/misc/bmp085.c
+++ b/drivers/misc/bmp085.c
@@ -86,7 +86,7 @@ struct bmp085_data {
struct bmp085_calibration_data calibration;
u32 raw_temperature;
u32 raw_pressure;
- unsigned char oversampling_setting;
+ u8 oversampling_setting; /* [0, 3] */
u32 last_temp_measurement;
s32 b6; /* calculated temperature correction coefficient */
};
@@ -284,22 +284,13 @@ exit:
* increase both. The datasheet gives on overview on how measurement time,
* accuracy and noise correlate.
*/
-static void bmp085_set_oversampling(struct bmp085_data *data,
- unsigned char oversampling)
+static void bmp085_set_oversampling(struct bmp085_data *data, u8 oversampling)
{
if (oversampling > 3)
oversampling = 3;
data->oversampling_setting = oversampling;
}

-/*
- * Returns the currently selected oversampling. Range: 0..3
- */
-static unsigned char bmp085_get_oversampling(struct bmp085_data *data)
-{
- return data->oversampling_setting;
-}
-
/* sysfs callbacks */
static ssize_t set_oversampling(struct device *dev,
struct device_attribute *attr,
@@ -307,13 +298,14 @@ static ssize_t set_oversampling(struct device *dev,
{
struct i2c_client *client = to_i2c_client(dev);
struct bmp085_data *data = i2c_get_clientdata(client);
- unsigned long oversampling;
- int success = strict_strtoul(buf, 10, &oversampling);
- if (success == 0) {
- bmp085_set_oversampling(data, oversampling);
- return count;
- }
- return success;
+ u8 oversampling;
+ int rv;
+
+ rv = kstrtou8(buf, 10, &oversampling);
+ if (rv < 0)
+ return rv;
+ bmp085_set_oversampling(data, oversampling);
+ return count;
}

static ssize_t show_oversampling(struct device *dev,
@@ -321,7 +313,8 @@ static ssize_t show_oversampling(struct device *dev,
{
struct i2c_client *client = to_i2c_client(dev);
struct bmp085_data *data = i2c_get_clientdata(client);
- return sprintf(buf, "%u\n", bmp085_get_oversampling(data));
+
+ return sprintf(buf, "%hhu\n", data->oversampling_setting);
}
static DEVICE_ATTR(oversampling, S_IWUSR | S_IRUGO,
show_oversampling, set_oversampling);
diff --git a/drivers/misc/ep93xx_pwm.c b/drivers/misc/ep93xx_pwm.c
index 46b3439..b7a653e 100644
--- a/drivers/misc/ep93xx_pwm.c
+++ b/drivers/misc/ep93xx_pwm.c
@@ -149,9 +149,9 @@ static ssize_t ep93xx_pwm_set_freq(struct device *dev,
long val;
int err;

- err = strict_strtol(buf, 10, &val);
+ err = kstrtol(buf, 10, &val);
if (err)
- return -EINVAL;
+ return err;

if (val == 0) {
ep93xx_pwm_disable(pwm);
@@ -191,7 +191,7 @@ static ssize_t ep93xx_pwm_get_duty_percent(struct device *dev,
struct platform_device *pdev = to_platform_device(dev);
struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);

- return sprintf(buf, "%d\n", pwm->duty_percent);
+ return sprintf(buf, "%u\n", pwm->duty_percent);
}

static ssize_t ep93xx_pwm_set_duty_percent(struct device *dev,
@@ -199,21 +199,20 @@ static ssize_t ep93xx_pwm_set_duty_percent(struct device *dev,
{
struct platform_device *pdev = to_platform_device(dev);
struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
- long val;
+ u32 term;
+ unsigned int val;
int err;

- err = strict_strtol(buf, 10, &val);
- if (err)
+ err = kstrtouint(buf, 10, &val);
+ if (err < 0)
+ return err;
+ if (val >= 100)
return -EINVAL;

- if (val > 0 && val < 100) {
- u32 term = ep93xx_pwm_read_tc(pwm);
- ep93xx_pwm_write_dc(pwm, ((term + 1) * val / 100) - 1);
- pwm->duty_percent = val;
- return count;
- }
-
- return -EINVAL;
+ term = ep93xx_pwm_read_tc(pwm);
+ ep93xx_pwm_write_dc(pwm, ((term + 1) * val / 100) - 1);
+ pwm->duty_percent = val;
+ return count;
}

static ssize_t ep93xx_pwm_get_invert(struct device *dev,
@@ -230,12 +229,12 @@ static ssize_t ep93xx_pwm_set_invert(struct device *dev,
{
struct platform_device *pdev = to_platform_device(dev);
struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
- long val;
+ int val;
int err;

- err = strict_strtol(buf, 10, &val);
+ err = kstrtoint(buf, 10, &val);
if (err)
- return -EINVAL;
+ return err;

if (val == 0)
ep93xx_pwm_normal(pwm);
diff --git a/drivers/misc/hmc6352.c b/drivers/misc/hmc6352.c
index 234bfca..8503368 100644
--- a/drivers/misc/hmc6352.c
+++ b/drivers/misc/hmc6352.c
@@ -43,11 +43,12 @@ static int compass_store(struct device *dev, const char *buf, size_t count,
const char *map)
{
struct i2c_client *c = to_i2c_client(dev);
+ unsigned int val;
int ret;
- unsigned long val;

- if (strict_strtoul(buf, 10, &val))
- return -EINVAL;
+ ret = kstrtouint(buf, 10, &val);
+ if (ret < 0)
+ return ret;
if (val >= strlen(map))
return -EINVAL;
mutex_lock(&compass_mutex);
diff --git a/drivers/misc/isl29003.c b/drivers/misc/isl29003.c
index a71e245..f66cda4 100644
--- a/drivers/misc/isl29003.c
+++ b/drivers/misc/isl29003.c
@@ -205,10 +205,13 @@ static ssize_t isl29003_store_range(struct device *dev,
const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
- unsigned long val;
+ unsigned int val;
int ret;

- if ((strict_strtoul(buf, 10, &val) < 0) || (val > 3))
+ ret = kstrtouint(buf, 10, &val);
+ if (ret < 0)
+ return ret;
+ if (val > 3)
return -EINVAL;

ret = isl29003_set_range(client, val);
@@ -236,10 +239,13 @@ static ssize_t isl29003_store_resolution(struct device *dev,
const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
- unsigned long val;
+ unsigned int val;
int ret;

- if ((strict_strtoul(buf, 10, &val) < 0) || (val > 3))
+ ret = kstrtouint(buf, 10, &val);
+ if (ret < 0)
+ return ret;
+ if (val > 3)
return -EINVAL;

ret = isl29003_set_resolution(client, val);
@@ -264,10 +270,13 @@ static ssize_t isl29003_store_mode(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
- unsigned long val;
+ unsigned int val;
int ret;

- if ((strict_strtoul(buf, 10, &val) < 0) || (val > 2))
+ ret = kstrtouint(buf, 10, &val);
+ if (ret < 0)
+ return ret;
+ if (val > 2)
return -EINVAL;

ret = isl29003_set_mode(client, val);
@@ -295,10 +304,13 @@ static ssize_t isl29003_store_power_state(struct device *dev,
const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
- unsigned long val;
+ unsigned int val;
int ret;

- if ((strict_strtoul(buf, 10, &val) < 0) || (val > 1))
+ ret = kstrtouint(buf, 10, &val);
+ if (ret < 0)
+ return ret;
+ if (val > 1)
return -EINVAL;

ret = isl29003_set_power_state(client, val);
diff --git a/drivers/misc/isl29020.c b/drivers/misc/isl29020.c
index 307aada..4d63b37 100644
--- a/drivers/misc/isl29020.c
+++ b/drivers/misc/isl29020.c
@@ -87,11 +87,12 @@ static ssize_t als_sensing_range_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
+ unsigned int val;
int ret_val;
- unsigned long val;

- if (strict_strtoul(buf, 10, &val))
- return -EINVAL;
+ ret_val = kstrtouint(buf, 10, &val);
+ if (ret_val < 0)
+ return ret_val;
if (val < 1 || val > 64000)
return -EINVAL;

diff --git a/drivers/misc/iwmc3200top/log.c b/drivers/misc/iwmc3200top/log.c
index a36a55a..9df9391 100644
--- a/drivers/misc/iwmc3200top/log.c
+++ b/drivers/misc/iwmc3200top/log.c
@@ -169,7 +169,6 @@ int log_get_fw_filter_str(char *buf, int size)
return _log_get_filter_str(iwmct_fw_logdefs, FW_LOG_SRC_MAX, buf, size);
}

-#define HEXADECIMAL_RADIX 16
#define LOG_SRC_FORMAT 7 /* log level is in format of "0xXXXX," */

ssize_t show_iwmct_log_level(struct device *d,
@@ -206,40 +205,34 @@ ssize_t store_iwmct_log_level(struct device *d,
const char *buf, size_t count)
{
struct iwmct_priv *priv = dev_get_drvdata(d);
- char *token, *str_buf = NULL;
- long val;
- ssize_t ret = count;
- u8 src, mask;
+ char *token, *str_buf, *p;
+ int ret;

if (!count)
- goto exit;
+ return -EINVAL;

- str_buf = kzalloc(count, GFP_KERNEL);
+ p = str_buf = kstrdup(buf, GFP_KERNEL);
if (!str_buf) {
LOG_ERROR(priv, DEBUGFS,
"failed to allocate %zd bytes\n", count);
- ret = -ENOMEM;
- goto exit;
+ return -ENOMEM;
}

- memcpy(str_buf, buf, count);
+ while ((token = strsep(&p, ",")) != NULL) {
+ u16 val;

- while ((token = strsep(&str_buf, ",")) != NULL) {
while (isspace(*token))
++token;
- if (strict_strtol(token, HEXADECIMAL_RADIX, &val)) {
+ ret = kstrtou16(token, 16, &val);
+ if (ret < 0) {
LOG_ERROR(priv, DEBUGFS,
- "failed to convert string to long %s\n",
+ "invalid integer \"%s\"\n",
token);
- ret = -EINVAL;
goto exit;
}
-
- mask = val & 0xFF;
- src = (val & 0XFF00) >> 8;
- iwmct_log_set_filter(src, mask);
+ iwmct_log_set_filter(val >> 8, val & 0xFF);
}
-
+ ret = count;
exit:
kfree(str_buf);
return ret;
@@ -281,51 +274,50 @@ ssize_t store_iwmct_log_level_fw(struct device *d,
{
struct iwmct_priv *priv = dev_get_drvdata(d);
struct top_msg cmd;
- char *token, *str_buf = NULL;
- ssize_t ret = count;
+ char *token, *str_buf, *p;
u16 cmdlen = 0;
int i;
- long val;
- u8 src, mask;
+ int ret;

if (!count)
- goto exit;
+ return -EINVAL;

- str_buf = kzalloc(count, GFP_KERNEL);
+ p = str_buf = kstrdup(buf, GFP_KERNEL);
if (!str_buf) {
LOG_ERROR(priv, DEBUGFS,
"failed to allocate %zd bytes\n", count);
- ret = -ENOMEM;
- goto exit;
+ return -ENOMEM;
}

- memcpy(str_buf, buf, count);
-
cmd.hdr.type = COMM_TYPE_H2D;
cmd.hdr.category = COMM_CATEGORY_DEBUG;
cmd.hdr.opcode = CMD_DBG_LOG_LEVEL;

- for (i = 0; ((token = strsep(&str_buf, ",")) != NULL) &&
+ for (i = 0; ((token = strsep(&p, ",")) != NULL) &&
(i < FW_LOG_SRC_MAX); i++) {
+ u16 val;
+ u8 src, mask;

while (isspace(*token))
++token;

- if (strict_strtol(token, HEXADECIMAL_RADIX, &val)) {
+ ret = kstrtou16(token, 16, &val);
+ if (ret < 0) {
LOG_ERROR(priv, DEBUGFS,
"failed to convert string to long %s\n",
token);
- ret = -EINVAL;
- goto exit;
+ kfree(str_buf);
+ return ret;
}
+ src = val >> 8;
+ mask = val & 0xFF;

- mask = val & 0xFF; /* LSB */
- src = (val & 0XFF00) >> 8; /* 2nd least significant byte. */
iwmct_log_set_fw_filter(src, mask);

cmd.u.logdefs[i].logsource = src;
cmd.u.logdefs[i].sevmask = mask;
}
+ kfree(str_buf);

cmd.hdr.length = cpu_to_le16(i * sizeof(cmd.u.logdefs[0]));
cmdlen = (i * sizeof(cmd.u.logdefs[0]) + sizeof(cmd.hdr));
@@ -333,16 +325,12 @@ ssize_t store_iwmct_log_level_fw(struct device *d,
ret = iwmct_send_hcmd(priv, (u8 *)&cmd, cmdlen);
if (ret) {
LOG_ERROR(priv, DEBUGFS,
- "Failed to send %d bytes of fwcmd, ret=%zd\n",
+ "Failed to send %d bytes of fwcmd, ret=%d\n",
cmdlen, ret);
- goto exit;
- } else
- LOG_INFO(priv, DEBUGFS, "fwcmd sent (%d bytes)\n", cmdlen);
-
- ret = count;
+ return ret;
+ }
+ LOG_INFO(priv, DEBUGFS, "fwcmd sent (%d bytes)\n", cmdlen);

-exit:
- kfree(str_buf);
- return ret;
+ return count;
}

diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
index 7768b87..c29500c 100644
--- a/drivers/misc/sgi-gru/gruprocfs.c
+++ b/drivers/misc/sgi-gru/gruprocfs.c
@@ -161,15 +161,16 @@ static ssize_t options_write(struct file *file, const char __user *userbuf,
size_t count, loff_t *data)
{
char buf[20];
+ int rv;

if (count >= sizeof(buf))
return -EINVAL;
if (copy_from_user(buf, userbuf, count))
return -EFAULT;
buf[count] = '\0';
- if (strict_strtoul(buf, 0, &gru_options))
- return -EINVAL;
-
+ rv = kstrtoul(buf, 0, &gru_options);
+ if (rv < 0)
+ return rv;
return count;
}

diff --git a/drivers/misc/ti_dac7512.c b/drivers/misc/ti_dac7512.c
index d3f229a..ef9fd33 100644
--- a/drivers/misc/ti_dac7512.c
+++ b/drivers/misc/ti_dac7512.c
@@ -31,11 +31,13 @@ static ssize_t dac7512_store_val(struct device *dev,
const char *buf, size_t count)
{
struct spi_device *spi = to_spi_device(dev);
- unsigned char tmp[2];
- unsigned long val;
+ u8 tmp[2];
+ u16 val;
+ int rv;

- if (strict_strtoul(buf, 10, &val) < 0)
- return -EINVAL;
+ rv = kstrtou16(buf, 10, &val);
+ if (rv < 0)
+ return rv;

tmp[0] = val >> 8;
tmp[1] = val & 0xff;
--
1.7.2.2

2010-12-05 17:51:22

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 25/45] kstrtox: convert drivers/input/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/input/input-polldev.c | 8 ++-
drivers/input/keyboard/atkbd.c | 33 ++++++++++----
drivers/input/keyboard/lm8323.c | 20 ++++-----
drivers/input/misc/adxl34x.c | 14 +++---
drivers/input/misc/ati_remote2.c | 31 +++++++------
drivers/input/mouse/elantech.c | 10 +---
drivers/input/mouse/hgpk.c | 18 +++++---
drivers/input/mouse/logips2pp.c | 8 +++-
drivers/input/mouse/psmouse-base.c | 31 ++++++-------
drivers/input/mouse/sentelic.c | 79 ++++++++++++++++++----------------
drivers/input/mouse/sentelic.h | 10 ++--
drivers/input/mouse/trackpoint.c | 19 +++++----
drivers/input/tablet/aiptek.c | 34 +++++++--------
drivers/input/touchscreen/ad7877.c | 16 ++++----
drivers/input/touchscreen/ad7879.c | 4 +-
drivers/input/touchscreen/ads7846.c | 6 ++-
16 files changed, 182 insertions(+), 159 deletions(-)

diff --git a/drivers/input/input-polldev.c b/drivers/input/input-polldev.c
index 10c9b0a..9003ad1 100644
--- a/drivers/input/input-polldev.c
+++ b/drivers/input/input-polldev.c
@@ -129,10 +129,12 @@ static ssize_t input_polldev_set_poll(struct device *dev,
{
struct input_polled_dev *polldev = dev_get_drvdata(dev);
struct input_dev *input = polldev->input;
- unsigned long interval;
+ unsigned int interval;
+ int rv;

- if (strict_strtoul(buf, 0, &interval))
- return -EINVAL;
+ rv = kstrtouint(buf, 0, &interval);
+ if (rv < 0)
+ return rv;

if (interval < polldev->poll_interval_min)
return -EINVAL;
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index 11478eb..b01c7e7 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -1305,7 +1305,7 @@ static ssize_t atkbd_show_extra(struct atkbd *atkbd, char *buf)
static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t count)
{
struct input_dev *old_dev, *new_dev;
- unsigned long value;
+ unsigned int value;
int err;
bool old_extra;
unsigned char old_set;
@@ -1313,7 +1313,10 @@ static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t coun
if (!atkbd->write)
return -EIO;

- if (strict_strtoul(buf, 10, &value) || value > 1)
+ err = kstrtouint(buf, 10, &value);
+ if (err < 0)
+ return err;
+ if (value > 1)
return -EINVAL;

if (atkbd->extra != value) {
@@ -1389,11 +1392,14 @@ static ssize_t atkbd_show_scroll(struct atkbd *atkbd, char *buf)
static ssize_t atkbd_set_scroll(struct atkbd *atkbd, const char *buf, size_t count)
{
struct input_dev *old_dev, *new_dev;
- unsigned long value;
+ unsigned int value;
int err;
bool old_scroll;

- if (strict_strtoul(buf, 10, &value) || value > 1)
+ err = kstrtouint(buf, 10, &value);
+ if (err < 0)
+ return err;
+ if (value > 1)
return -EINVAL;

if (atkbd->scroll != value) {
@@ -1433,7 +1439,7 @@ static ssize_t atkbd_show_set(struct atkbd *atkbd, char *buf)
static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count)
{
struct input_dev *old_dev, *new_dev;
- unsigned long value;
+ int value;
int err;
unsigned char old_set;
bool old_extra;
@@ -1441,7 +1447,10 @@ static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count)
if (!atkbd->write)
return -EIO;

- if (strict_strtoul(buf, 10, &value) || (value != 2 && value != 3))
+ err = kstrtoint(buf, 10, &value);
+ if (err < 0)
+ return err;
+ if (value != 2 && value != 3)
return -EINVAL;

if (atkbd->set != value) {
@@ -1484,14 +1493,17 @@ static ssize_t atkbd_show_softrepeat(struct atkbd *atkbd, char *buf)
static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t count)
{
struct input_dev *old_dev, *new_dev;
- unsigned long value;
+ unsigned int value;
int err;
bool old_softrepeat, old_softraw;

if (!atkbd->write)
return -EIO;

- if (strict_strtoul(buf, 10, &value) || value > 1)
+ err = kstrtouint(buf, 10, &value);
+ if (err < 0)
+ return err;
+ if (value > 1)
return -EINVAL;

if (atkbd->softrepeat != value) {
@@ -1534,11 +1546,12 @@ static ssize_t atkbd_show_softraw(struct atkbd *atkbd, char *buf)
static ssize_t atkbd_set_softraw(struct atkbd *atkbd, const char *buf, size_t count)
{
struct input_dev *old_dev, *new_dev;
- unsigned long value;
+ unsigned int value;
int err;
bool old_softraw;

- if (strict_strtoul(buf, 10, &value) || value > 1)
+ err = kstrtouint(buf, 10, &value);
+ if (value > 1)
return -EINVAL;

if (atkbd->softraw != value) {
diff --git a/drivers/input/keyboard/lm8323.c b/drivers/input/keyboard/lm8323.c
index f7c2a16..79ca455 100644
--- a/drivers/input/keyboard/lm8323.c
+++ b/drivers/input/keyboard/lm8323.c
@@ -557,15 +557,10 @@ static ssize_t lm8323_pwm_store_time(struct device *dev,
struct led_classdev *led_cdev = dev_get_drvdata(dev);
struct lm8323_pwm *pwm = cdev_to_pwm(led_cdev);
int ret;
- unsigned long time;
-
- ret = strict_strtoul(buf, 10, &time);
- /* Numbers only, please. */
- if (ret)
- return -EINVAL;
-
- pwm->fade_time = time;

+ ret = kstrtoint(buf, 10, &pwm->fade_time);
+ if (ret < 0)
+ return ret;
return strlen(buf);
}
static DEVICE_ATTR(time, 0644, lm8323_pwm_show_time, lm8323_pwm_store_time);
@@ -623,13 +618,14 @@ static ssize_t lm8323_set_disable(struct device *dev,
const char *buf, size_t count)
{
struct lm8323_chip *lm = dev_get_drvdata(dev);
+ unsigned int kp_enabled;
int ret;
- unsigned long i;
-
- ret = strict_strtoul(buf, 10, &i);

+ ret = kstrtouint(buf, 10, &kp_enabled);
+ if (ret < 0)
+ return ret;
mutex_lock(&lm->lock);
- lm->kp_enabled = !i;
+ lm->kp_enabled = !kp_enabled;
mutex_unlock(&lm->lock);

return count;
diff --git a/drivers/input/misc/adxl34x.c b/drivers/input/misc/adxl34x.c
index de5900d..03b284a 100644
--- a/drivers/input/misc/adxl34x.c
+++ b/drivers/input/misc/adxl34x.c
@@ -454,8 +454,8 @@ static ssize_t adxl34x_disable_store(struct device *dev,
unsigned long val;
int error;

- error = strict_strtoul(buf, 10, &val);
- if (error)
+ error = kstrtoul(buf, 10, &val);
+ if (error < 0)
return error;

mutex_lock(&ac->mutex);
@@ -543,7 +543,7 @@ static ssize_t adxl34x_rate_store(struct device *dev,
unsigned long val;
int error;

- error = strict_strtoul(buf, 10, &val);
+ error = kstrtoul(buf, 10, &val);
if (error)
return error;

@@ -578,7 +578,7 @@ static ssize_t adxl34x_autosleep_store(struct device *dev,
unsigned long val;
int error;

- error = strict_strtoul(buf, 10, &val);
+ error = kstrtoul(buf, 10, &val);
if (error)
return error;

@@ -622,13 +622,13 @@ static ssize_t adxl34x_write_store(struct device *dev,
const char *buf, size_t count)
{
struct adxl34x *ac = dev_get_drvdata(dev);
- unsigned long val;
+ u16 val;
int error;

/*
* This allows basic ADXL register write access for debug purposes.
*/
- error = strict_strtoul(buf, 16, &val);
+ error = kstrtou16(buf, 16, &val);
if (error)
return error;

@@ -639,7 +639,7 @@ static ssize_t adxl34x_write_store(struct device *dev,
return count;
}

-static DEVICE_ATTR(write, 0664, NULL, adxl34x_write_store);
+static DEVICE_ATTR(write, 0220, NULL, adxl34x_write_store);
#endif

static struct attribute *adxl34x_attributes[] = {
diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c
index 0b0e9be..3226c9a 100644
--- a/drivers/input/misc/ati_remote2.c
+++ b/drivers/input/misc/ati_remote2.c
@@ -41,14 +41,14 @@ static int ati_remote2_set_mask(const char *val,
const struct kernel_param *kp,
unsigned int max)
{
- unsigned long mask;
+ unsigned int mask;
int ret;

if (!val)
return -EINVAL;

- ret = strict_strtoul(val, 0, &mask);
- if (ret)
+ ret = kstrtouint(val, 0, &mask);
+ if (ret < 0)
return ret;

if (mask & ~max)
@@ -719,20 +719,21 @@ static ssize_t ati_remote2_store_channel_mask(struct device *dev,
struct usb_device *udev = to_usb_device(dev);
struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
struct ati_remote2 *ar2 = usb_get_intfdata(intf);
- unsigned long mask;
- int r;
+ unsigned int mask;
+ int rv;

- if (strict_strtoul(buf, 0, &mask))
- return -EINVAL;
+ rv = kstrtouint(buf, 0, &mask);
+ if (rv < 0)
+ return rv;

if (mask & ~ATI_REMOTE2_MAX_CHANNEL_MASK)
return -EINVAL;

- r = usb_autopm_get_interface(ar2->intf[0]);
- if (r) {
+ rv = usb_autopm_get_interface(ar2->intf[0]);
+ if (rv) {
dev_err(&ar2->intf[0]->dev,
- "%s(): usb_autopm_get_interface() = %d\n", __func__, r);
- return r;
+ "%s(): usb_autopm_get_interface() = %d\n", __func__, rv);
+ return rv;
}

mutex_lock(&ati_remote2_mutex);
@@ -765,10 +766,12 @@ static ssize_t ati_remote2_store_mode_mask(struct device *dev,
struct usb_device *udev = to_usb_device(dev);
struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
struct ati_remote2 *ar2 = usb_get_intfdata(intf);
- unsigned long mask;
+ unsigned int mask;
+ int rv;

- if (strict_strtoul(buf, 0, &mask))
- return -EINVAL;
+ rv = kstrtouint(buf, 0, &mask);
+ if (rv < 0)
+ return rv;

if (mask & ~ATI_REMOTE2_MAX_MODE_MASK)
return -EINVAL;
diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
index 04d9bf3..b3c788b 100644
--- a/drivers/input/mouse/elantech.c
+++ b/drivers/input/mouse/elantech.c
@@ -517,16 +517,12 @@ static ssize_t elantech_set_int_attr(struct psmouse *psmouse,
struct elantech_data *etd = psmouse->private;
struct elantech_attr_data *attr = data;
unsigned char *reg = (unsigned char *) etd + attr->field_offset;
- unsigned long value;
+ u8 value;
int err;

- err = strict_strtoul(buf, 16, &value);
- if (err)
+ err = kstrtou8(buf, 16, &value);
+ if (err < 0)
return err;
-
- if (value > 0xff)
- return -EINVAL;
-
/* Do we need to preserve some bits for version 2 hardware too? */
if (etd->hw_version == 1) {
if (attr->reg == 0x10)
diff --git a/drivers/input/mouse/hgpk.c b/drivers/input/mouse/hgpk.c
index 1d2205b..aea82af 100644
--- a/drivers/input/mouse/hgpk.c
+++ b/drivers/input/mouse/hgpk.c
@@ -343,11 +343,13 @@ static ssize_t hgpk_set_powered(struct psmouse *psmouse, void *data,
const char *buf, size_t count)
{
struct hgpk_data *priv = psmouse->private;
- unsigned long value;
+ unsigned int value;
int err;

- err = strict_strtoul(buf, 10, &value);
- if (err || value > 1)
+ err = kstrtouint(buf, 10, &value);
+ if (err < 0)
+ return err;
+ if (value > 1)
return -EINVAL;

if (value != priv->powered) {
@@ -376,11 +378,13 @@ static ssize_t hgpk_trigger_recal(struct psmouse *psmouse, void *data,
const char *buf, size_t count)
{
struct hgpk_data *priv = psmouse->private;
- unsigned long value;
+ unsigned int value;
int err;

- err = strict_strtoul(buf, 10, &value);
- if (err || value != 1)
+ err = kstrtouint(buf, 10, &value);
+ if (err < 0)
+ return err;
+ if (value != 1)
return -EINVAL;

/*
@@ -392,7 +396,7 @@ static ssize_t hgpk_trigger_recal(struct psmouse *psmouse, void *data,
return count;
}

-__PSMOUSE_DEFINE_ATTR(recalibrate, S_IWUSR | S_IRUGO, NULL,
+__PSMOUSE_DEFINE_ATTR(recalibrate, S_IWUSR, NULL,
hgpk_trigger_recal_show, hgpk_trigger_recal, false);

static void hgpk_disconnect(struct psmouse *psmouse)
diff --git a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
index c9983ae..c977ea9 100644
--- a/drivers/input/mouse/logips2pp.c
+++ b/drivers/input/mouse/logips2pp.c
@@ -155,9 +155,13 @@ static ssize_t ps2pp_attr_show_smartscroll(struct psmouse *psmouse,
static ssize_t ps2pp_attr_set_smartscroll(struct psmouse *psmouse, void *data,
const char *buf, size_t count)
{
- unsigned long value;
+ unsigned int value;
+ int rv;

- if (strict_strtoul(buf, 10, &value) || value > 1)
+ rv = kstrtouint(buf, 10, &value);
+ if (rv < 0)
+ return rv;
+ if (value > 1)
return -EINVAL;

ps2pp_set_smartscroll(psmouse, value);
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index cd9d0c9..a53978c 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -1546,16 +1546,11 @@ static ssize_t psmouse_show_int_attr(struct psmouse *psmouse, void *offset, char
static ssize_t psmouse_set_int_attr(struct psmouse *psmouse, void *offset, const char *buf, size_t count)
{
unsigned int *field = (unsigned int *)((char *)psmouse + (size_t)offset);
- unsigned long value;
-
- if (strict_strtoul(buf, 10, &value))
- return -EINVAL;
-
- if ((unsigned int)value != value)
- return -EINVAL;
-
- *field = value;
+ int rv;

+ rv = kstrtouint(buf, 10, field);
+ if (rv < 0)
+ return rv;
return count;
}

@@ -1660,22 +1655,24 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co

static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, void *data, const char *buf, size_t count)
{
- unsigned long value;
-
- if (strict_strtoul(buf, 10, &value))
- return -EINVAL;
+ unsigned int value;
+ int rv;

+ rv = kstrtouint(buf, 10, &value);
+ if (rv < 0)
+ return rv;
psmouse->set_rate(psmouse, value);
return count;
}

static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, void *data, const char *buf, size_t count)
{
- unsigned long value;
-
- if (strict_strtoul(buf, 10, &value))
- return -EINVAL;
+ unsigned int value;
+ int rv;

+ rv = kstrtouint(buf, 10, &value);
+ if (rv < 0)
+ return rv;
psmouse->set_resolution(psmouse, value);
return count;
}
diff --git a/drivers/input/mouse/sentelic.c b/drivers/input/mouse/sentelic.c
index 1242775..baaa141 100644
--- a/drivers/input/mouse/sentelic.c
+++ b/drivers/input/mouse/sentelic.c
@@ -78,7 +78,7 @@ static unsigned char fsp_test_invert_cmd(unsigned char reg_val)
}
}

-static int fsp_reg_read(struct psmouse *psmouse, int reg_addr, int *reg_val)
+static int fsp_reg_read(struct psmouse *psmouse, u8 reg_addr, u8 *reg_val)
{
struct ps2dev *ps2dev = &psmouse->ps2dev;
unsigned char param[3];
@@ -136,7 +136,7 @@ static int fsp_reg_read(struct psmouse *psmouse, int reg_addr, int *reg_val)
return rc;
}

-static int fsp_reg_write(struct psmouse *psmouse, int reg_addr, int reg_val)
+static int fsp_reg_write(struct psmouse *psmouse, u8 reg_addr, u8 reg_val)
{
struct ps2dev *ps2dev = &psmouse->ps2dev;
unsigned char v;
@@ -190,7 +190,7 @@ static int fsp_reg_write(struct psmouse *psmouse, int reg_addr, int reg_val)
/* Enable register clock gating for writing certain registers */
static int fsp_reg_write_enable(struct psmouse *psmouse, bool enable)
{
- int v, nv;
+ u8 v, nv;

if (fsp_reg_read(psmouse, FSP_REG_SYSCTL1, &v) == -1)
return -1;
@@ -284,7 +284,7 @@ static int fsp_page_reg_write(struct psmouse *psmouse, int reg_val)
return rc;
}

-static int fsp_get_version(struct psmouse *psmouse, int *version)
+static int fsp_get_version(struct psmouse *psmouse, u8 *version)
{
if (fsp_reg_read(psmouse, FSP_REG_VERSION, version))
return -EIO;
@@ -292,7 +292,7 @@ static int fsp_get_version(struct psmouse *psmouse, int *version)
return 0;
}

-static int fsp_get_revision(struct psmouse *psmouse, int *rev)
+static int fsp_get_revision(struct psmouse *psmouse, u8 *rev)
{
if (fsp_reg_read(psmouse, FSP_REG_REVISION, rev))
return -EIO;
@@ -300,7 +300,7 @@ static int fsp_get_revision(struct psmouse *psmouse, int *rev)
return 0;
}

-static int fsp_get_buttons(struct psmouse *psmouse, int *btn)
+static int fsp_get_buttons(struct psmouse *psmouse, u8 *btn)
{
static const int buttons[] = {
0x16, /* Left/Middle/Right/Forward/Backward & Scroll Up/Down */
@@ -308,7 +308,7 @@ static int fsp_get_buttons(struct psmouse *psmouse, int *btn)
0x04, /* Left/Middle/Right & Scroll Up/Down */
0x02, /* Left/Middle/Right */
};
- int val;
+ u8 val;

if (fsp_reg_read(psmouse, FSP_REG_TMOD_STATUS1, &val) == -1)
return -EIO;
@@ -320,7 +320,7 @@ static int fsp_get_buttons(struct psmouse *psmouse, int *btn)
/* Enable on-pad command tag output */
static int fsp_opc_tag_enable(struct psmouse *psmouse, bool enable)
{
- int v, nv;
+ u8 v, nv;
int res = 0;

if (fsp_reg_read(psmouse, FSP_REG_OPC_QDOWN, &v) == -1) {
@@ -352,7 +352,7 @@ static int fsp_opc_tag_enable(struct psmouse *psmouse, bool enable)
static int fsp_onpad_vscr(struct psmouse *psmouse, bool enable)
{
struct fsp_data *pad = psmouse->private;
- int val;
+ u8 val;

if (fsp_reg_read(psmouse, FSP_REG_ONPAD_CTL, &val))
return -EIO;
@@ -373,7 +373,7 @@ static int fsp_onpad_vscr(struct psmouse *psmouse, bool enable)
static int fsp_onpad_hscr(struct psmouse *psmouse, bool enable)
{
struct fsp_data *pad = psmouse->private;
- int val, v2;
+ u8 val, v2;

if (fsp_reg_read(psmouse, FSP_REG_ONPAD_CTL, &val))
return -EIO;
@@ -409,24 +409,18 @@ static int fsp_onpad_hscr(struct psmouse *psmouse, bool enable)
static ssize_t fsp_attr_set_setreg(struct psmouse *psmouse, void *data,
const char *buf, size_t count)
{
- unsigned long reg, val;
- char *rest;
- ssize_t retval;
+ u8 reg, val;
+ int rv;

- reg = simple_strtoul(buf, &rest, 16);
- if (rest == buf || *rest != ' ' || reg > 0xff)
- return -EINVAL;
-
- if (strict_strtoul(rest + 1, 16, &val) || val > 0xff)
+ if (sscanf(buf, "%hhu %hhu", &reg, &val) != 2)
return -EINVAL;

if (fsp_reg_write_enable(psmouse, true))
return -EIO;
-
- retval = fsp_reg_write(psmouse, reg, val) < 0 ? -EIO : count;
-
+ rv = fsp_reg_write(psmouse, reg, val);
fsp_reg_write_enable(psmouse, false);
-
+ if (rv < 0)
+ return -EIO;
return count;
}

@@ -449,11 +443,12 @@ static ssize_t fsp_attr_set_getreg(struct psmouse *psmouse, void *data,
const char *buf, size_t count)
{
struct fsp_data *pad = psmouse->private;
- unsigned long reg;
- int val;
+ u8 reg, val;
+ int rv;

- if (strict_strtoul(buf, 16, &reg) || reg > 0xff)
- return -EINVAL;
+ rv = kstrtou8(buf, 16, &reg);
+ if (rv < 0)
+ return rv;

if (fsp_reg_read(psmouse, reg, &val))
return -EIO;
@@ -481,10 +476,12 @@ static ssize_t fsp_attr_show_pagereg(struct psmouse *psmouse,
static ssize_t fsp_attr_set_pagereg(struct psmouse *psmouse, void *data,
const char *buf, size_t count)
{
- unsigned long val;
+ u8 val;
+ int rv;

- if (strict_strtoul(buf, 16, &val) || val > 0xff)
- return -EINVAL;
+ rv = kstrtou8(buf, 16, &val);
+ if (rv < 0)
+ return rv;

if (fsp_page_reg_write(psmouse, val))
return -EIO;
@@ -506,9 +503,13 @@ static ssize_t fsp_attr_show_vscroll(struct psmouse *psmouse,
static ssize_t fsp_attr_set_vscroll(struct psmouse *psmouse, void *data,
const char *buf, size_t count)
{
- unsigned long val;
+ unsigned int val;
+ int rv;

- if (strict_strtoul(buf, 10, &val) || val > 1)
+ rv = kstrtouint(buf, 10, &val);
+ if (rv < 0)
+ return rv;
+ if (val > 1)
return -EINVAL;

fsp_onpad_vscr(psmouse, val);
@@ -530,9 +531,13 @@ static ssize_t fsp_attr_show_hscroll(struct psmouse *psmouse,
static ssize_t fsp_attr_set_hscroll(struct psmouse *psmouse, void *data,
const char *buf, size_t count)
{
- unsigned long val;
+ unsigned int val;
+ int rv;

- if (strict_strtoul(buf, 10, &val) || val > 1)
+ rv = kstrtouint(buf, 10, &val);
+ if (rv < 0)
+ return rv;
+ if (val > 1)
return -EINVAL;

fsp_onpad_hscr(psmouse, val);
@@ -704,7 +709,7 @@ static int fsp_activate_protocol(struct psmouse *psmouse)
struct fsp_data *pad = psmouse->private;
struct ps2dev *ps2dev = &psmouse->ps2dev;
unsigned char param[2];
- int val;
+ u8 val;

/*
* Standard procedure to enter FSP Intellimouse mode
@@ -761,7 +766,7 @@ static int fsp_activate_protocol(struct psmouse *psmouse)

int fsp_detect(struct psmouse *psmouse, bool set_properties)
{
- int id;
+ u8 id;

if (fsp_reg_read(psmouse, FSP_REG_DEVICE_ID, &id))
return -EIO;
@@ -795,7 +800,7 @@ static void fsp_disconnect(struct psmouse *psmouse)

static int fsp_reconnect(struct psmouse *psmouse)
{
- int version;
+ u8 version;

if (fsp_detect(psmouse, 0))
return -ENODEV;
@@ -812,7 +817,7 @@ static int fsp_reconnect(struct psmouse *psmouse)
int fsp_init(struct psmouse *psmouse)
{
struct fsp_data *priv;
- int ver, rev, buttons;
+ u8 ver, rev, buttons;
int error;

if (fsp_get_version(psmouse, &ver) ||
diff --git a/drivers/input/mouse/sentelic.h b/drivers/input/mouse/sentelic.h
index ed1395a..363df999 100644
--- a/drivers/input/mouse/sentelic.h
+++ b/drivers/input/mouse/sentelic.h
@@ -66,17 +66,17 @@
#ifdef __KERNEL__

struct fsp_data {
- unsigned char ver; /* hardware version */
- unsigned char rev; /* hardware revison */
- unsigned char buttons; /* Number of buttons */
+ u8 ver; /* hardware version */
+ u8 rev; /* hardware revison */
+ u8 buttons; /* Number of buttons */
unsigned int flags;
#define FSPDRV_FLAG_EN_OPC (0x001) /* enable on-pad clicking */

bool vscroll; /* Vertical scroll zone enabled */
bool hscroll; /* Horizontal scroll zone enabled */

- unsigned char last_reg; /* Last register we requested read from */
- unsigned char last_val;
+ u8 last_reg; /* Last register we requested read from */
+ u8 last_val;
};

#ifdef CONFIG_MOUSE_PS2_SENTELIC
diff --git a/drivers/input/mouse/trackpoint.c b/drivers/input/mouse/trackpoint.c
index 54b2fa8..daf74c4 100644
--- a/drivers/input/mouse/trackpoint.c
+++ b/drivers/input/mouse/trackpoint.c
@@ -89,13 +89,12 @@ static ssize_t trackpoint_set_int_attr(struct psmouse *psmouse, void *data,
struct trackpoint_data *tp = psmouse->private;
struct trackpoint_attr_data *attr = data;
unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset);
- unsigned long value;
+ int rv;

- if (strict_strtoul(buf, 10, &value) || value > 255)
- return -EINVAL;
-
- *field = value;
- trackpoint_write(&psmouse->ps2dev, attr->command, value);
+ rv = kstrtou8(buf, 10, field);
+ if (rv < 0)
+ return rv;
+ trackpoint_write(&psmouse->ps2dev, attr->command, *field);

return count;
}
@@ -115,9 +114,13 @@ static ssize_t trackpoint_set_bit_attr(struct psmouse *psmouse, void *data,
struct trackpoint_data *tp = psmouse->private;
struct trackpoint_attr_data *attr = data;
unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset);
- unsigned long value;
+ u8 value;
+ int rv;

- if (strict_strtoul(buf, 10, &value) || value > 1)
+ rv = kstrtou8(buf, 10, &value);
+ if (rv < 0)
+ return rv;
+ if (value > 1)
return -EINVAL;

if (attr->inverted)
diff --git a/drivers/input/tablet/aiptek.c b/drivers/input/tablet/aiptek.c
index 0a619c5..6fb2ac2 100644
--- a/drivers/input/tablet/aiptek.c
+++ b/drivers/input/tablet/aiptek.c
@@ -1199,9 +1199,9 @@ static ssize_t
store_tabletXtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct aiptek *aiptek = dev_get_drvdata(dev);
- long x;
+ int x;

- if (strict_strtol(buf, 10, &x)) {
+ if (kstrtoint(buf, 10, &x)) {
size_t len = buf[count - 1] == '\n' ? count - 1 : count;

if (strncmp(buf, "disable", len))
@@ -1241,9 +1241,9 @@ static ssize_t
store_tabletYtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct aiptek *aiptek = dev_get_drvdata(dev);
- long y;
+ int y;

- if (strict_strtol(buf, 10, &y)) {
+ if (kstrtoint(buf, 10, &y)) {
size_t len = buf[count - 1] == '\n' ? count - 1 : count;

if (strncmp(buf, "disable", len))
@@ -1278,12 +1278,11 @@ static ssize_t
store_tabletJitterDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct aiptek *aiptek = dev_get_drvdata(dev);
- long j;
+ int rv;

- if (strict_strtol(buf, 10, &j))
- return -EINVAL;
-
- aiptek->newSetting.jitterDelay = (int)j;
+ rv = kstrtoint(buf, 10, &aiptek->newSetting.jitterDelay);
+ if (rv < 0)
+ return rv;
return count;
}

@@ -1307,12 +1306,11 @@ static ssize_t
store_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct aiptek *aiptek = dev_get_drvdata(dev);
- long d;
+ int rv;

- if (strict_strtol(buf, 10, &d))
- return -EINVAL;
-
- aiptek->newSetting.programmableDelay = (int)d;
+ rv = kstrtoint(buf, 10, &aiptek->newSetting.programmableDelay);
+ if (rv < 0)
+ return rv;
return count;
}

@@ -1558,11 +1556,11 @@ static ssize_t
store_tabletWheel(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct aiptek *aiptek = dev_get_drvdata(dev);
- long w;
-
- if (strict_strtol(buf, 10, &w)) return -EINVAL;
+ int rv;

- aiptek->newSetting.wheel = (int)w;
+ rv = kstrtoint(buf, 10, &aiptek->newSetting.wheel);
+ if (rv < 0)
+ return rv;
return count;
}

diff --git a/drivers/input/touchscreen/ad7877.c b/drivers/input/touchscreen/ad7877.c
index a1952fc..dac8711 100644
--- a/drivers/input/touchscreen/ad7877.c
+++ b/drivers/input/touchscreen/ad7877.c
@@ -489,8 +489,8 @@ static ssize_t ad7877_disable_store(struct device *dev,
unsigned long val;
int error;

- error = strict_strtoul(buf, 10, &val);
- if (error)
+ error = kstrtoul(buf, 10, &val);
+ if (error < 0)
return error;

if (val)
@@ -519,8 +519,8 @@ static ssize_t ad7877_dac_store(struct device *dev,
unsigned long val;
int error;

- error = strict_strtoul(buf, 10, &val);
- if (error)
+ error = kstrtoul(buf, 10, &val);
+ if (error < 0)
return error;

mutex_lock(&ts->mutex);
@@ -549,8 +549,8 @@ static ssize_t ad7877_gpio3_store(struct device *dev,
unsigned long val;
int error;

- error = strict_strtoul(buf, 10, &val);
- if (error)
+ error = kstrtoul(buf, 10, &val);
+ if (error < 0)
return error;

mutex_lock(&ts->mutex);
@@ -580,8 +580,8 @@ static ssize_t ad7877_gpio4_store(struct device *dev,
unsigned long val;
int error;

- error = strict_strtoul(buf, 10, &val);
- if (error)
+ error = kstrtoul(buf, 10, &val);
+ if (error < 0)
return error;

mutex_lock(&ts->mutex);
diff --git a/drivers/input/touchscreen/ad7879.c b/drivers/input/touchscreen/ad7879.c
index bc3b518..d3e0b9c 100644
--- a/drivers/input/touchscreen/ad7879.c
+++ b/drivers/input/touchscreen/ad7879.c
@@ -340,8 +340,8 @@ static ssize_t ad7879_disable_store(struct device *dev,
unsigned long val;
int error;

- error = strict_strtoul(buf, 10, &val);
- if (error)
+ error = kstrtoul(buf, 10, &val);
+ if (error < 0)
return error;

ad7879_toggle(ts, val);
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index 14ea54b..3a02113 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -590,9 +590,11 @@ static ssize_t ads7846_disable_store(struct device *dev,
{
struct ads7846 *ts = dev_get_drvdata(dev);
unsigned long i;
+ int rv;

- if (strict_strtoul(buf, 10, &i))
- return -EINVAL;
+ rv = kstrtoul(buf, 10, &i);
+ if (rv < 0)
+ return rv;

if (i)
ads7846_disable(ts);
--
1.7.2.2

2010-12-05 17:55:35

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 27/45] kstrtox: convert drivers/leds/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/leds/leds-bd2802.c | 10 +++++-----
drivers/leds/leds-lp5521.c | 9 +++++----
drivers/leds/leds-lp5523.c | 11 ++++++-----
drivers/leds/leds-netxbig.c | 2 +-
drivers/leds/leds-ns2.c | 2 +-
drivers/leds/leds-ss4200.c | 4 ++--
6 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/drivers/leds/leds-bd2802.c b/drivers/leds/leds-bd2802.c
index 19dc4b6..4248173 100644
--- a/drivers/leds/leds-bd2802.c
+++ b/drivers/leds/leds-bd2802.c
@@ -338,15 +338,15 @@ static ssize_t bd2802_store_reg##reg_addr(struct device *dev, \
struct device_attribute *attr, const char *buf, size_t count) \
{ \
struct bd2802_led *led = i2c_get_clientdata(to_i2c_client(dev));\
- unsigned long val; \
+ u8 val; \
int ret; \
if (!count) \
return -EINVAL; \
- ret = strict_strtoul(buf, 16, &val); \
+ ret = kstrtou8(buf, 16, &val); \
if (ret) \
return ret; \
down_write(&led->rwsem); \
- bd2802_write_byte(led->client, reg_addr, (u8) val); \
+ bd2802_write_byte(led->client, reg_addr, val); \
up_write(&led->rwsem); \
return count; \
} \
@@ -502,11 +502,11 @@ static ssize_t bd2802_store_##attr_name(struct device *dev, \
struct device_attribute *attr, const char *buf, size_t count) \
{ \
struct bd2802_led *led = i2c_get_clientdata(to_i2c_client(dev));\
- unsigned long val; \
+ unsigned int val; \
int ret; \
if (!count) \
return -EINVAL; \
- ret = strict_strtoul(buf, 16, &val); \
+ ret = kstrtouint(buf, 16, &val); \
if (ret) \
return ret; \
down_write(&led->rwsem); \
diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c
index 33facd0..1a3c43d 100644
--- a/drivers/leds/leds-lp5521.c
+++ b/drivers/leds/leds-lp5521.c
@@ -508,11 +508,12 @@ static ssize_t store_current(struct device *dev,
struct led_classdev *led_cdev = dev_get_drvdata(dev);
struct lp5521_led *led = cdev_to_led(led_cdev);
struct lp5521_chip *chip = led_to_lp5521(led);
- ssize_t ret;
- unsigned long curr;
+ u8 curr;
+ int ret;

- if (strict_strtoul(buf, 0, &curr))
- return -EINVAL;
+ ret = kstrtou8(buf, 0, &curr);
+ if (ret < 0)
+ return ret;

if (curr > led->max_current)
return -EINVAL;
diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c
index 0cc4ead..c21ee86 100644
--- a/drivers/leds/leds-lp5523.c
+++ b/drivers/leds/leds-lp5523.c
@@ -677,11 +677,12 @@ static ssize_t store_current(struct device *dev,
struct led_classdev *led_cdev = dev_get_drvdata(dev);
struct lp5523_led *led = cdev_to_led(led_cdev);
struct lp5523_chip *chip = led_to_lp5523(led);
- ssize_t ret;
- unsigned long curr;
+ u8 curr;
+ int ret;

- if (strict_strtoul(buf, 0, &curr))
- return -EINVAL;
+ ret = kstrtou8(buf, 0, &curr);
+ if (ret < 0)
+ return ret;

if (curr > led->max_current)
return -EINVAL;
@@ -689,7 +690,7 @@ static ssize_t store_current(struct device *dev,
mutex_lock(&chip->lock);
ret = lp5523_write(chip->client,
LP5523_REG_LED_CURRENT_BASE + led->chan_nr,
- (u8)curr);
+ curr);
mutex_unlock(&chip->lock);

if (ret < 0)
diff --git a/drivers/leds/leds-netxbig.c b/drivers/leds/leds-netxbig.c
index f2e51c1..b149f30 100644
--- a/drivers/leds/leds-netxbig.c
+++ b/drivers/leds/leds-netxbig.c
@@ -255,7 +255,7 @@ static ssize_t netxbig_led_sata_store(struct device *dev,
int mode_val;
int ret;

- ret = strict_strtoul(buff, 10, &enable);
+ ret = kstrtoul(buff, 10, &enable);
if (ret < 0)
return ret;

diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index f77d48d..4027583 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -148,7 +148,7 @@ static ssize_t ns2_led_sata_store(struct device *dev,
unsigned long enable;
enum ns2_led_modes mode;

- ret = strict_strtoul(buff, 10, &enable);
+ ret = kstrtoul(buff, 10, &enable);
if (ret < 0)
return ret;

diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
index 614ebeb..56b3ab8 100644
--- a/drivers/leds/leds-ss4200.c
+++ b/drivers/leds/leds-ss4200.c
@@ -457,9 +457,9 @@ static ssize_t nas_led_blink_store(struct device *dev,
{
int ret;
struct led_classdev *led = dev_get_drvdata(dev);
- unsigned long blink_state;
+ u32 blink_state;

- ret = strict_strtoul(buf, 10, &blink_state);
+ ret = kstrtou32(buf, 10, &blink_state);
if (ret)
return ret;

--
1.7.2.2

2010-12-05 17:55:59

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 24/45] kstrtox: convert drivers/infiniband/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/infiniband/hw/nes/nes.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
index 0c9f0aa..bae80e3 100644
--- a/drivers/infiniband/hw/nes/nes.c
+++ b/drivers/infiniband/hw/nes/nes.c
@@ -1107,12 +1107,15 @@ static ssize_t nes_show_wqm_quanta(struct device_driver *ddp, char *buf)
static ssize_t nes_store_wqm_quanta(struct device_driver *ddp,
const char *buf, size_t count)
{
- unsigned long wqm_quanta_value;
+ unsigned int wqm_quanta_value;
u32 wqm_config1;
u32 i = 0;
struct nes_device *nesdev;
+ int rv;

- strict_strtoul(buf, 0, &wqm_quanta_value);
+ rv = kstrtouint(buf, 0, &wqm_quanta_value);
+ if (rv < 0)
+ return rv;
list_for_each_entry(nesdev, &nes_dev_list, list) {
if (i == ee_flsh_adapter) {
nesdev->nesadapter->wqm_quanta = wqm_quanta_value;
--
1.7.2.2

2010-12-05 17:56:27

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 21/45] kstrtox: convert drivers/hid/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/hid/hid-magicmouse.c | 14 ++++++++--
drivers/hid/hid-ntrig.c | 54 ++++++++++++++++++++++------------------
drivers/hid/hid-roccat-kone.c | 8 +++---
3 files changed, 45 insertions(+), 31 deletions(-)

diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index e6dc151..5107ee5 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -32,9 +32,17 @@ module_param(emulate_scroll_wheel, bool, 0644);
MODULE_PARM_DESC(emulate_scroll_wheel, "Emulate a scroll wheel");

static unsigned int scroll_speed = 32;
-static int param_set_scroll_speed(const char *val, struct kernel_param *kp) {
- unsigned long speed;
- if (!val || strict_strtoul(val, 0, &speed) || speed > 63)
+static int param_set_scroll_speed(const char *val, struct kernel_param *kp)
+{
+ unsigned int speed;
+ int rv;
+
+ if (!val)
+ return -EINVAL;
+ rv = kstrtouint(val, 0, &speed);
+ if (rv < 0)
+ return rv;
+ if (speed > 63)
return -EINVAL;
scroll_speed = speed;
return 0;
diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
index 69169ef..6128531 100644
--- a/drivers/hid/hid-ntrig.c
+++ b/drivers/hid/hid-ntrig.c
@@ -206,11 +206,12 @@ static ssize_t set_min_width(struct device *dev,
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
struct ntrig_data *nd = hid_get_drvdata(hdev);

- unsigned long val;
-
- if (strict_strtoul(buf, 0, &val))
- return -EINVAL;
+ u16 val;
+ int rv;

+ rv = kstrtou16(buf, 0, &val);
+ if (rv < 0)
+ return rv;
if (val > nd->sensor_physical_width)
return -EINVAL;

@@ -241,11 +242,12 @@ static ssize_t set_min_height(struct device *dev,
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
struct ntrig_data *nd = hid_get_drvdata(hdev);

- unsigned long val;
-
- if (strict_strtoul(buf, 0, &val))
- return -EINVAL;
+ u16 val;
+ int rv;

+ rv = kstrtou16(buf, 0, &val);
+ if (rv < 0)
+ return rv;
if (val > nd->sensor_physical_height)
return -EINVAL;

@@ -275,11 +277,12 @@ static ssize_t set_activate_slack(struct device *dev,
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
struct ntrig_data *nd = hid_get_drvdata(hdev);

- unsigned long val;
-
- if (strict_strtoul(buf, 0, &val))
- return -EINVAL;
+ u8 val;
+ int rv;

+ rv = kstrtou8(buf, 0, &val);
+ if (rv < 0)
+ return rv;
if (val > 0x7f)
return -EINVAL;

@@ -310,11 +313,12 @@ static ssize_t set_activation_width(struct device *dev,
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
struct ntrig_data *nd = hid_get_drvdata(hdev);

- unsigned long val;
-
- if (strict_strtoul(buf, 0, &val))
- return -EINVAL;
+ u16 val;
+ int rv;

+ rv = kstrtou16(buf, 0, &val);
+ if (rv < 0)
+ return rv;
if (val > nd->sensor_physical_width)
return -EINVAL;

@@ -346,11 +350,12 @@ static ssize_t set_activation_height(struct device *dev,
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
struct ntrig_data *nd = hid_get_drvdata(hdev);

- unsigned long val;
-
- if (strict_strtoul(buf, 0, &val))
- return -EINVAL;
+ u16 val;
+ int rv;

+ rv = kstrtou16(buf, 0, &val);
+ if (rv < 0)
+ return rv;
if (val > nd->sensor_physical_height)
return -EINVAL;

@@ -380,11 +385,12 @@ static ssize_t set_deactivate_slack(struct device *dev,
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
struct ntrig_data *nd = hid_get_drvdata(hdev);

- unsigned long val;
-
- if (strict_strtoul(buf, 0, &val))
- return -EINVAL;
+ u8 val;
+ int rv;

+ rv = kstrtou8(buf, 0, &val);
+ if (rv < 0)
+ return rv;
/*
* No more than 8 terminal frames have been observed so far
* and higher slack is highly likely to leave the single
diff --git a/drivers/hid/hid-roccat-kone.c b/drivers/hid/hid-roccat-kone.c
index f776957..e0dd8f9 100644
--- a/drivers/hid/hid-roccat-kone.c
+++ b/drivers/hid/hid-roccat-kone.c
@@ -507,9 +507,9 @@ static ssize_t kone_sysfs_set_tcu(struct device *dev,
struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
int retval;
- unsigned long state;
+ int state;

- retval = strict_strtoul(buf, 10, &state);
+ retval = kstrtoint(buf, 10, &state);
if (retval)
return retval;

@@ -589,9 +589,9 @@ static ssize_t kone_sysfs_set_startup_profile(struct device *dev,
struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
int retval;
- unsigned long new_startup_profile;
+ int new_startup_profile;

- retval = strict_strtoul(buf, 10, &new_startup_profile);
+ retval = kstrtoint(buf, 10, &new_startup_profile);
if (retval)
return retval;

--
1.7.2.2

2010-12-05 17:56:52

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 16/45] kstrtox: convert drivers/bluetooth/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/bluetooth/btmrvl_debugfs.c | 50 +++++++++++++++++------------------
1 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/drivers/bluetooth/btmrvl_debugfs.c b/drivers/bluetooth/btmrvl_debugfs.c
index fd6305b..ffc4324 100644
--- a/drivers/bluetooth/btmrvl_debugfs.c
+++ b/drivers/bluetooth/btmrvl_debugfs.c
@@ -56,16 +56,16 @@ static ssize_t btmrvl_hscfgcmd_write(struct file *file,
{
struct btmrvl_private *priv = file->private_data;
char buf[16];
- long result, ret;
+ int ret;

memset(buf, 0, sizeof(buf));

if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
return -EFAULT;

- ret = strict_strtol(buf, 10, &result);
-
- priv->btmrvl_dev.hscfgcmd = result;
+ ret = kstrtou8(buf, 10, &priv->btmrvl_dev.hscfgcmd);
+ if (ret < 0)
+ return ret;

if (priv->btmrvl_dev.hscfgcmd) {
btmrvl_prepare_command(priv);
@@ -100,17 +100,16 @@ static ssize_t btmrvl_psmode_write(struct file *file, const char __user *ubuf,
{
struct btmrvl_private *priv = file->private_data;
char buf[16];
- long result, ret;
+ int ret;

memset(buf, 0, sizeof(buf));

if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
return -EFAULT;

- ret = strict_strtol(buf, 10, &result);
-
- priv->btmrvl_dev.psmode = result;
-
+ ret = kstrtou8(buf, 10, &priv->btmrvl_dev.psmode);
+ if (ret < 0)
+ return ret;
return count;
}

@@ -139,16 +138,16 @@ static ssize_t btmrvl_pscmd_write(struct file *file, const char __user *ubuf,
{
struct btmrvl_private *priv = file->private_data;
char buf[16];
- long result, ret;
+ int ret;

memset(buf, 0, sizeof(buf));

if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
return -EFAULT;

- ret = strict_strtol(buf, 10, &result);
-
- priv->btmrvl_dev.pscmd = result;
+ ret = kstrtou8(buf, 10, &priv->btmrvl_dev.pscmd);
+ if (ret < 0)
+ return ret;

if (priv->btmrvl_dev.pscmd) {
btmrvl_prepare_command(priv);
@@ -183,17 +182,16 @@ static ssize_t btmrvl_gpiogap_write(struct file *file, const char __user *ubuf,
{
struct btmrvl_private *priv = file->private_data;
char buf[16];
- long result, ret;
+ int ret;

memset(buf, 0, sizeof(buf));

if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
return -EFAULT;

- ret = strict_strtol(buf, 16, &result);
-
- priv->btmrvl_dev.gpio_gap = result;
-
+ ret = kstrtou16(buf, 16, &priv->btmrvl_dev.gpio_gap);
+ if (ret < 0)
+ return ret;
return count;
}

@@ -222,16 +220,17 @@ static ssize_t btmrvl_hscmd_write(struct file *file, const char __user *ubuf,
{
struct btmrvl_private *priv = file->private_data;
char buf[16];
- long result, ret;
+ int ret;

memset(buf, 0, sizeof(buf));

if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
return -EFAULT;

- ret = strict_strtol(buf, 10, &result);
+ ret = kstrtou8(buf, 10, &priv->btmrvl_dev.hscmd);
+ if (ret < 0)
+ return ret;

- priv->btmrvl_dev.hscmd = result;
if (priv->btmrvl_dev.hscmd) {
btmrvl_prepare_command(priv);
wake_up_interruptible(&priv->main_thread.wait_q);
@@ -264,17 +263,16 @@ static ssize_t btmrvl_hsmode_write(struct file *file, const char __user *ubuf,
{
struct btmrvl_private *priv = file->private_data;
char buf[16];
- long result, ret;
+ int ret;

memset(buf, 0, sizeof(buf));

if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
return -EFAULT;

- ret = strict_strtol(buf, 10, &result);
-
- priv->btmrvl_dev.hsmode = result;
-
+ ret = kstrtou8(buf, 10, &priv->btmrvl_dev.hsmode);
+ if (ret < 0)
+ return ret;
return count;
}

--
1.7.2.2

2010-12-05 17:50:39

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 12/45] kstrtox: convert drivers/acpi/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
drivers/acpi/acpi_pad.c | 27 ++++++++++++++++++---------
drivers/acpi/power_meter.c | 16 +++++++---------
2 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c
index 6afceb3..20d1c2d 100644
--- a/drivers/acpi/acpi_pad.c
+++ b/drivers/acpi/acpi_pad.c
@@ -284,9 +284,12 @@ static uint32_t acpi_pad_idle_cpus_num(void)
static ssize_t acpi_pad_rrtime_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
- unsigned long num;
- if (strict_strtoul(buf, 0, &num))
- return -EINVAL;
+ unsigned int num;
+ int rv;
+
+ rv = kstrtouint(buf, 0, &num);
+ if (rv < 0)
+ return rv;
if (num < 1 || num >= 100)
return -EINVAL;
mutex_lock(&isolated_cpus_lock);
@@ -307,9 +310,12 @@ static DEVICE_ATTR(rrtime, S_IRUGO|S_IWUSR,
static ssize_t acpi_pad_idlepct_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
- unsigned long num;
- if (strict_strtoul(buf, 0, &num))
- return -EINVAL;
+ unsigned int num;
+ int rv;
+
+ rv = kstrtouint(buf, 0, &num);
+ if (rv < 0)
+ return rv;
if (num < 1 || num >= 100)
return -EINVAL;
mutex_lock(&isolated_cpus_lock);
@@ -330,9 +336,12 @@ static DEVICE_ATTR(idlepct, S_IRUGO|S_IWUSR,
static ssize_t acpi_pad_idlecpus_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
- unsigned long num;
- if (strict_strtoul(buf, 0, &num))
- return -EINVAL;
+ unsigned int num;
+ int rv;
+
+ rv = kstrtouint(buf, 0, &num);
+ if (rv < 0)
+ return rv;
mutex_lock(&isolated_cpus_lock);
acpi_pad_idle_cpus(num);
mutex_unlock(&isolated_cpus_lock);
diff --git a/drivers/acpi/power_meter.c b/drivers/acpi/power_meter.c
index 66f6729..a468c33 100644
--- a/drivers/acpi/power_meter.c
+++ b/drivers/acpi/power_meter.c
@@ -166,12 +166,12 @@ static ssize_t set_avg_interval(struct device *dev,
union acpi_object arg0 = { ACPI_TYPE_INTEGER };
struct acpi_object_list args = { 1, &arg0 };
int res;
- unsigned long temp;
+ u64 temp;
unsigned long long data;
acpi_status status;

- res = strict_strtoul(buf, 10, &temp);
- if (res)
+ res = kstrtou64(buf, 10, &temp);
+ if (res < 0)
return res;

if (temp > resource->caps.max_avg_interval ||
@@ -241,8 +241,8 @@ static ssize_t set_cap(struct device *dev, struct device_attribute *devattr,
unsigned long long data;
acpi_status status;

- res = strict_strtoul(buf, 10, &temp);
- if (res)
+ res = kstrtoul(buf, 10, &temp);
+ if (res < 0)
return res;

temp /= 1000;
@@ -311,13 +311,11 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
int res;
unsigned long temp;

- res = strict_strtoul(buf, 10, &temp);
- if (res)
+ res = kstrtoul(buf, 10, &temp);
+ if (res < 0)
return res;

temp /= 1000;
- if (temp < 0)
- return -EINVAL;

mutex_lock(&resource->lock);
resource->trip[attr->index - 7] = temp;
--
1.7.2.2

2010-12-05 17:57:31

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 11/45] kstrtox: convert block/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
block/blk-cgroup.c | 47 ++++++++++++++++++++++++-----------------------
1 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index b1febd0..a18532a 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -656,10 +656,9 @@ static int blkio_policy_parse_and_set(char *buf,
{
char *s[4], *p, *major_s = NULL, *minor_s = NULL;
int ret;
- unsigned long major, minor, temp;
+ unsigned int major, minor;
int i = 0;
dev_t dev;
- u64 bps, iops;

memset(s, 0, sizeof(s));

@@ -687,15 +686,15 @@ static int blkio_policy_parse_and_set(char *buf,
if (!minor_s)
return -EINVAL;

- ret = strict_strtoul(major_s, 10, &major);
- if (ret)
- return -EINVAL;
-
- ret = strict_strtoul(minor_s, 10, &minor);
+ ret = kstrtouint(major_s, 10, &major);
+ if (ret < 0)
+ return ret;
+ ret = kstrtouint(minor_s, 10, &minor);
if (ret)
- return -EINVAL;
-
+ return ret;
dev = MKDEV(major, minor);
+ if (MAJOR(dev) != major || MINOR(dev) != minor)
+ return -EINVAL;

ret = blkio_check_dev_num(dev);
if (ret)
@@ -707,40 +706,42 @@ static int blkio_policy_parse_and_set(char *buf,
return -EINVAL;

switch (plid) {
+ unsigned int weigth;
+
case BLKIO_POLICY_PROP:
- ret = strict_strtoul(s[1], 10, &temp);
- if (ret || (temp < BLKIO_WEIGHT_MIN && temp > 0) ||
- temp > BLKIO_WEIGHT_MAX)
+ ret = kstrtouint(s[1], 10, &weigth);
+ if (ret < 0)
+ return ret;
+ if (weigth < BLKIO_WEIGHT_MIN || weigth > BLKIO_WEIGHT_MAX)
return -EINVAL;

newpn->plid = plid;
newpn->fileid = fileid;
- newpn->val.weight = temp;
+ newpn->val.weight = weigth;
break;
case BLKIO_POLICY_THROTL:
switch(fileid) {
+ unsigned int iops;
+
case BLKIO_THROTL_read_bps_device:
case BLKIO_THROTL_write_bps_device:
- ret = strict_strtoull(s[1], 10, &bps);
- if (ret)
- return -EINVAL;
-
newpn->plid = plid;
newpn->fileid = fileid;
- newpn->val.bps = bps;
+ ret = kstrtou64(s[1], 10, &newpn->val.bps);
+ if (ret < 0)
+ return ret;
break;
case BLKIO_THROTL_read_iops_device:
case BLKIO_THROTL_write_iops_device:
- ret = strict_strtoull(s[1], 10, &iops);
- if (ret)
- return -EINVAL;
-
+ ret = kstrtouint(s[1], 10, &iops);
+ if (ret < 0)
+ return ret;
if (iops > THROTL_IOPS_MAX)
return -EINVAL;

newpn->plid = plid;
newpn->fileid = fileid;
- newpn->val.iops = (unsigned int)iops;
+ newpn->val.iops = iops;
break;
}
break;
--
1.7.2.2

2010-12-05 17:57:47

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 09/45] kstrtox: convert fs/proc/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
fs/proc/base.c | 12 ++++++------
fs/proc/task_mmu.c | 8 +++++---
2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index f3d02ca..4469398 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1018,7 +1018,7 @@ static ssize_t oom_adjust_write(struct file *file, const char __user *buf,
{
struct task_struct *task;
char buffer[PROC_NUMBUF];
- long oom_adjust;
+ int oom_adjust;
unsigned long flags;
int err;

@@ -1030,8 +1030,8 @@ static ssize_t oom_adjust_write(struct file *file, const char __user *buf,
goto out;
}

- err = strict_strtol(strstrip(buffer), 0, &oom_adjust);
- if (err)
+ err = kstrtoint(strstrip(buffer), 0, &oom_adjust);
+ if (err < 0)
goto out;
if ((oom_adjust < OOM_ADJUST_MIN || oom_adjust > OOM_ADJUST_MAX) &&
oom_adjust != OOM_DISABLE) {
@@ -1127,7 +1127,7 @@ static ssize_t oom_score_adj_write(struct file *file, const char __user *buf,
struct task_struct *task;
char buffer[PROC_NUMBUF];
unsigned long flags;
- long oom_score_adj;
+ int oom_score_adj;
int err;

memset(buffer, 0, sizeof(buffer));
@@ -1138,8 +1138,8 @@ static ssize_t oom_score_adj_write(struct file *file, const char __user *buf,
goto out;
}

- err = strict_strtol(strstrip(buffer), 0, &oom_score_adj);
- if (err)
+ err = kstrtoint(strstrip(buffer), 0, &oom_score_adj);
+ if (err < 0)
goto out;
if (oom_score_adj < OOM_SCORE_ADJ_MIN ||
oom_score_adj > OOM_SCORE_ADJ_MAX) {
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index c126c83..d6cd94a 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -493,15 +493,17 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
char buffer[PROC_NUMBUF];
struct mm_struct *mm;
struct vm_area_struct *vma;
- long type;
+ int type;
+ int rv;

memset(buffer, 0, sizeof(buffer));
if (count > sizeof(buffer) - 1)
count = sizeof(buffer) - 1;
if (copy_from_user(buffer, buf, count))
return -EFAULT;
- if (strict_strtol(strstrip(buffer), 10, &type))
- return -EINVAL;
+ rv = kstrtoint(strstrip(buffer), 10, &type);
+ if (rv < 0)
+ return rv;
if (type < CLEAR_REFS_ALL || type > CLEAR_REFS_MAPPED)
return -EINVAL;
task = get_proc_task(file->f_path.dentry->d_inode);
--
1.7.2.2

2010-12-05 17:58:15

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 07/45] kstrtox: convert fs/fuse/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
fs/fuse/control.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/fuse/control.c b/fs/fuse/control.c
index 85542a7..b916b34 100644
--- a/fs/fuse/control.c
+++ b/fs/fuse/control.c
@@ -74,7 +74,7 @@ static ssize_t fuse_conn_limit_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos, unsigned *val,
unsigned global_limit)
{
- unsigned long t;
+ unsigned int t;
char tmp[32];
unsigned limit = (1 << 16) - 1;
int err;
@@ -87,7 +87,7 @@ static ssize_t fuse_conn_limit_write(struct file *file, const char __user *buf,

tmp[count] = '\0';

- err = strict_strtoul(tmp, 0, &t);
+ err = kstrtouint(tmp, 0, &t);
if (err)
return err;

--
1.7.2.2

2010-12-05 17:50:17

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 02/45] kstrtox: convert arch/x86/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
arch/x86/kernel/cpu/cpufreq/powernow-k8.c | 12 ++++++++----
arch/x86/kernel/cpu/intel_cacheinfo.c | 15 ++++++++-------
arch/x86/kernel/cpu/mcheck/mce.c | 25 ++++++++++++++-----------
arch/x86/kernel/cpu/mcheck/mce_amd.c | 12 ++++++++----
arch/x86/kvm/mmu_audit.c | 6 +++---
arch/x86/platform/uv/tlb_uv.c | 19 ++++++++++++-------
6 files changed, 53 insertions(+), 36 deletions(-)

diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k8.c b/arch/x86/kernel/cpu/cpufreq/powernow-k8.c
index 491977b..1b8380a 100644
--- a/arch/x86/kernel/cpu/cpufreq/powernow-k8.c
+++ b/arch/x86/kernel/cpu/cpufreq/powernow-k8.c
@@ -1451,11 +1451,15 @@ static void cpb_toggle(bool t)
static ssize_t store_cpb(struct cpufreq_policy *policy, const char *buf,
size_t count)
{
- int ret = -EINVAL;
- unsigned long val = 0;
+ int val;
+ int ret;

- ret = strict_strtoul(buf, 10, &val);
- if (!ret && (val == 0 || val == 1) && cpb_capable)
+ ret = kstrtoint(buf, 10, &val);
+ if (ret < 0)
+ return ret;
+ if (val != 0 && val != 1)
+ return -EINVAL;
+ if (cpb_capable)
cpb_toggle(val);
else
return -EINVAL;
diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
index 17ad033..3647889 100644
--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
@@ -442,7 +442,7 @@ SHOW_CACHE_DISABLE(0)
SHOW_CACHE_DISABLE(1)

static void amd_l3_disable_index(struct amd_l3_cache *l3, int cpu,
- unsigned slot, unsigned long idx)
+ unsigned slot, u32 idx)
{
int i;

@@ -481,12 +481,12 @@ static void amd_l3_disable_index(struct amd_l3_cache *l3, int cpu,
*
* @return: 0 on success, error status on failure
*/
-int amd_set_l3_disable_slot(struct amd_l3_cache *l3, int cpu, unsigned slot,
- unsigned long index)
+static int amd_set_l3_disable_slot(struct amd_l3_cache *l3, int cpu,
+ unsigned slot, u32 index)
{
int ret = 0;

-#define SUBCACHE_MASK (3UL << 20)
+#define SUBCACHE_MASK (3U << 20)
#define SUBCACHE_INDEX 0xfff

/*
@@ -518,7 +518,7 @@ static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,
const char *buf, size_t count,
unsigned int slot)
{
- unsigned long val = 0;
+ u32 val;
int cpu, err = 0;

if (!capable(CAP_SYS_ADMIN))
@@ -529,8 +529,9 @@ static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,

cpu = cpumask_first(to_cpumask(this_leaf->shared_cpu_map));

- if (strict_strtoul(buf, 10, &val) < 0)
- return -EINVAL;
+ err = kstrtou32(buf, 10, &val);
+ if (err < 0)
+ return err;

err = amd_set_l3_disable_slot(this_leaf->l3, cpu, slot, val);
if (err) {
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index 7a35b72..f868f80 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -1833,12 +1833,11 @@ static ssize_t show_bank(struct sys_device *s, struct sysdev_attribute *attr,
static ssize_t set_bank(struct sys_device *s, struct sysdev_attribute *attr,
const char *buf, size_t size)
{
- u64 new;
+ int rv;

- if (strict_strtoull(buf, 0, &new) < 0)
- return -EINVAL;
-
- attr_to_bank(attr)->ctl = new;
+ rv = kstrtou64(buf, 0, &attr_to_bank(attr)->ctl);
+ if (rv < 0)
+ return rv;
mce_restart();

return size;
@@ -1871,10 +1870,12 @@ static ssize_t set_ignore_ce(struct sys_device *s,
struct sysdev_attribute *attr,
const char *buf, size_t size)
{
- u64 new;
+ unsigned long long new;
+ int rv;

- if (strict_strtoull(buf, 0, &new) < 0)
- return -EINVAL;
+ rv = kstrtoull(buf, 0, &new);
+ if (rv < 0)
+ return rv;

if (mce_ignore_ce ^ !!new) {
if (new) {
@@ -1894,10 +1895,12 @@ static ssize_t set_cmci_disabled(struct sys_device *s,
struct sysdev_attribute *attr,
const char *buf, size_t size)
{
- u64 new;
+ unsigned long long new;
+ int rv;

- if (strict_strtoull(buf, 0, &new) < 0)
- return -EINVAL;
+ rv = kstrtoull(buf, 0, &new);
+ if (rv < 0)
+ return rv;

if (mce_cmci_disabled ^ !!new) {
if (new) {
diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c
index 80c4823..27e1555 100644
--- a/arch/x86/kernel/cpu/mcheck/mce_amd.c
+++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c
@@ -292,9 +292,11 @@ store_interrupt_enable(struct threshold_block *b, const char *buf, size_t size)
{
struct thresh_restart tr;
unsigned long new;
+ int rv;

- if (strict_strtoul(buf, 0, &new) < 0)
- return -EINVAL;
+ rv = kstrtoul(buf, 0, &new);
+ if (rv < 0)
+ return rv;

b->interrupt_enable = !!new;

@@ -312,9 +314,11 @@ store_threshold_limit(struct threshold_block *b, const char *buf, size_t size)
{
struct thresh_restart tr;
unsigned long new;
+ int rv;

- if (strict_strtoul(buf, 0, &new) < 0)
- return -EINVAL;
+ rv = kstrtoul(buf, 0, &new);
+ if (rv < 0)
+ return rv;

if (new > THRESHOLD_MAX)
new = THRESHOLD_MAX;
diff --git a/arch/x86/kvm/mmu_audit.c b/arch/x86/kvm/mmu_audit.c
index ba2bcdd..64ffde1 100644
--- a/arch/x86/kvm/mmu_audit.c
+++ b/arch/x86/kvm/mmu_audit.c
@@ -270,12 +270,12 @@ static void mmu_audit_disable(void)

static int mmu_audit_set(const char *val, const struct kernel_param *kp)
{
+ int enable;
int ret;
- unsigned long enable;

- ret = strict_strtoul(val, 10, &enable);
+ ret = kstrtoint(val, 10, &enable);
if (ret < 0)
- return -EINVAL;
+ return ret;

switch (enable) {
case 0:
diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
index ba9caa8..0fc13d3 100644
--- a/arch/x86/platform/uv/tlb_uv.c
+++ b/arch/x86/platform/uv/tlb_uv.c
@@ -1028,21 +1028,22 @@ static ssize_t uv_ptc_proc_write(struct file *file, const char __user *user,
size_t count, loff_t *data)
{
int cpu;
- long input_arg;
+ int input_arg;
char optstr[64];
struct ptc_stats *stat;
+ int rv;

if (count == 0 || count > sizeof(optstr))
return -EINVAL;
if (copy_from_user(optstr, user, count))
return -EFAULT;
optstr[count - 1] = '\0';
- if (strict_strtol(optstr, 10, &input_arg) < 0) {
- printk(KERN_DEBUG "%s is invalid\n", optstr);
- return -EINVAL;
- }
+ rv = kstrtoint(optstr, 10, &input_arg);
+ if (rv < 0)
+ return rv;

- if (input_arg == 0) {
+ switch (input_arg) {
+ case 0:
printk(KERN_DEBUG "# cpu: cpu number\n");
printk(KERN_DEBUG "Sender statistics:\n");
printk(KERN_DEBUG
@@ -1110,11 +1111,15 @@ static ssize_t uv_ptc_proc_write(struct file *file, const char __user *user,
"disable: number times use of the BAU was disabled\n");
printk(KERN_DEBUG
"enable: number times use of the BAU was re-enabled\n");
- } else if (input_arg == -1) {
+ break;
+ case -1:
for_each_present_cpu(cpu) {
stat = &per_cpu(ptcstats, cpu);
memset(stat, 0, sizeof(struct ptc_stats));
}
+ break;
+ default:
+ return -EINVAL;
}

return count;
--
1.7.2.2

2010-12-05 17:58:33

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 05/45] kstrtox: kernel/trace/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
kernel/trace/ftrace.c | 6 +++---
kernel/trace/ring_buffer.c | 2 +-
kernel/trace/trace.c | 16 ++++++++--------
kernel/trace/trace_events.c | 8 ++++----
kernel/trace/trace_events_filter.c | 4 ++--
kernel/trace/trace_functions.c | 4 ++--
kernel/trace/trace_kprobe.c | 25 ++++++++++++-------------
kernel/trace/trace_stack.c | 4 ++--
8 files changed, 34 insertions(+), 35 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index f3dadae..537fd31 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -747,7 +747,7 @@ ftrace_profile_write(struct file *filp, const char __user *ubuf,

buf[cnt] = 0;

- ret = strict_strtoul(buf, 10, &val);
+ ret = kstrtoul(buf, 10, &val);
if (ret < 0)
return ret;

@@ -3053,7 +3053,7 @@ ftrace_pid_write(struct file *filp, const char __user *ubuf,
size_t cnt, loff_t *ppos)
{
char buf[64], *tmp;
- long val;
+ int val;
int ret;

if (cnt >= sizeof(buf))
@@ -3072,7 +3072,7 @@ ftrace_pid_write(struct file *filp, const char __user *ubuf,
if (strlen(tmp) == 0)
return 1;

- ret = strict_strtol(tmp, 10, &val);
+ ret = kstrtoint(tmp, 10, &val);
if (ret < 0)
return ret;

diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 9ed509a..9ad99a6 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -3965,7 +3965,7 @@ rb_simple_write(struct file *filp, const char __user *ubuf,

buf[cnt] = 0;

- ret = strict_strtoul(buf, 10, &val);
+ ret = kstrtoul(buf, 10, &val);
if (ret < 0)
return ret;

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index c380612..8509b20 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -389,7 +389,7 @@ static int __init set_tracing_thresh(char *str)

if (!str)
return 0;
- ret = strict_strtoul(str, 0, &threshhold);
+ ret = kstrtoul(str, 0, &threshhold);
if (ret < 0)
return 0;
tracing_thresh = threshhold * 1000;
@@ -2696,7 +2696,7 @@ tracing_ctrl_write(struct file *filp, const char __user *ubuf,

buf[cnt] = 0;

- ret = strict_strtoul(buf, 10, &val);
+ ret = kstrtoul(buf, 10, &val);
if (ret < 0)
return ret;

@@ -2957,7 +2957,7 @@ tracing_max_lat_write(struct file *filp, const char __user *ubuf,

buf[cnt] = 0;

- ret = strict_strtoul(buf, 10, &val);
+ ret = kstrtoul(buf, 10, &val);
if (ret < 0)
return ret;

@@ -3416,7 +3416,7 @@ tracing_entries_write(struct file *filp, const char __user *ubuf,

buf[cnt] = 0;

- ret = strict_strtoul(buf, 10, &val);
+ ret = kstrtoul(buf, 10, &val);
if (ret < 0)
return ret;

@@ -4069,7 +4069,7 @@ trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt,
loff_t *ppos)
{
struct trace_option_dentry *topt = filp->private_data;
- unsigned long val;
+ unsigned int val;
char buf[64];
int ret;

@@ -4081,7 +4081,7 @@ trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt,

buf[cnt] = 0;

- ret = strict_strtoul(buf, 10, &val);
+ ret = kstrtouint(buf, 10, &val);
if (ret < 0)
return ret;

@@ -4131,7 +4131,7 @@ trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt,
{
long index = (long)filp->private_data;
char buf[64];
- unsigned long val;
+ unsigned int val;
int ret;

if (cnt >= sizeof(buf))
@@ -4142,7 +4142,7 @@ trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt,

buf[cnt] = 0;

- ret = strict_strtoul(buf, 10, &val);
+ ret = kstrtouint(buf, 10, &val);
if (ret < 0)
return ret;

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 0725eea..c7039a2 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -480,7 +480,7 @@ event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
{
struct ftrace_event_call *call = filp->private_data;
char buf[64];
- unsigned long val;
+ int val;
int ret;

if (cnt >= sizeof(buf))
@@ -491,7 +491,7 @@ event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,

buf[cnt] = 0;

- ret = strict_strtoul(buf, 10, &val);
+ ret = kstrtoint(buf, 10, &val);
if (ret < 0)
return ret;

@@ -563,8 +563,8 @@ system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
loff_t *ppos)
{
const char *system = filp->private_data;
- unsigned long val;
char buf[64];
+ int val;
ssize_t ret;

if (cnt >= sizeof(buf))
@@ -575,7 +575,7 @@ system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,

buf[cnt] = 0;

- ret = strict_strtoul(buf, 10, &val);
+ ret = kstrtoint(buf, 10, &val);
if (ret < 0)
return ret;

diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 36d4010..f17f6a0 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -807,9 +807,9 @@ static int filter_add_pred(struct filter_parse_state *ps,
fn = filter_pred_pchar;
} else {
if (field->is_signed)
- ret = strict_strtoll(pred->regex.pattern, 0, &val);
+ ret = kstrtoll(pred->regex.pattern, 0, &val);
else
- ret = strict_strtoull(pred->regex.pattern, 0, &val);
+ ret = kstrtoull(pred->regex.pattern, 0, &val);
if (ret) {
parse_error(ps, FILT_ERR_ILLEGAL_INTVAL, 0);
return -EINVAL;
diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c
index 16aee4d..2f0dab3 100644
--- a/kernel/trace/trace_functions.c
+++ b/kernel/trace/trace_functions.c
@@ -354,8 +354,8 @@ ftrace_trace_onoff_callback(char *glob, char *cmd, char *param, int enable)
* We use the callback data field (which is a pointer)
* as our counter.
*/
- ret = strict_strtoul(number, 0, (unsigned long *)&count);
- if (ret)
+ ret = kstrtoul(number, 0, (unsigned long *)&count);
+ if (ret < 0)
return ret;

out_reg:
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 2dec9bc..e29849d 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -684,9 +684,8 @@ static int split_symbol_offset(char *symbol, unsigned long *offset)

tmp = strchr(symbol, '+');
if (tmp) {
- /* skip sign because strict_strtol doesn't accept '+' */
- ret = strict_strtoul(tmp + 1, 0, offset);
- if (ret)
+ ret = kstrtoul(tmp, 0, offset);
+ if (ret < 0)
return ret;
*tmp = '\0';
} else
@@ -715,8 +714,10 @@ static int parse_probe_vars(char *arg, const struct fetch_type *t,
else
ret = -EINVAL;
} else if (isdigit(arg[5])) {
- ret = strict_strtoul(arg + 5, 10, &param);
- if (ret || param > PARAM_MAX_STACK)
+ ret = kstrtoul(arg + 5, 10, &param);
+ if (ret < 0)
+ return ret;
+ if (param > PARAM_MAX_STACK)
ret = -EINVAL;
else {
f->fn = t->fetch[FETCH_MTD_stack];
@@ -752,8 +753,8 @@ static int __parse_probe_arg(char *arg, const struct fetch_type *t,
break;
case '@': /* memory or symbol */
if (isdigit(arg[1])) {
- ret = strict_strtoul(arg + 1, 0, &param);
- if (ret)
+ ret = kstrtoul(arg + 1, 0, &param);
+ if (ret < 0)
break;
f->fn = t->fetch[FETCH_MTD_memory];
f->data = (void *)param;
@@ -772,11 +773,9 @@ static int __parse_probe_arg(char *arg, const struct fetch_type *t,
if (!tmp)
break;
*tmp = '\0';
- ret = strict_strtol(arg + 1, 0, &offset);
- if (ret)
+ ret = kstrtol(arg, 0, &offset);
+ if (ret < 0)
break;
- if (arg[0] == '-')
- offset = -offset;
arg = tmp + 1;
tmp = strrchr(arg, ')');
if (tmp) {
@@ -948,8 +947,8 @@ static int create_trace_probe(int argc, char **argv)
return -EINVAL;
}
/* an address specified */
- ret = strict_strtoul(&argv[1][0], 0, (unsigned long *)&addr);
- if (ret) {
+ ret = kstrtoul(&argv[1][0], 0, (unsigned long *)&addr);
+ if (ret < 0) {
pr_info("Failed to parse address.\n");
return ret;
}
diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
index 4c5dead..36ebd3b 100644
--- a/kernel/trace/trace_stack.c
+++ b/kernel/trace/trace_stack.c
@@ -153,7 +153,7 @@ static ssize_t
stack_max_size_write(struct file *filp, const char __user *ubuf,
size_t count, loff_t *ppos)
{
- long *ptr = filp->private_data;
+ unsigned long *ptr = filp->private_data;
unsigned long val, flags;
char buf[64];
int ret;
@@ -167,7 +167,7 @@ stack_max_size_write(struct file *filp, const char __user *ubuf,

buf[count] = 0;

- ret = strict_strtoul(buf, 10, &val);
+ ret = kstrtoul(buf, 10, &val);
if (ret < 0)
return ret;

--
1.7.2.2

2010-12-05 17:58:48

by Alexey Dobriyan

[permalink] [raw]
Subject: [PATCH 04/45] kstrtox: convert kernel/


Signed-off-by: Alexey Dobriyan <[email protected]>
---
kernel/gcov/fs.c | 5 +----
kernel/ksysfs.c | 5 +++--
kernel/params.c | 24 +++++++++++-------------
kernel/power/main.c | 8 +++++---
4 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/kernel/gcov/fs.c b/kernel/gcov/fs.c
index 9bd0934..347c2b3 100644
--- a/kernel/gcov/fs.c
+++ b/kernel/gcov/fs.c
@@ -72,13 +72,10 @@ static int gcov_persist = 1;

static int __init gcov_persist_setup(char *str)
{
- unsigned long val;
-
- if (strict_strtoul(str, 0, &val)) {
+ if (kstrtoint(str, 0, &gcov_persist) < 0) {
pr_warning("invalid gcov_persist parameter '%s'\n", str);
return 0;
}
- gcov_persist = val;
pr_info("setting gcov_persist to %d\n", gcov_persist);

return 1;
diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
index 0b624e7..b0b4681 100644
--- a/kernel/ksysfs.c
+++ b/kernel/ksysfs.c
@@ -112,8 +112,9 @@ static ssize_t kexec_crash_size_store(struct kobject *kobj,
unsigned long cnt;
int ret;

- if (strict_strtoul(buf, 0, &cnt))
- return -EINVAL;
+ ret = kstrtoul(buf, 0, &cnt);
+ if (ret < 0)
+ return ret;

ret = crash_shrink_memory(cnt);
return ret < 0 ? ret : count;
diff --git a/kernel/params.c b/kernel/params.c
index 08107d1..7c3ecec 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -218,16 +218,14 @@ int parse_args(const char *name,
}

/* Lazy bastard, eh? */
-#define STANDARD_PARAM_DEF(name, type, format, tmptype, strtolfn) \
+#define STANDARD_PARAM_DEF(name, type, format, strtolfn) \
int param_set_##name(const char *val, const struct kernel_param *kp) \
{ \
- tmptype l; \
int ret; \
\
- ret = strtolfn(val, 0, &l); \
- if (ret == -EINVAL || ((type)l != l)) \
- return -EINVAL; \
- *((type *)kp->arg) = l; \
+ ret = strtolfn(val, 0, (type *)kp->arg); \
+ if (ret < 0) \
+ return ret; \
return 0; \
} \
int param_get_##name(char *buffer, const struct kernel_param *kp) \
@@ -243,13 +241,13 @@ int parse_args(const char *name,
EXPORT_SYMBOL(param_ops_##name)


-STANDARD_PARAM_DEF(byte, unsigned char, "%c", unsigned long, strict_strtoul);
-STANDARD_PARAM_DEF(short, short, "%hi", long, strict_strtol);
-STANDARD_PARAM_DEF(ushort, unsigned short, "%hu", unsigned long, strict_strtoul);
-STANDARD_PARAM_DEF(int, int, "%i", long, strict_strtol);
-STANDARD_PARAM_DEF(uint, unsigned int, "%u", unsigned long, strict_strtoul);
-STANDARD_PARAM_DEF(long, long, "%li", long, strict_strtol);
-STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", unsigned long, strict_strtoul);
+STANDARD_PARAM_DEF(byte, u8, "%c", kstrtou8);
+STANDARD_PARAM_DEF(short, s16, "%hi", kstrtos16);
+STANDARD_PARAM_DEF(ushort, u16, "%hu", kstrtou16);
+STANDARD_PARAM_DEF(int, int, "%i", kstrtoint);
+STANDARD_PARAM_DEF(uint, unsigned int, "%u", kstrtouint);
+STANDARD_PARAM_DEF(long, long, "%li", kstrtol);
+STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", kstrtoul);

int param_set_charp(const char *val, const struct kernel_param *kp)
{
diff --git a/kernel/power/main.c b/kernel/power/main.c
index 7b5db6a..c53c77e 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -56,10 +56,12 @@ static ssize_t pm_async_show(struct kobject *kobj, struct kobj_attribute *attr,
static ssize_t pm_async_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t n)
{
- unsigned long val;
+ unsigned int val;
+ int rv;

- if (strict_strtoul(buf, 10, &val))
- return -EINVAL;
+ rv = kstrtouint(buf, 10, &val);
+ if (rv < 0)
+ return rv;

if (val > 1)
return -EINVAL;
--
1.7.2.2

2010-12-06 00:24:09

by Tilman Schmidt

[permalink] [raw]
Subject: Re: [PATCH 26/45] kstrtox: convert drivers/isdn/

I like the patch, but why not go all the way?

Am 05.12.2010 18:49 schrieb Alexey Dobriyan:
> @@ -566,10 +566,10 @@ void gigaset_handle_modem_response(struct cardstate *cs)
> case RT_ZCAU:
> event->parameter = -1;
> if (curarg + 1 < params) {
> - unsigned long type, value;
> + u8 type, value;
>
> - i = strict_strtoul(argv[curarg++], 16, &type);
> - j = strict_strtoul(argv[curarg++], 16, &value);
> + i = kstrtou8(argv[curarg++], 16, &type);
> + j = kstrtou8(argv[curarg++], 16, &value);
>
> if (i == 0 && type < 256 &&
> j == 0 && value < 256)

Once type and value are u8, the checks for < 256 are unnecessary.

> @@ -583,7 +583,7 @@ void gigaset_handle_modem_response(struct cardstate *cs)
> unsigned long res;
> int rc;
>
> - rc = strict_strtoul(argv[curarg++], 10, &res);
> + rc = kstrtoul(argv[curarg++], 10, &res);
> if (rc == 0)
> event->parameter = res;
> }

The new kstrtoul() promises not to touch the result field in the event
of a conversion error, so &event->parameter can be passed directly to
it, getting rid of the variables rc and res and the if statement.

Thanks,
Tilman

2010-12-06 00:32:31

by Jesper Juhl

[permalink] [raw]
Subject: Re: [PATCH 01/45] kstrtox: converting strings to integers done (hopefully) right

On Sun, 5 Dec 2010, Alexey Dobriyan wrote:

> 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: sizeof and __alignof__ trick is done to save function call
> where types aren't distinguishable.
>
> Signed-off-by: Alexey Dobriyan <[email protected]>
> ---
<snip>
> +/* Internal, do not use. */
> +int _kstrtol(const char *s, unsigned int base, long *res)
> +{
> + long long tmp;
> + int rv;
> +
> + rv = kstrtoll(s, base, &tmp);
> + if (rv < 0)
> + return rv;
> + if (tmp != (long long)(long)tmp)
> + return -EINVAL;
> + *res = tmp;
> + return 0;
> +}
> +EXPORT_SYMBOL(_kstrtol);

Ok, probably I'm just being dense, but the "_" prefix tells me I probably
shouldn't use this function. The comment clearly tells me I shouldn't use
this function.
So, why is this exported? And if it is not/should not be exported, then
why is it not static?
(goes for other functions in this patch as well).


/Jesper Juhl

2010-12-06 15:16:39

by Alexey Dobriyan

[permalink] [raw]
Subject: Re: [PATCH 01/45] kstrtox: converting strings to integers done (hopefully) right

On Mon, Dec 6, 2010 at 2:25 AM, Jesper Juhl <[email protected]> wrote:
> On Sun, 5 Dec 2010, Alexey Dobriyan wrote:
>> Note: sizeof and __alignof__ trick is done to save function call
>> ? ? ? where types aren't distinguishable.
>>
>> Signed-off-by: Alexey Dobriyan <[email protected]>
>> ---
> <snip>
>> +/* Internal, do not use. */
>> +int _kstrtol(const char *s, unsigned int base, long *res)
>> +{
>> + ? ? long long tmp;
>> + ? ? int rv;
>> +
>> + ? ? rv = kstrtoll(s, base, &tmp);
>> + ? ? if (rv < 0)
>> + ? ? ? ? ? ? return rv;
>> + ? ? if (tmp != (long long)(long)tmp)
>> + ? ? ? ? ? ? return -EINVAL;
>> + ? ? *res = tmp;
>> + ? ? return 0;
>> +}
>> +EXPORT_SYMBOL(_kstrtol);
>
> Ok, probably I'm just being dense, but the "_" prefix tells me I probably
> shouldn't use this function. The comment clearly tells me I shouldn't use
> this function.
> So, why is this exported? And if it is not/should not be exported, then
> why is it not static?
> (goes for other functions in this patch as well).

It is used by kstrtol() if "long" and "long long" aren't the same type.
I can't ifdef it because gcc doesn't allow "#if sizeof(long long) == ".
"Do not use" hints "use kstrtol()".

2010-12-06 20:10:17

by Alexey Dobriyan

[permalink] [raw]
Subject: Re: [PATCH 26/45] kstrtox: convert drivers/isdn/

On Mon, Dec 06, 2010 at 01:10:45AM +0100, Tilman Schmidt wrote:
> I like the patch, but why not go all the way?
>
> Am 05.12.2010 18:49 schrieb Alexey Dobriyan:
> > @@ -566,10 +566,10 @@ void gigaset_handle_modem_response(struct cardstate *cs)
> > case RT_ZCAU:
> > event->parameter = -1;
> > if (curarg + 1 < params) {
> > - unsigned long type, value;
> > + u8 type, value;
> >
> > - i = strict_strtoul(argv[curarg++], 16, &type);
> > - j = strict_strtoul(argv[curarg++], 16, &value);
> > + i = kstrtou8(argv[curarg++], 16, &type);
> > + j = kstrtou8(argv[curarg++], 16, &value);
> >
> > if (i == 0 && type < 256 &&
> > j == 0 && value < 256)
>
> Once type and value are u8, the checks for < 256 are unnecessary.

OK.

> > @@ -583,7 +583,7 @@ void gigaset_handle_modem_response(struct cardstate *cs)
> > unsigned long res;
> > int rc;
> >
> > - rc = strict_strtoul(argv[curarg++], 10, &res);
> > + rc = kstrtoul(argv[curarg++], 10, &res);
> > if (rc == 0)
> > event->parameter = res;
> > }
>
> The new kstrtoul() promises not to touch the result field in the event
> of a conversion error, so &event->parameter can be passed directly to
> it, getting rid of the variables rc and res and the if statement.

What should be done in case of error?
Compiler will warn if kstrto*() result is unused:

kstrtoul(argv[curarg++], 10, &event->parameter);

2010-12-07 09:05:20

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [PATCH 01/45] kstrtox: converting strings to integers done (hopefully) right

On Monday 06 December 2010 16:16:36 Alexey Dobriyan wrote:
> > <snip>
> >> +/* Internal, do not use. */
> >> +int _kstrtol(const char *s, unsigned int base, long *res)
> >> +{
> >> + long long tmp;
> >> + int rv;
> >> +
> >> + rv = kstrtoll(s, base, &tmp);
> >> + if (rv < 0)
> >> + return rv;
> >> + if (tmp != (long long)(long)tmp)
> >> + return -EINVAL;
> >> + *res = tmp;
> >> + return 0;
> >> +}
> >> +EXPORT_SYMBOL(_kstrtol);
> >
> > Ok, probably I'm just being dense, but the "_" prefix tells me I probably
> > shouldn't use this function. The comment clearly tells me I shouldn't use
> > this function.
> > So, why is this exported? And if it is not/should not be exported, then
> > why is it not static?
> > (goes for other functions in this patch as well).
>
> It is used by kstrtol() if "long" and "long long" aren't the same type.
> I can't ifdef it because gcc doesn't allow "#if sizeof(long long) == ".
> "Do not use" hints "use kstrtol()".

Can't you use #ifdef CONFIG_64BIT to see if long is 64 bit wide?

Arnd

2010-12-07 09:32:33

by Alexey Dobriyan

[permalink] [raw]
Subject: Re: [PATCH 01/45] kstrtox: converting strings to integers done (hopefully) right

On Tue, Dec 07, 2010 at 10:04:58AM +0100, Arnd Bergmann wrote:
> On Monday 06 December 2010 16:16:36 Alexey Dobriyan wrote:
> > > <snip>
> > >> +/* Internal, do not use. */
> > >> +int _kstrtol(const char *s, unsigned int base, long *res)
> > >> +{
> > >> + long long tmp;
> > >> + int rv;
> > >> +
> > >> + rv = kstrtoll(s, base, &tmp);
> > >> + if (rv < 0)
> > >> + return rv;
> > >> + if (tmp != (long long)(long)tmp)
> > >> + return -EINVAL;
> > >> + *res = tmp;
> > >> + return 0;
> > >> +}
> > >> +EXPORT_SYMBOL(_kstrtol);
> > >
> > > Ok, probably I'm just being dense, but the "_" prefix tells me I probably
> > > shouldn't use this function. The comment clearly tells me I shouldn't use
> > > this function.
> > > So, why is this exported? And if it is not/should not be exported, then
> > > why is it not static?
> > > (goes for other functions in this patch as well).
> >
> > It is used by kstrtol() if "long" and "long long" aren't the same type.
> > I can't ifdef it because gcc doesn't allow "#if sizeof(long long) == ".
> > "Do not use" hints "use kstrtol()".
>
> Can't you use #ifdef CONFIG_64BIT to see if long is 64 bit wide?

I could, but there are no defines for alignment.

2010-12-07 09:45:49

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [PATCH 01/45] kstrtox: converting strings to integers done (hopefully) right

On Tuesday 07 December 2010 10:32:29 Alexey Dobriyan wrote:
> On Tue, Dec 07, 2010 at 10:04:58AM +0100, Arnd Bergmann wrote:
> > On Monday 06 December 2010 16:16:36 Alexey Dobriyan wrote:
> >
> > > It is used by kstrtol() if "long" and "long long" aren't the same type.
> > > I can't ifdef it because gcc doesn't allow "#if sizeof(long long) == ".
> > > "Do not use" hints "use kstrtol()".
> >
> > Can't you use #ifdef CONFIG_64BIT to see if long is 64 bit wide?
>
> I could, but there are no defines for alignment.

Not sure what you mean here. All architectures always naturally align
'long' variables -- we rely on that elsewhere already. 'long long' is
misaligned on x86-32 and possibly some other 32 bit architectures, but
since that should not cause any problems.

Another option would be to export just the strto{u,s}{8,16,32,64}
functions and define the inline wrappers conditionally on CONFIG_64BIT.

Arnd

2010-12-07 10:06:37

by Tilman Schmidt

[permalink] [raw]
Subject: Re: [PATCH 26/45] kstrtox: convert drivers/isdn/

Am 2010-12-06 21:10 schrieb Alexey Dobriyan:
> On Mon, Dec 06, 2010 at 01:10:45AM +0100, Tilman Schmidt wrote:
>> I like the patch, but why not go all the way?
>>
>> Am 05.12.2010 18:49 schrieb Alexey Dobriyan:
>>> @@ -566,10 +566,10 @@ void gigaset_handle_modem_response(struct cardstate *cs)
>>> case RT_ZCAU:
>>> event->parameter = -1;
>>> if (curarg + 1 < params) {
>>> - unsigned long type, value;
>>> + u8 type, value;
>>>
>>> - i = strict_strtoul(argv[curarg++], 16, &type);
>>> - j = strict_strtoul(argv[curarg++], 16, &value);
>>> + i = kstrtou8(argv[curarg++], 16, &type);
>>> + j = kstrtou8(argv[curarg++], 16, &value);
>>>
>>> if (i == 0 && type < 256 &&
>>> j == 0 && value < 256)
>>
>> Once type and value are u8, the checks for < 256 are unnecessary.
>
> OK.
>
>>> @@ -583,7 +583,7 @@ void gigaset_handle_modem_response(struct cardstate *cs)
>>> unsigned long res;
>>> int rc;
>>>
>>> - rc = strict_strtoul(argv[curarg++], 10, &res);
>>> + rc = kstrtoul(argv[curarg++], 10, &res);
>>> if (rc == 0)
>>> event->parameter = res;
>>> }
>>
>> The new kstrtoul() promises not to touch the result field in the event
>> of a conversion error, so &event->parameter can be passed directly to
>> it, getting rid of the variables rc and res and the if statement.
>
> What should be done in case of error?

The same as now: leave event->parameter alone. It's preset to -1
which will later be interpreted as "erroneous or missing value".

> Compiler will warn if kstrto*() result is unused:
>
> kstrtoul(argv[curarg++], 10, &event->parameter);

That's annoying of course. Perhaps silence the warning with some
innocuous pro forma activity like emitting a message:

if (kstrtoul(argv[curarg++], 10, &event->parameter))
dev_warn(cs->dev, "bad number");

Or rearrange the code to assign -1 only after an error is
detected, like so:

@@ -578,15 +578,9 @@ void gigaset_handle_modem_response(struct cardstate *cs)
curarg = params - 1;
break;
case RT_NUMBER:
- event->parameter = -1;
- if (curarg < params) {
- unsigned long res;
- int rc;
-
- rc = strict_strtoul(argv[curarg++], 10, &res);
- if (rc == 0)
- event->parameter = res;
- }
+ if (curarg >= params ||
+ kstrtoul(argv[curarg], 10, &event->parameter))
+ event->parameter = -1;
gig_dbg(DEBUG_EVENT, "parameter==%d", event->parameter);
break;
}

Thanks,
Tilman

--
Tilman Schmidt
Phoenix Software GmbH
Bonn, Germany

2010-12-08 08:51:54

by Alexey Dobriyan

[permalink] [raw]
Subject: Re: [PATCH 01/45] kstrtox: converting strings to integers done (hopefully) right

On Tue, Dec 07, 2010 at 10:45:33AM +0100, Arnd Bergmann wrote:
> On Tuesday 07 December 2010 10:32:29 Alexey Dobriyan wrote:
> > On Tue, Dec 07, 2010 at 10:04:58AM +0100, Arnd Bergmann wrote:
> > > On Monday 06 December 2010 16:16:36 Alexey Dobriyan wrote:
> > >
> > > > It is used by kstrtol() if "long" and "long long" aren't the same type.
> > > > I can't ifdef it because gcc doesn't allow "#if sizeof(long long) == ".
> > > > "Do not use" hints "use kstrtol()".
> > >
> > > Can't you use #ifdef CONFIG_64BIT to see if long is 64 bit wide?
> >
> > I could, but there are no defines for alignment.
>
> Not sure what you mean here.

One can't write:

#if sizeof(long) == sizeof(long long) && alignof(long) == alignof(long long)

and there are no _ALIGNOF_LONG or something like that.

> All architectures always naturally align 'long' variables --
> we rely on that elsewhere already. 'long long' is misaligned on x86-32 and
> possibly some other 32 bit architectures, but since that should not cause
> any problems.

The point is that code as written doesn't care and correct wrt alignment.

> Another option would be to export just the strto{u,s}{8,16,32,64}
> functions and define the inline wrappers conditionally on CONFIG_64BIT.

This means more ifdefs. Maybe someone could ifdeflessly fix this later.