Skip to contentSkip to conversation

kstrtox: converting strings to integers done (hopefully) right

PATCH In review Alexey Dobriyan 4 participants 54 messages Dec 5, 2010 – Dec 8, 2010

Subsystems (105)
lore
Share & tools
lore
#0 lore raw

PATCH 1/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.

---
 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
drivers/video/via/viafbdev.h +0 -3
index 4960e3d..57d77e1 100644
@@ -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);
include/linux/kernel.h +58 -4

72 lines not on this page · raw message

lib/Kconfig.debug +3 -0
index 28b42b9..64a6577 100644
@@ -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"
lib/Makefile +2 -0
index e6a3763..75b524a 100644
@@ -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
lib/kstrtox.c new file +227 -0

227 lines not on this page · raw message

lib/test-kstrtox.c new file +739 -0

739 lines not on this page · raw message

lib/vsprintf.c +0 -141

147 lines not on this page · raw message

scripts/checkpatch.pl +2 -2
index e3c7fc0..645e9f9 100755
@@ -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*\(/) {
Signature · 1 line
1.7.2.2
#1 lore raw

PATCH 2/45 kstrtox: convert arch/x86/

---
 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(-)
arch/x86/kernel/cpu/cpufreq/powernow-k8.c +8 -4
index 491977b..1b8380a 100644
@@ -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;
arch/x86/kernel/cpu/intel_cacheinfo.c +8 -7
index 17ad033..3647889 100644
@@ -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) {
arch/x86/kernel/cpu/mcheck/mce.c +14 -11
index 7a35b72..f868f80 100644
@@ -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) {
arch/x86/kernel/cpu/mcheck/mce_amd.c +8 -4
index 80c4823..27e1555 100644
@@ -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;
arch/x86/kvm/mmu_audit.c +3 -3
index ba2bcdd..64ffde1 100644
@@ -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:
arch/x86/platform/uv/tlb_uv.c +12 -7
index ba9caa8..0fc13d3 100644
@@ -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;
Signature · 1 line
1.7.2.2
#2 lore raw

PATCH 3/45 kstrtox: convert arch/arm/

In reply to Alexey Dobriyan

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

---
 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(-)
arch/arm/mach-omap2/board-omap3touchbook.c +0 -11
index 41104bb..6e57bda 100644
@@ -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,
arch/arm/mach-omap2/mux.c +6 -9
index 074536a..5e2886d 100644
@@ -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);
 		}
 	}
 
arch/arm/mach-pxa/balloon3.c +1 -1
index 21e1889..3748d65 100644
@@ -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);
 
arch/arm/mach-pxa/viper.c +1 -2
index 438fc9a..d99ee1b 100644
@@ -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);
arch/arm/mach-s3c2412/mach-jive.c +1 -1
index 923e01b..a21b119 100644
@@ -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;
 	}
arch/arm/mach-ux500/mbox.c +8 -19
index 6343538..946a6f5 100644
@@ -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);
arch/arm/mach-w90x900/cpu.c +3 -2
index 83c5632..67f015c 100644
@@ -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");
 
arch/arm/plat-omap/mcbsp.c +2 -2
index eac4b97..e049ad3 100644
@@ -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;						\
 									\
Signature · 1 line
1.7.2.2
#3 lore raw

PATCH 4/45 kstrtox: convert kernel/

In reply to Alexey Dobriyan
---
 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(-)
kernel/gcov/fs.c +1 -4
index 9bd0934..347c2b3 100644
@@ -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;
kernel/ksysfs.c +3 -2
index 0b624e7..b0b4681 100644
@@ -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;
kernel/params.c +11 -13
index 08107d1..7c3ecec 100644
@@ -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)
 {
kernel/power/main.c +5 -3
index 7b5db6a..c53c77e 100644
@@ -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;
Signature · 1 line
1.7.2.2
#4 lore raw

PATCH 5/45 kstrtox: kernel/trace/

In reply to Alexey Dobriyan
---
 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(-)
kernel/trace/ftrace.c +3 -3
index f3dadae..537fd31 100644
@@ -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;
 
kernel/trace/ring_buffer.c +1 -1
index 9ed509a..9ad99a6 100644
@@ -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;
 
kernel/trace/trace.c +8 -8
index c380612..8509b20 100644
@@ -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;
 
kernel/trace/trace_events.c +4 -4
index 0725eea..c7039a2 100644
@@ -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;
 
kernel/trace/trace_events_filter.c +2 -2
index 36d4010..f17f6a0 100644
@@ -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;
kernel/trace/trace_functions.c +2 -2
index 16aee4d..2f0dab3 100644
@@ -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:
kernel/trace/trace_kprobe.c +12 -13
index 2dec9bc..e29849d 100644
@@ -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;
 		}
kernel/trace/trace_stack.c +2 -2
index 4c5dead..36ebd3b 100644
@@ -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;
 
Signature · 1 line
1.7.2.2
#5 lore raw

