linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* staging: iio: light: obsolete use of strict_strtoul v2
@ 2011-12-12 23:38 Johannes Tenschert
  2011-12-12 23:38 ` [PATCH v2 1/2] staging: iio: light: isl29018.c: obsolete use of strict_strtoul Johannes Tenschert
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Johannes Tenschert @ 2011-12-12 23:38 UTC (permalink / raw)
  To: devel; +Cc: jic23, gregkh, jbrenner, linux-iio

Hi,

I changed the patch to use the right kstrto* as Dan Carpenter suggested, but
I'm not familiar enough with the code to fix the divide by zero bug in a good
way.

I also didn't change taos_settings because I don't know it well enough and don't
want to introduce new bugs. So kstrtoint was used provisional to set it.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] staging: iio: light: isl29018.c: obsolete use of strict_strtoul
  2011-12-12 23:38 staging: iio: light: obsolete use of strict_strtoul v2 Johannes Tenschert
@ 2011-12-12 23:38 ` Johannes Tenschert
  2011-12-12 23:38 ` [PATCH v2 2/2] staging: iio: light: tsl2583.c: " Johannes Tenschert
  2011-12-13  6:33 ` staging: iio: light: obsolete use of strict_strtoul v2 Dan Carpenter
  2 siblings, 0 replies; 5+ messages in thread
From: Johannes Tenschert @ 2011-12-12 23:38 UTC (permalink / raw)
  To: devel; +Cc: jic23, gregkh, jbrenner, linux-iio, Johannes Tenschert

The function strict_strtoul is obsolete and replaced by kstrtoul
and kstrtoint.

If kstrto* fails its return code is returned instead of -EINVAL.

Signed-off-by: Johannes Tenschert <Johannes.Tenschert@informatik.stud.uni-erlangen.de>
---
 drivers/staging/iio/light/isl29018.c |   24 +++++++++++++++---------
 1 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/iio/light/isl29018.c b/drivers/staging/iio/light/isl29018.c
