linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: linux-iio@vger.kernel.org
Cc: jbrenner@taosinc.com, Jonathan Cameron <jic23@kernel.org>
Subject: [PATCH 3/3] staging:iio:light:tsl2583 switch to kstrto and strtobool
Date: Sat, 12 Jan 2013 10:42:19 +0000	[thread overview]
Message-ID: <1357987339-11800-4-git-send-email-jic23@kernel.org> (raw)
In-Reply-To: <1357987339-11800-1-git-send-email-jic23@kernel.org>

Doing this results in cleaner code and better error handling.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/light/tsl2583.c | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 944db26..dfae0f7 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -493,15 +493,17 @@ 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_to_iio_dev(dev);
-	unsigned long value;
+	bool state;
+	int ret;
 
-	if (strict_strtoul(buf, 0, &value))
-		return -EINVAL;
+	ret = strtobool(buf, &state);
+	if (ret < 0)
+		return ret;
 
-	if (value == 0)
-		taos_chip_off(indio_dev);
-	else
+	if (state)
 		taos_chip_on(indio_dev);
+	else
+		taos_chip_off(indio_dev);		
 
 	return len;
 }
@@ -527,9 +529,11 @@ static ssize_t taos_als_time_store(struct device *dev,
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct tsl2583_chip *chip = iio_priv(indio_dev);
 	unsigned long value;
+	int ret;
 
-	if (strict_strtoul(buf, 0, &value))
-		return -EINVAL;
+	ret = kstrtoul(buf, 0, &value);
+	if (ret < 0)
+		return ret;
 
 	if ((value < 50) || (value > 650))
 		return -EINVAL;
@@ -564,9 +568,11 @@ static ssize_t taos_als_cal_target_store(struct device *dev,
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct tsl2583_chip *chip = iio_priv(indio_dev);
 	unsigned long value;
+	int ret;
 
-	if (strict_strtoul(buf, 0, &value))
-		return -EINVAL;
+	ret = kstrtoul(buf, 0, &value);
+	if (ret < 0)
+		return ret;
 
 	if (value)
 		chip->taos_settings.als_cal_target = value;
@@ -578,12 +584,14 @@ 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_to_iio_dev(dev);
-	unsigned long value;
+	bool cal;
+	int ret;
 
-	if (strict_strtoul(buf, 0, &value))
-		return -EINVAL;
+	ret = strtobool(buf, &cal);
+	if (ret < 0)
+		return ret;
 
-	if (value == 1)
+	if (cal)
 		taos_als_calibrate(indio_dev);
 
 	return len;
-- 
1.8.1


  parent reply	other threads:[~2013-01-12 10:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-12 10:42 [PATCH 0/3 V2] staging:iio:tsl2583 update interfaces Jonathan Cameron
2013-01-12 10:42 ` [PATCH 1/3] staging:iio:light:tsl2583 use read_raw, write_raw hooks Jonathan Cameron
2013-01-12 10:42 ` [PATCH 2/3] staging:iio:light:tsl2583 apply in_ prefix to attributes Jonathan Cameron
2013-01-12 10:42 ` Jonathan Cameron [this message]
2013-01-20 12:10 ` [PATCH 0/3 V2] staging:iio:tsl2583 update interfaces Jonathan Cameron
  -- strict thread matches above, loose matches on Subject: below --
2013-01-06 16:23 [PATCH 0/3] " Jonathan Cameron
2013-01-06 16:23 ` [PATCH 3/3] staging:iio:light:tsl2583 switch to kstrto and strtobool Jonathan Cameron
2013-01-12 10:31   ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1357987339-11800-4-git-send-email-jic23@kernel.org \
    --to=jic23@kernel.org \
    --cc=jbrenner@taosinc.com \
    --cc=linux-iio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).