PATCH 6/45 kstrtox: convert mm/

In reply to Alexey Dobriyan

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

---
 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(-)
include/linux/slub_def.h +1 -1
index e4f5ed1..37f439d 100644
@@ -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];
 };
mm/hugetlb.c +6 -6
index 8585524..a9a5460 100644
@@ -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;
mm/kmemleak.c +2 -2
index bd9bc21..b3fb3f5 100644
@@ -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();
mm/ksm.c +10 -18
index 43bc893..c03345b 100644
@@ -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;
 
mm/slub.c +10 -9
index 981fb73..3170e52 100644
@@ -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;
 }
mm/vmscan.c +10 -15
index d31d7ce..61acce3 100644
@@ -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)
Signature · 1 line
1.7.2.2
#6 lore raw

PATCH 7/45 kstrtox: convert fs/fuse/

In reply to Alexey Dobriyan
---
 fs/fuse/control.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
fs/fuse/control.c +2 -2
index 85542a7..b916b34 100644
@@ -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;
 
Signature · 1 line
1.7.2.2
#7 lore raw

PATCH 8/45 kstrtox: convert fs/nfs/

In reply to Alexey Dobriyan
---
 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(-)
fs/nfs/callback.c +5 -3
index 93a8b3b..05a9f3d 100644
@@ -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;
fs/nfs/idmap.c +4 -8
index 4e2d9b6..b3a915a 100644
@@ -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;
 }
 
fs/nfs/internal.h +4 -4
index e6356b7..f12ef9f 100644
@@ -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;
fs/nfs/super.c +33 -40

207 lines not on this page · raw message

Signature · 1 line
1.7.2.2
#8 lore raw

PATCH 9/45 kstrtox: convert fs/proc/

In reply to Alexey Dobriyan
---
 fs/proc/base.c     |   12 ++++++------
 fs/proc/task_mmu.c |    8 +++++---
 2 files changed, 11 insertions(+), 9 deletions(-)
fs/proc/base.c +6 -6
index f3d02ca..4469398 100644
@@ -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) {
fs/proc/task_mmu.c +5 -3
index c126c83..d6cd94a 100644
@@ -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);
Signature · 1 line
1.7.2.2
#9 lore raw

PATCH 10/45 kstrtox: convert security/

In reply to Alexey Dobriyan
---
 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(-)
security/apparmor/lsm.c +1 -1
index b7106f1..990ff86 100644
@@ -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;
security/integrity/ima/ima_audit.c +1 -1
index c5c5a72..b4a203c 100644
@@ -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;
 }
security/integrity/ima/ima_policy.c +4 -11
index aef8c0a..7958938 100644
@@ -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);
security/selinux/hooks.c +2 -2
index 65fa8bf..4ee09bd 100644
@@ -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;
 }
security/selinux/selinuxfs.c +1 -1
index 073fd5b..cdaf958 100644
@@ -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;
 }
security/tomoyo/common.c +5 -3
index 7556315..1096c81 100644
@@ -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;
Signature · 1 line
1.7.2.2
#10 lore raw

PATCH 11/45 kstrtox: convert block/

In reply to Alexey Dobriyan
---
 block/blk-cgroup.c |   47 ++++++++++++++++++++++++-----------------------
 1 files changed, 24 insertions(+), 23 deletions(-)
block/blk-cgroup.c +24 -23
index b1febd0..a18532a 100644
@@ -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;
Signature · 1 line
1.7.2.2
#11 lore raw

PATCH 12/45 kstrtox: convert drivers/acpi/

In reply to Alexey Dobriyan
---
 drivers/acpi/acpi_pad.c    |   27 ++++++++++++++++++---------
 drivers/acpi/power_meter.c |   16 +++++++---------
 2 files changed, 25 insertions(+), 18 deletions(-)
drivers/acpi/acpi_pad.c +18 -9
index 6afceb3..20d1c2d 100644
@@ -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);
drivers/acpi/power_meter.c +7 -9
index 66f6729..a468c33 100644
@@ -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;
Signature · 1 line
1.7.2.2
#12 lore raw

PATCH 13/45 kstrtox: convert drivers/ata/

In reply to Alexey Dobriyan
---
 drivers/ata/libata-scsi.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/ata/libata-scsi.c +1 -1
index 66aa4be..83d3cc0 100644
@@ -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) {
Signature · 1 line
1.7.2.2
#13 lore raw

PATCH 14/45 kstrtox: convert drivers/base/

In reply to Alexey Dobriyan
---
 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(-)
drivers/base/core.c +3 -3
index 6ed6454..f4862a4 100644
@@ -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
drivers/base/memory.c +6 -4
index cafeaaf..2dc57aa 100644
@@ -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;
drivers/base/power/sysfs.c +5 -4
index 0b1e46b..1397768 100644
@@ -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;
 }
include/linux/device.h +1 -1
index dd48953..f3474dc 100644
@@ -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
Signature · 1 line
1.7.2.2
#14 lore raw