index 849d6a5..9806495 100644
--- a/drivers/staging/iio/light/isl29018.c
+++ b/drivers/staging/iio/light/isl29018.c
@@ -253,9 +253,11 @@ static ssize_t store_range(struct device *dev,
 	int status;
 	unsigned long lval;
 	unsigned int new_range;
+	int ret;
 
-	if (strict_strtoul(buf, 10, &lval))
-		return -EINVAL;
+	ret = kstrtoul(buf, 10, &lval);
+	if (ret)
+		return ret;
 
 	if (!(lval == 1000UL || lval == 4000UL ||
 			lval == 16000UL || lval == 64000UL)) {
@@ -295,9 +297,11 @@ static ssize_t store_resolution(struct device *dev,
 	int status;
 	unsigned long lval;
 	unsigned int new_adc_bit;
+	int ret;
 
-	if (strict_strtoul(buf, 10, &lval))
-		return -EINVAL;
+	ret = kstrtoul(buf, 10, &lval);
+	if (ret)
+		return ret;
 	if (!(lval == 4 || lval == 8 || lval == 12 || lval == 16)) {
 		dev_err(dev, "The resolution is not supported\n");
 		return -EINVAL;
@@ -333,11 +337,13 @@ static ssize_t store_prox_infrared_supression(struct device *dev,
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct isl29018_chip *chip = iio_priv(indio_dev);
-	unsigned long lval;
+	int val;
+	int ret;
 
-	if (strict_strtoul(buf, 10, &lval))
-		return -EINVAL;
-	if (!(lval == 0UL || lval == 1UL)) {
+	ret = kstrtoint(buf, 10, &val);
+	if (ret)
+		return ret;
+	if (!(val == 0 || val == 1)) {
 		dev_err(dev, "The mode is not supported\n");
 		return -EINVAL;
 	}
@@ -345,7 +351,7 @@ static ssize_t store_prox_infrared_supression(struct device *dev,
 	/* get the  "proximity scheme" i.e. if the chip does on chip
 	infrared supression (1 means perform on chip supression) */
 	mutex_lock(&chip->lock);
-	chip->prox_scheme = (int)lval;
+	chip->prox_scheme = val;
 	mutex_unlock(&chip->lock);
 
 	return count;
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] staging: iio: light: tsl2583.c: obsolete use of strict_strtoul
  2011-12-12 23:38 staging: iio: light: obsolete use of strict_strtoul v2 Johannes Tenschert
  2011-12-12 23:38 ` [PATCH v2 1/2] staging: iio: light: isl29018.c: obsolete use of strict_strtoul Johannes Tenschert
@ 2011-12-12 23:38 ` Johannes Tenschert
  2011-12-13  6:33 ` staging: iio: light: obsolete use of strict_strtoul v2 Dan Carpenter
  2 siblings, 0 replies; 5+ messages in thread
From: Johannes Tenschert @ 2011-12-12 23:38 UTC (permalink / raw)
  To: devel; +Cc: jic23, gregkh, jbrenner, linux-iio, Johannes Tenschert

The function strict_strtoul is obsolete and replaced by kstrtouint
and kstrtoint.

If kstrto* fails its return code is returned instead of -EINVAL.

Signed-off-by: Johannes Tenschert <Johannes.Tenschert@informatik.stud.uni-erlangen.de>
---
 drivers/staging/iio/light/tsl2583.c |   48 +++++++++++++++++++++-------------
 1 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 5b6455a..8c751e0 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -493,10 +493,12 @@ static ssize_t taos_power_state_store(struct device *dev,
 	struct device_attribute *attr, const char *buf, size_t len)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
-	unsigned long value;
+	unsigned int value;
+	int ret;
 
-	if (strict_strtoul(buf, 0, &value))
-		return -EINVAL;
+	ret = kstrtouint(buf, 0, &value);
+	if (ret)
+		return ret;
 
 	if (value == 0)
 		taos_chip_off(indio_dev);
@@ -536,10 +538,12 @@ static ssize_t taos_gain_store(struct device *dev,
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct tsl2583_chip *chip = iio_priv(indio_dev);
-	unsigned long value;
+	unsigned int value;
+	int ret;
 
-	if (strict_strtoul(buf, 0, &value))
-		return -EINVAL;
+	ret = kstrtouint(buf, 0, &value);
+	if (ret)
+		return ret;
 
 	switch (value) {
 	case 1:
@@ -582,10 +586,12 @@ static ssize_t taos_als_time_store(struct device *dev,
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct tsl2583_chip *chip = iio_priv(indio_dev);
-	unsigned long value;
+	int value;
+	int ret;
 
-	if (strict_strtoul(buf, 0, &value))
-		return -EINVAL;
+	ret = kstrtoint(buf, 0, &value);
+	if (ret)
+		return ret;
 
 	if ((value < 50) || (value > 650))
 		return -EINVAL;
@@ -619,10 +625,12 @@ static ssize_t taos_als_trim_store(struct device *dev,
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct tsl2583_chip *chip = iio_priv(indio_dev);
-	unsigned long value;
+	int value;
+	int ret;
 
-	if (strict_strtoul(buf, 0, &value))
-		return -EINVAL;
+	ret = kstrtoint(buf, 0, &value);
+	if (ret)
+		return ret;
 
 	if (value)
 		chip->taos_settings.als_gain_trim = value;
@@ -644,10 +652,12 @@ static ssize_t taos_als_cal_target_store(struct device *dev,
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct tsl2583_chip *chip = iio_priv(indio_dev);
-	unsigned long value;
+	int value;
+	int ret;
 
-	if (strict_strtoul(buf, 0, &value))
-		return -EINVAL;
+	ret = kstrtoint(buf, 0, &value);
+	if (ret)
+		return ret;
 
 	if (value)
 		chip->taos_settings.als_cal_target = value;
@@ -671,10 +681,12 @@ static ssize_t taos_do_calibrate(struct device *dev,
 	struct device_attribute *attr, const char *buf, size_t len)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
-	unsigned long value;
+	unsigned int value;
+	int ret;
 
-	if (strict_strtoul(buf, 0, &value))
-		return -EINVAL;
+	ret = kstrtouint(buf, 0, &value);
+	if (ret)
+		return ret;
 
 	if (value == 1)
 		taos_als_calibrate(indio_dev);
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: staging: iio: light: obsolete use of strict_strtoul v2
  2011-12-12 23:38 staging: iio: light: obsolete use of strict_strtoul v2 Johannes Tenschert
  2011-12-12 23:38 ` [PATCH v2 1/2] staging: iio: light: isl29018.c: obsolete use of strict_strtoul Johannes Tenschert
  2011-12-12 23:38 ` [PATCH v2 2/2] staging: iio: light: tsl2583.c: " Johannes Tenschert
@ 2011-12-13  6:33 ` Dan Carpenter
  2011-12-14 20:11   ` Jonathan Cameron
  2 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2011-12-13  6:33 UTC (permalink / raw)
  To: Johannes Tenschert; +Cc: devel, linux-iio, gregkh, jic23, jbrenner

[-- Attachment #1: Type: text/plain, Size: 527 bytes --]

On Tue, Dec 13, 2011 at 12:38:20AM +0100, Johannes Tenschert wrote:
> Hi,
> 
> I changed the patch to use the right kstrto* as Dan Carpenter suggested, but
> I'm not familiar enough with the code to fix the divide by zero bug in a good
> way.
> 
> I also didn't change taos_settings because I don't know it well enough and don't
> want to introduce new bugs. So kstrtoint was used provisional to set it.

Yah, yah.  Neither of us know the code, so hopefully the iio people
can comment.

regards,
dan carpenter


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: staging: iio: light: obsolete use of strict_strtoul v2
  2011-12-13  6:33 ` staging: iio: light: obsolete use of strict_strtoul v2 Dan Carpenter
@ 2011-12-14 20:11   ` Jonathan Cameron
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2011-12-14 20:11 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Johannes Tenschert, devel, linux-iio, gregkh, jic23, jbrenner

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 12/13/2011 06:33 AM, Dan Carpenter wrote:
> On Tue, Dec 13, 2011 at 12:38:20AM +0100, Johannes Tenschert 
> wrote:
>> Hi,
>> 
>> I changed the patch to use the right kstrto* as Dan Carpenter 
>> suggested, but I'm not familiar enough with the code to fix the 
>> divide by zero bug in a good way.
>> 
>> I also didn't change taos_settings because I don't know it well 
>> enough and don't want to introduce new bugs. So kstrtoint was 
>> used provisional to set it.
> 
> Yah, yah.  Neither of us know the code, so hopefully the iio people
> can comment.
I'm feeling lazy lets leave it for Jon when he gets to it ;)

(bug description is with the previous version of this patch in Dan's
response where he cc'd various people in).

Jonathan

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJO6QLWAAoJEFSFNJnE9BaIvsYQALzcJmYzwfS6TSuKeWW/FIxt
zoddt9yjr/XP+nhLBxnPQo06hsgp8e0yxPIpe1xV+FFryb22eOLXXdCchbXSc5bE
UeKuwQjgtilLZYFAWxc5VvscaYtLvo82swyeDe8YldbQykXVYRuZcFebH2p1YQUU
ai3R7ykErgYft+39AwIaxS9irZoVte2+IhKazBuCs6JYebCJ3sBS6/5YFJDyI87Z
jLxPy69yhRBwv++rQ7gQwH1Z43DnYYfbxVbO/ZaD5we+2YnpAAc7IpSN4ZA5b34t
KdyFBJlC1RTSZc9qQfI4Jm50JFGvFXwMxD6wdbpOjzwq6rjvrAYlk/W9GI9OtScN
fhgpC3mGBKO059jrO34JWNtbuwl3QLmfIuqCRKiUX+yeKGJQpSMxIron0E6Hf2m7
FKSHtjlflsyIXwH0w1AtDxzqBhcn+AWB5agyDBX3oZEeIOS8id41ISIFpYQEk5xH
H2zG7YTzWQQVBStQlCEpgzqbGg2JTGElQJifBk677pZ7F09MHLnZiK+qbnALBaqO
3rDBA9ZbZckohtm2YCHPiT8dTNfT2yby3XMG5y12VNxPnSNRN+HrOBYa5FLESY7d
rgl9vdCLhJUSxF68/t1WsAZ5l/box9gqjqIz1QjNBIi9J14uQvF4LklASI55GVWk
d/WsoXgigTeuWld24BRc
=aw+/
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-12-14 20:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-12 23:38 staging: iio: light: obsolete use of strict_strtoul v2 Johannes Tenschert
2011-12-12 23:38 ` [PATCH v2 1/2] staging: iio: light: isl29018.c: obsolete use of strict_strtoul Johannes Tenschert
2011-12-12 23:38 ` [PATCH v2 2/2] staging: iio: light: tsl2583.c: " Johannes Tenschert
2011-12-13  6:33 ` staging: iio: light: obsolete use of strict_strtoul v2 Dan Carpenter
2011-12-14 20:11   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).