PATCH 15/45 kstrtox: convert drivers/block/

In reply to Alexey Dobriyan
---
 drivers/block/osdblk.c |   10 ++--------
 drivers/block/rbd.c    |    8 +-------
 2 files changed, 3 insertions(+), 15 deletions(-)
drivers/block/osdblk.c +2 -8
index 87311eb..9a645ed 100644
@@ -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);
 
drivers/block/rbd.c +1 -7
index 008d4a0..e3baf92 100644
@@ -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);
Signature · 1 line
1.7.2.2
#15 lore raw

PATCH 16/45 kstrtox: convert drivers/bluetooth/

In reply to Alexey Dobriyan
---
 drivers/bluetooth/btmrvl_debugfs.c |   50 +++++++++++++++++------------------
 1 files changed, 24 insertions(+), 26 deletions(-)
drivers/bluetooth/btmrvl_debugfs.c +24 -26
index fd6305b..ffc4324 100644
@@ -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;
 }
 
Signature · 1 line
1.7.2.2
#16 lore raw

PATCH 17/45 kstrtox: convert drivers/clocksource/

In reply to Alexey Dobriyan
---
 drivers/clocksource/acpi_pm.c |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)
drivers/clocksource/acpi_pm.c +6 -8
index cfb0f52..2e77b1d 100644
@@ -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;
 
Signature · 1 line
1.7.2.2
#17 lore raw

PATCH 18/45 kstrtox: convert drivers/edac/

In reply to Alexey Dobriyan

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

---
 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(-)
drivers/edac/amd64_edac_inj.c +57 -87
index 29f1f7a..c66556c 100644
@@ -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,
drivers/edac/edac_mc_sysfs.c +11 -12
index dce61f7..644a5b6 100644
@@ -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;
 	}
 }
drivers/edac/i7core_edac.c +22 -19

95 lines not on this page · raw message

drivers/edac/mce_amd_inj.c +14 -19
index 39faded..794be1a 100644
@@ -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);
 
Signature · 1 line
1.7.2.2
#18 lore raw

PATCH 19/45 kstrtox: convert drivers/gpio/

In reply to Alexey Dobriyan
---
 drivers/gpio/gpiolib.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
drivers/gpio/gpiolib.c +6 -6
index 21da9c1..0eb79d9 100644
@@ -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;
 
Signature · 1 line
1.7.2.2
#19 lore raw

PATCH 20/45 kstrtox: convert drivers/gpu/drm/nouveau/

In reply to Alexey Dobriyan
---
 drivers/gpu/drm/nouveau/nouveau_pm.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
drivers/gpu/drm/nouveau/nouveau_pm.c +10 -6
index 9f7b158..a2cdef5 100644
@@ -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;
 
Signature · 1 line
1.7.2.2
#20 lore raw

PATCH 21/45 kstrtox: convert drivers/hid/

In reply to Alexey Dobriyan
---
 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(-)
drivers/hid/hid-magicmouse.c +11 -3
index e6dc151..5107ee5 100644
@@ -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;
drivers/hid/hid-ntrig.c +30 -24

96 lines not on this page · raw message

drivers/hid/hid-roccat-kone.c +4 -4
index f776957..e0dd8f9 100644
@@ -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;
 
Signature · 1 line
1.7.2.2
#21 lore raw

PATCH 22/45 kstrtox: convert drivers/hwmon/

In reply to Alexey Dobriyan
---
 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(-)
drivers/hwmon/adcxx.c +5 -3
index fbdc765..b6367e8 100644
@@ -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;
drivers/hwmon/adm1031.c +3 -3
index 0683e6b..641a7e9 100644
@@ -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;
 
 	/*
drivers/hwmon/adt7411.c +5 -3
index f13c843..dbc35a8 100644
@@ -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);
drivers/hwmon/adt7462.c +62 -25

185 lines not on this page · raw message

drivers/hwmon/adt7470.c +55 -25

172 lines not on this page · raw message

drivers/hwmon/adt7475.c +47 -36

165 lines not on this page · raw message

drivers/hwmon/amc6821.c +29 -16

88 lines not on this page · raw message

drivers/hwmon/asc7621.c +53 -30

180 lines not on this page · raw message

drivers/hwmon/emc1403.c +10 -7
index 8dee3f3..5d6f7ea 100644
@@ -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);
drivers/hwmon/emc2103.c +18 -14
index af914ad..72bcc0e 100644
@@ -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) {
drivers/hwmon/f71882fg.c +31 -31

153 lines not on this page · raw message

drivers/hwmon/g760a.c +4 -2
index 1d6a6fa..32191de 100644
@@ -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));
drivers/hwmon/gpio-fan.c +17 -7
index f141a1d..5e7bc1e 100644
@@ -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) {
drivers/hwmon/ibmaem.c +2 -2
index eaee546..d84497b 100644
@@ -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)
drivers/hwmon/it87.c +73 -36

228 lines not on this page · raw message

drivers/hwmon/jc42.c +18 -16
index 340fc78..2f269f8 100644
@@ -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,
drivers/hwmon/lis3lv02d.c +5 -3
index 0cee73a..c681910 100644
@@ -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))
drivers/hwmon/lm73.c +2 -1
index 29b9030..0ab02a6 100644
@@ -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;
 
drivers/hwmon/lm75.c +2 -2
index f36eb80..dfddb06 100644
@@ -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);
drivers/hwmon/lm90.c +8 -8
index 812781c..34907f5 100644
@@ -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;
 
drivers/hwmon/lm95241.c +82 -94

197 lines not on this page · raw message

drivers/hwmon/pc87427.c +14 -6
index 9ec4daa..dea7260 100644
@@ -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);
drivers/hwmon/tmp102.c +3 -2
index 93187c3..f839a78 100644
@@ -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);
drivers/hwmon/tmp401.c +23 -14
index ad8d535..6e67bdb 100644
@@ -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;
 }
drivers/hwmon/w83791d.c +18 -10
index 400a88b..c588a76 100644
@@ -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:
drivers/hwmon/w83795.c +72 -37

228 lines not on this page · raw message

Signature · 1 line
1.7.2.2
#22 lore raw

PATCH 23/45 kstrtox: convert drivers/ide/

In reply to Alexey Dobriyan
---
 drivers/ide/ide-park.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
drivers/ide/ide-park.c +5 -3
index 88a380c..436ca71 100644
@@ -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;
Signature · 1 line
1.7.2.2
#23 lore raw

PATCH 24/45 kstrtox: convert drivers/infiniband/

In reply to Alexey Dobriyan
---
 drivers/infiniband/hw/nes/nes.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
drivers/infiniband/hw/nes/nes.c +5 -2
index 0c9f0aa..bae80e3 100644
@@ -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;
Signature · 1 line
1.7.2.2
#24 lore raw

PATCH 25/45 kstrtox: convert drivers/input/

In reply to Alexey Dobriyan
---
 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(-)
drivers/input/input-polldev.c +5 -3
index 10c9b0a..9003ad1 100644
@@ -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;
drivers/input/keyboard/atkbd.c +23 -10
index 11478eb..b01c7e7 100644
@@ -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) {
drivers/input/keyboard/lm8323.c +8 -12
index f7c2a16..79ca455 100644
@@ -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;
drivers/input/misc/adxl34x.c +7 -7
index de5900d..03b284a 100644
@@ -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[] = {
drivers/input/misc/ati_remote2.c +17 -14
index 0b0e9be..3226c9a 100644
@@ -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;
drivers/input/mouse/elantech.c +3 -7
index 04d9bf3..b3c788b 100644
@@ -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)
drivers/input/mouse/hgpk.c +11 -7
index 1d2205b..aea82af 100644
@@ -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)
drivers/input/mouse/logips2pp.c +6 -2
index c9983ae..c977ea9 100644
@@ -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);
drivers/input/mouse/psmouse-base.c +14 -17
index cd9d0c9..a53978c 100644
@@ -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;
 }
drivers/input/mouse/sentelic.c +42 -37

203 lines not on this page · raw message

drivers/input/mouse/sentelic.h +5 -5
index ed1395a..363df999 100644
@@ -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
drivers/input/mouse/trackpoint.c +11 -8
index 54b2fa8..daf74c4 100644
@@ -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)
drivers/input/tablet/aiptek.c +16 -18
index 0a619c5..6fb2ac2 100644
@@ -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;
 }
 
drivers/input/touchscreen/ad7877.c +8 -8
index a1952fc..dac8711 100644
@@ -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);
drivers/input/touchscreen/ad7879.c +2 -2
index bc3b518..d3e0b9c 100644
@@ -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);
drivers/input/touchscreen/ads7846.c +4 -2
index 14ea54b..3a02113 100644
@@ -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);
Signature · 1 line
1.7.2.2
#25 lore raw

PATCH 26/45 kstrtox: convert drivers/isdn/

In reply to Alexey Dobriyan
---
 drivers/isdn/gigaset/ev-layer.c    |   12 ++++++------
 drivers/isdn/hysdn/hysdn_proclog.c |   11 ++++-------
 2 files changed, 10 insertions(+), 13 deletions(-)
drivers/isdn/gigaset/ev-layer.c +6 -6
index a141876..7a9a07c 100644
@@ -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;
 			}
drivers/isdn/hysdn/hysdn_proclog.c +4 -7
index 2ee93d0..236cc7d 100644
@@ -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 */
 
Signature · 1 line
1.7.2.2
#26 lore raw

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:

Quoted 4 lines
drivers/isdn/gigaset/ev-layer.c +0 -0
@@ -566,10 +566,10 @@ void gigaset_handle_modem_response(struct cardstate *cs)
 		case RT_ZCAU:
 			event->parameter = -1;
 			if (curarg + 1 < params) {

drivers/isdn/gigaset/ev-layer.c void gigaset_handle_modem_response(struct cardstate *cs) · line 575

Quoted 10 lines
drivers/isdn/gigaset/ev-layer.c +3 -3
-				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.

drivers/isdn/gigaset/ev-layer.c void gigaset_handle_modem_response(struct cardstate *cs) · line 589

Quoted 9 lines
drivers/isdn/gigaset/ev-layer.c +1 -1
@@ -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

#27 lore raw

Re: [PATCH 26/45] kstrtox: convert drivers/isdn/

Quoted 15 lines · Tilman Schmidt

I like the patch, but why not go all the way?

Am 05.12.2010 18:49 schrieb Alexey Dobriyan:

Quoted 12 lines
drivers/isdn/gigaset/ev-layer.c +3 -3
@@ -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);
 
Quoted 4 lines

drivers/isdn/gigaset/ev-layer.c void gigaset_handle_modem_response(struct cardstate *cs) · line 575

Quoted 2 lines
drivers/isdn/gigaset/ev-layer.c +0 -0
 				if (i == 0 && type < 256 &&
 				    j == 0 && value < 256)

Once type and value are u8, the checks for < 256 are unnecessary.

OK.

Quoted 4 lines
Quoted 4 lines
drivers/isdn/gigaset/ev-layer.c +0 -0
@@ -583,7 +583,7 @@ void gigaset_handle_modem_response(struct cardstate *cs)
 				unsigned long res;
 				int rc;
 
Quoted 9 lines

drivers/isdn/gigaset/ev-layer.c void gigaset_handle_modem_response(struct cardstate *cs) · line 589

Quoted 5 lines
drivers/isdn/gigaset/ev-layer.c +1 -1
-				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);
#28 lore raw

Re: [PATCH 26/45] kstrtox: convert drivers/isdn/

Am 2010-12-06 21:10 schrieb Alexey Dobriyan:

Quoted 37 lines · Tilman Schmidt
Quoted 15 lines

I like the patch, but why not go all the way?

Am 05.12.2010 18:49 schrieb Alexey Dobriyan:

Quoted 12 lines
drivers/isdn/gigaset/ev-layer.c +3 -3
@@ -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);
 
Quoted 4 lines

drivers/isdn/gigaset/ev-layer.c void gigaset_handle_modem_response(struct cardstate *cs) · line 575

Quoted 2 lines
drivers/isdn/gigaset/ev-layer.c +0 -0
 				if (i == 0 && type < 256 &&
 				    j == 0 && value < 256)

Once type and value are u8, the checks for < 256 are unnecessary.

OK.

Quoted 4 lines
Quoted 4 lines
drivers/isdn/gigaset/ev-layer.c +0 -0
@@ -583,7 +583,7 @@ void gigaset_handle_modem_response(struct cardstate *cs)
 				unsigned long res;
 				int rc;
 
Quoted 9 lines

drivers/isdn/gigaset/ev-layer.c void gigaset_handle_modem_response(struct cardstate *cs) · line 589

Quoted 5 lines
drivers/isdn/gigaset/ev-layer.c +1 -1
-				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.

Quoted 1 line

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".

Quoted 3 lines

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

Signature · 3 lines
Tilman Schmidt
Phoenix Software GmbH
Bonn, Germany
#29 lore raw

PATCH 27/45 kstrtox: convert drivers/leds/

In reply to Alexey Dobriyan
---
 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(-)
drivers/leds/leds-bd2802.c +5 -5
index 19dc4b6..4248173 100644
@@ -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);					\
drivers/leds/leds-lp5521.c +5 -4
index 33facd0..1a3c43d 100644
@@ -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;
drivers/leds/leds-lp5523.c +6 -5
index 0cc4ead..c21ee86 100644
@@ -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)
drivers/leds/leds-netxbig.c +1 -1
index f2e51c1..b149f30 100644
@@ -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;
 
drivers/leds/leds-ns2.c +1 -1
index f77d48d..4027583 100644
@@ -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;
 
drivers/leds/leds-ss4200.c +2 -2
index 614ebeb..56b3ab8 100644
@@ -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;
 
Signature · 1 line
1.7.2.2
#30 lore raw

PATCH 28/45 kstrtox: convert drivers/md/

In reply to Alexey Dobriyan
---
 drivers/md/bitmap.c |   12 ++++----
 drivers/md/md.c     |   82 ++++++++++++++++++++++++++++++++++----------------
 drivers/md/raid5.c  |   16 ++++++----
 3 files changed, 72 insertions(+), 38 deletions(-)
drivers/md/bitmap.c +6 -6
index 5a1ffe3..99ad322 100644
@@ -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 ||
drivers/md/md.c +56 -26

158 lines not on this page · raw message

drivers/md/raid5.c +10 -6
index dc574f3..61d63fb 100644
@@ -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;
Signature · 1 line
1.7.2.2
#31 lore raw

PATCH 29/45 kstrtox: convert drivers/mfd/

In reply to Alexey Dobriyan
---
 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(-)
drivers/mfd/ab3100-core.c +4 -12
index 4193af5..5b1c8ac 100644
@@ -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);
 
drivers/mfd/ab3550-core.c +18 -30

106 lines not on this page · raw message

drivers/mfd/ab8500-debugfs.c +15 -26

113 lines not on this page · raw message

Signature · 1 line
1.7.2.2
#32 lore raw

PATCH 30/45 kstrtox: convert drivers/misc/

In reply to Alexey Dobriyan
---
 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(-)
drivers/misc/ad525x_dpot.c +1 -1
index 7cb9110..d0de26a 100644
@@ -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;
 
drivers/misc/apds9802als.c +4 -3
index 644d4cd..e6d0ebc 100644
@@ -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;
drivers/misc/apds990x.c +26 -19

89 lines not on this page · raw message

drivers/misc/bh1770glc.c +44 -28

145 lines not on this page · raw message

drivers/misc/bh1780gli.c +2 -2
index d5f3a3f..5faca8e 100644
@@ -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;
 
drivers/misc/bmp085.c +12 -19
index 63ee4c1..b656c36 100644
@@ -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);
drivers/misc/ep93xx_pwm.c +16 -17
index 46b3439..b7a653e 100644
@@ -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);
drivers/misc/hmc6352.c +4 -3
index 234bfca..8503368 100644
@@ -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);
drivers/misc/isl29003.c +20 -8
index a71e245..f66cda4 100644
@@ -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);
drivers/misc/isl29020.c +4 -3
index 307aada..4d63b37 100644
@@ -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;
 
drivers/misc/iwmc3200top/log.c +32 -44

146 lines not on this page · raw message

drivers/misc/sgi-gru/gruprocfs.c +4 -3
index 7768b87..c29500c 100644
@@ -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;
 }
 
drivers/misc/ti_dac7512.c +6 -4
index d3f229a..ef9fd33 100644
@@ -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;
Signature · 1 line
1.7.2.2
#33 lore raw

PATCH 31/45 kstrtox: convert drivers/mmc/

In reply to Alexey Dobriyan
---
 drivers/mmc/card/mmc_test.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/card/mmc_test.c +2 -2
index 21adc27..108b72c 100644
@@ -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);
Signature · 1 line
1.7.2.2
#34 lore raw

PATCH 32/45 kstrtox: convert drivers/net/

In reply to Alexey Dobriyan
---
 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(-)
drivers/net/can/janz-ican3.c +3 -2
index 6e533dc..51fd497 100644
@@ -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)
drivers/net/netxen/netxen_nic_main.c +2 -2
index e1d30d7..b2c79e7 100644
@@ -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))
drivers/net/qlcnic/qlcnic_main.c +2 -2
index a3dcd04..5c4e2db 100644
@@ -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))
drivers/net/stmmac/stmmac_main.c +16 -13
index 06bc603..8190289 100644
@@ -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;
 }
Signature · 1 line
1.7.2.2
#35 lore raw

PATCH 33/45 kstrtox: convert drivers/net/wireless/

In reply to Alexey Dobriyan
---
 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(-)
drivers/net/wireless/ath/ath9k/debug.c +8 -14
index 43e71a9..3a5aefb 100644
@@ -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);
drivers/net/wireless/iwlwifi/iwl-agn.c +16 -20
index c2636a7..47334bf 100644
@@ -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);
drivers/net/wireless/iwlwifi/iwl3945-base.c +6 -9
index 7edf8c2..5dae5bf 100644
@@ -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,
drivers/net/wireless/libertas/mesh.c +4 -3
index acf3bf6..0b61551 100644
@@ -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;
 
drivers/net/wireless/wl12xx/wl1271_debugfs.c +5 -10
index 66c2b90..9ba9418 100644
@@ -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;
 }
drivers/net/wireless/wl12xx/wl1271_main.c +2 -4
index 48a4b99..1a628e0 100644
@@ -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;
 
Signature · 1 line
1.7.2.2
#36 lore raw

PATCH 34/45 kstrtox: convert drivers/pci/

In reply to Alexey Dobriyan
---
 drivers/pci/hotplug/fakephp.c |    2 +-
 drivers/pci/pci-sysfs.c       |   45 ++++++++++++++++++++++------------------
 2 files changed, 26 insertions(+), 21 deletions(-)
drivers/pci/hotplug/fakephp.c +1 -1
index 17d10e2..aaf2529 100644
@@ -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)
drivers/pci/pci-sysfs.c +25 -20

108 lines not on this page · raw message

Signature · 1 line
1.7.2.2
#37 lore raw

PATCH 35/45 kstrtox: convert drivers/platform/x86/

In reply to Alexey Dobriyan
---
 drivers/platform/x86/classmate-laptop.c |    2 +-
 drivers/platform/x86/compal-laptop.c    |   14 ++++++--------
 2 files changed, 7 insertions(+), 9 deletions(-)
drivers/platform/x86/classmate-laptop.c +1 -1
index 341cbfe..07d7ce6 100644
@@ -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;
 
drivers/platform/x86/compal-laptop.c +6 -8
index 097083c..c4602a4 100644
@@ -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;
 
Signature · 1 line
1.7.2.2
#38 lore raw

PATCH 36/45 kstrtox: convert drivers/power/

In reply to Alexey Dobriyan
---
 drivers/power/pcf50633-charger.c   |    4 ++--
 drivers/power/power_supply_sysfs.c |    6 +-----
 2 files changed, 3 insertions(+), 7 deletions(-)
drivers/power/pcf50633-charger.c +2 -2
index 4fa52e1..b6d9281 100644
@@ -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;
 
drivers/power/power_supply_sysfs.c +1 -5
index cd1f907..15d2d4a 100644
@@ -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;
Signature · 1 line
1.7.2.2
#39 lore raw

PATCH 37/45 kstrtox: convert drivers/regulator/

In reply to Alexey Dobriyan
---
 drivers/regulator/virtual.c |   32 ++++++++++++++++++++------------
 1 files changed, 20 insertions(+), 12 deletions(-)
drivers/regulator/virtual.c +20 -12
index 69e550f..6e3eee2 100644
@@ -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);
 
Signature · 1 line
1.7.2.2
#40 lore raw

PATCH 38/45 kstrtox: convert drivers/rtc/

In reply to Alexey Dobriyan
---
 drivers/rtc/rtc-pcf2123.c |   23 +++++++++++------------
 1 files changed, 11 insertions(+), 12 deletions(-)
drivers/rtc/rtc-pcf2123.c +11 -12
index 71bab0e..9e08179 100644
@@ -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;
Signature · 1 line
1.7.2.2
#41 lore raw

PATCH 39/45 kstrtox: convert drivers/scsi/

In reply to Alexey Dobriyan
---
 drivers/scsi/pmcraid.c    |    2 +-
 drivers/scsi/scsi_sysfs.c |    9 +++++----
 2 files changed, 6 insertions(+), 5 deletions(-)
drivers/scsi/pmcraid.c +1 -1
index 5e76a62..3957c63 100644
@@ -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)
drivers/scsi/scsi_sysfs.c +5 -4
index 76ee2e7..04d99c3 100644
@@ -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;
 }
Signature · 1 line
1.7.2.2
#42 lore raw

PATCH 40/45 kstrtox: convert drivers/ssb/

In reply to Alexey Dobriyan
---
 drivers/ssb/sprom.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
drivers/ssb/sprom.c +4 -3
index 4f7cc8d..fea2ac4 100644
@@ -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;
Signature · 1 line
1.7.2.2
#43 lore raw

PATCH 41/45 kstrtox: convert drivers/usb/

In reply to Alexey Dobriyan
---
 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(-)
drivers/usb/gadget/storage_common.c +4 -3
index 3b513ba..b7c7df9 100644
@@ -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 */
drivers/usb/host/ehci-dbg.c +3 -3
index 6e25996..34e263b 100644
@@ -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)) {
drivers/usb/serial/iuu_phoenix.c +10 -17
index 12ed594..0d23f3d 100644
@@ -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;
 }
 
Signature · 1 line
1.7.2.2
#44 lore raw

PATCH 42/45 kstrtox: convert drivers/video/

In reply to Alexey Dobriyan
---
 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(-)
drivers/video/backlight/adp5520_bl.c +8 -5
index 9f436e0..497d0a7 100644
@@ -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,
drivers/video/backlight/adp8860_bl.c +7 -5
index 734c650..6cfbb5f 100644
@@ -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;
 
drivers/video/backlight/backlight.c +2 -2
index 0870329..e6cd673 100644
@@ -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;
 
drivers/video/backlight/s6e63m0.c +1 -1
index 5927db0..8bbbc4a 100644
@@ -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;
 
drivers/video/fsl-diu-fb.c +24 -12
index 8bbbf08..88ffbac 100644
@@ -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,
drivers/video/omap2/displays/panel-tpo-td043mtea1.c +6 -4
index dbe9d43..77a363b 100644
@@ -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;
drivers/video/omap2/dss/display.c +8 -8
index 22dd7a4..413b618 100644
@@ -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;
 }
drivers/video/via/viafbdev.c +95 -60

244 lines not on this page · raw message

Signature · 1 line
1.7.2.2
#45 lore raw

PATCH 43/45 kstrtox: convert drivers/w1/

In reply to Alexey Dobriyan
---
 drivers/w1/w1.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
drivers/w1/w1.c +4 -4
index b7b5014..cd3d308 100644
@@ -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);
Signature · 1 line
1.7.2.2
#46 lore raw

PATCH 44/45 kstrtox: convert sound/

In reply to Alexey Dobriyan
---
 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(-)
sound/drivers/dummy.c +1 -1
index 7f41990..d3b1a02 100644
@@ -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;
sound/pci/hda/hda_hwdep.c +4 -6
index bf3ced5..ecc7edb 100644
@@ -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);
sound/pci/hda/patch_sigmatel.c +2 -5
index efa4225..0fedc41 100644
@@ -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;
 }
sound/soc/codecs/wm8962.c +2 -2
index e809274..f1f76d8 100644
@@ -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;
 
sound/soc/soc-core.c +3 -3
index 441285a..3cdf2d2 100644
@@ -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;
Signature · 1 line
1.7.2.2
#47 lore raw

PATCH 45/45 kstrtox: convert net/

In reply to Alexey Dobriyan
---
 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(-)
net/bluetooth/hci_sysfs.c +8 -8
index 5fce3d6..131ce95 100644
@@ -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)
net/dns_resolver/dns_key.c +3 -2
index 739435a..8cd5294 100644
@@ -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;
 
net/mac80211/debugfs.c +4 -6
index 18260aa..149efdd 100644
@@ -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;
 
net/rfkill/core.c +5 -6
index 04f5990..fd55757 100644
@@ -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;
 
net/sunrpc/addr.c +7 -11
index 1419d0c..36c554c 100644
@@ -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)
net/sunrpc/auth.c +3 -3
index afe6784..79737b2 100644
@@ -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++;
net/sunrpc/xprtsock.c +5 -3
index dfcab5a..04d1496 100644
@@ -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;
Signature · 1 line
1.7.2.2
#48 lore raw
In reply to Alexey Dobriyan
Quoted 39 lines · Alexey Dobriyan

1. simple_strto*() do not contain overflow checks and crufty, libc way to indicate failure.
2. strict_strto*() also do not have overflow checks but the name and comments pretend they do.
3. Both families have only "long long" and "long" variants, but users want strtou8()
4. Both "simple" and "strict" prefixes are wrong:
Simple doesn't exactly say what's so simple, strict should not exist because conversion should be strict by default.

The solution is to use "k" prefix and add convertors for more types. Enter

	kstrtoull()
	kstrtoll()
	kstrtoul()
	kstrtol()
	kstrtouint()
	kstrtoint()
	kstrtou64()
	kstrtos64()
	kstrtou32()
	kstrtos32()
	kstrtou16()
	kstrtos16()
	kstrtou8()
	kstrtos8()

Include runtime testsuite (somewhat incomplete) as well.

strict_strto*() become deprecated, stubbed to kstrto*() and eventually will be removed altogether.

Use kstrto*() in code today!

Note: sizeof and __alignof__ trick is done to save function call
where types aren't distinguishable.

---

<snip>

Quoted 5 lines
lib/kstrtox.c new file +5 -0
+/* Internal, do not use. */
+int _kstrtol(const char *s, unsigned int base, long *res)
+{
+	long long tmp;
+	int rv;

lib/kstrtox.c line 137

Quoted 10 lines
lib/kstrtox.c new file +10 -0
+
+	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

#49 lore raw
Quoted 21 lines · Jesper Juhl
Quoted 5 lines · Alexey Dobriyan

Note: sizeof and __alignof__ trick is done to save function call where types aren't distinguishable.

---

<snip>

Quoted 14 lines
lib/kstrtox.c new file +14 -0
+/* 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;
+}
Quoted 8 lines
Quoted 1 line

+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()".

maintainer
#50 lore raw
Quoted 24 lines · On Monday 06 December 2010 16:16:36 Alexey Dobriyan wrote:
Quoted 15 lines

<snip>

Quoted 14 lines
lib/kstrtox.c new file +14 -0
+/* 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;
+}
Quoted 8 lines
Quoted 1 line

+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).

Quoted 3 lines

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

#51 lore raw
Quoted 25 lines · Arnd Bergmann
Quoted 24 lines · On Monday 06 December 2010 16:16:36 Alexey Dobriyan wrote:
Quoted 23 lines

<snip>

Quoted 5 lines
lib/kstrtox.c new file +5 -0
+/* Internal, do not use. */
+int _kstrtol(const char *s, unsigned int base, long *res)
+{
+     long long tmp;
+     int rv;

lib/kstrtox.c line 137

Quoted 10 lines
lib/kstrtox.c new file +10 -0
+
+     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).

Quoted 5 lines
Quoted 3 lines

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.

maintainer
#52 lore raw
Quoted 10 lines · On Tuesday 07 December 2010 10:32:29 Alexey Dobriyan wrote:
Quoted 7 lines · Arnd Bergmann
Quoted 3 lines · 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

#53 lore raw
Quoted 8 lines · Arnd Bergmann
Quoted 7 lines · On Tuesday 07 December 2010 10:32:29 Alexey Dobriyan wrote:
Quoted 6 lines · Arnd Bergmann
Quoted 3 lines · 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()".

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

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.

Quoted 4 lines

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.

Quoted 2 lines

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.