From: Jean Delvare <khali@linux-fr.org>
To: Giel van Schijndel <me@mortis.eu>
Cc: Hans de Goede <hdegoede@redhat.com>,
Jonathan Cameron <jic23@cam.ac.uk>,
lm-sensors@lm-sensors.org, linux-kernel@vger.kernel.org
Subject: Re: [lm-sensors] [PATCH 2/2] Hwmon: f71882fg: use strict_stro(l|ul)
Date: Mon, 22 Mar 2010 10:23:08 +0000 [thread overview]
Message-ID: <20100322112308.13d58db4@hyperion.delvare> (raw)
In-Reply-To: <1269185834-10266-2-git-send-email-me@mortis.eu>
On Sun, 21 Mar 2010 16:37:14 +0100, Giel van Schijndel wrote:
> Use the strict_strol and strict_stroul functions instead of simple_strol
> and simple_stroul respectively in sysfs functions.
>
> Signed-off-by: Giel van Schijndel <me@mortis.eu>
> ---
> drivers/hwmon/f71882fg.c | 89 ++++++++++++++++++++++++++++++++++++++--------
> 1 files changed, 74 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c
> index 21bc661..5c725a3 100644
> --- a/drivers/hwmon/f71882fg.c
> +++ b/drivers/hwmon/f71882fg.c
> @@ -1128,7 +1128,10 @@ static ssize_t store_fan_full_speed(struct device *dev,
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - long val = simple_strtol(buf, NULL, 10);
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) = -EINVAL)
> + return -EINVAL;
That's not correct. You want to return an error if strict_strtol()
returns _any_ error, not just -EINVAL. Maybe the current implementation
can't return any other error code, but you should not assume this will
always be the case in the future.
>
> val = SENSORS_LIMIT(val, 23, 1500000);
> val = fan_to_reg(val);
> @@ -1158,7 +1161,10 @@ static ssize_t store_fan_beep(struct device *dev, struct device_attribute
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - unsigned long val = simple_strtoul(buf, NULL, 10);
> + unsigned long val;
> +
> + if (strict_strtoul(buf, 10, &val) = -EINVAL)
> + return -EINVAL;
>
> mutex_lock(&data->update_lock);
> data->fan_beep = f71882fg_read8(data, F71882FG_REG_FAN_BEEP);
> @@ -1206,7 +1212,12 @@ static ssize_t store_in_max(struct device *dev, struct device_attribute
> *devattr, const char *buf, size_t count)
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> - long val = simple_strtol(buf, NULL, 10) / 8;
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) = -EINVAL)
> + return -EINVAL;
> +
> + val /= 8;
> val = SENSORS_LIMIT(val, 0, 255);
>
> mutex_lock(&data->update_lock);
> @@ -1234,7 +1245,10 @@ static ssize_t store_in_beep(struct device *dev, struct device_attribute
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - unsigned long val = simple_strtoul(buf, NULL, 10);
> + unsigned long val;
> +
> + if (strict_strtoul(buf, 10, &val) = -EINVAL)
> + return -EINVAL;
>
> mutex_lock(&data->update_lock);
> data->in_beep = f71882fg_read8(data, F71882FG_REG_IN_BEEP);
> @@ -1300,7 +1314,12 @@ static ssize_t store_temp_max(struct device *dev, struct device_attribute
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - long val = simple_strtol(buf, NULL, 10) / 1000;
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) = -EINVAL)
> + return -EINVAL;
> +
> + val /= 1000;
> val = SENSORS_LIMIT(val, 0, 255);
>
> mutex_lock(&data->update_lock);
> @@ -1334,9 +1353,14 @@ static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - long val = simple_strtol(buf, NULL, 10) / 1000;
> ssize_t ret = count;
> u8 reg;
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) = -EINVAL)
> + return -EINVAL;
> +
> + val /= 1000;
>
> mutex_lock(&data->update_lock);
>
> @@ -1373,7 +1397,12 @@ static ssize_t store_temp_crit(struct device *dev, struct device_attribute
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - long val = simple_strtol(buf, NULL, 10) / 1000;
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) = -EINVAL)
> + return -EINVAL;
> +
> + val /= 1000;
> val = SENSORS_LIMIT(val, 0, 255);
>
> mutex_lock(&data->update_lock);
> @@ -1428,7 +1457,10 @@ static ssize_t store_temp_beep(struct device *dev, struct device_attribute
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - unsigned long val = simple_strtoul(buf, NULL, 10);
> + unsigned long val;
> +
> + if (strict_strtoul(buf, 10, &val) = -EINVAL)
> + return -EINVAL;
>
> mutex_lock(&data->update_lock);
> data->temp_beep = f71882fg_read8(data, F71882FG_REG_TEMP_BEEP);
> @@ -1491,7 +1523,11 @@ static ssize_t store_pwm(struct device *dev,
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - long val = simple_strtol(buf, NULL, 10);
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) = -EINVAL)
> + return -EINVAL;
> +
> val = SENSORS_LIMIT(val, 0, 255);
>
> mutex_lock(&data->update_lock);
> @@ -1552,7 +1588,10 @@ static ssize_t store_pwm_enable(struct device *dev, struct device_attribute
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - long val = simple_strtol(buf, NULL, 10);
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) = -EINVAL)
> + return -EINVAL;
>
> /* Special case for F8000 pwm channel 3 which only does auto mode */
> if (data->type = f8000 && nr = 2 && val != 2)
> @@ -1628,7 +1667,11 @@ static ssize_t store_pwm_auto_point_pwm(struct device *dev,
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int pwm = to_sensor_dev_attr_2(devattr)->index;
> int point = to_sensor_dev_attr_2(devattr)->nr;
> - long val = simple_strtol(buf, NULL, 10);
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) = -EINVAL)
> + return -EINVAL;
> +
> val = SENSORS_LIMIT(val, 0, 255);
>
> mutex_lock(&data->update_lock);
> @@ -1676,8 +1719,13 @@ static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> int point = to_sensor_dev_attr_2(devattr)->nr;
> - long val = simple_strtol(buf, NULL, 10) / 1000;
> u8 reg;
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) = -EINVAL)
> + return -EINVAL;
> +
> + val /= 1000;
>
> mutex_lock(&data->update_lock);
> data->pwm_auto_point_temp[nr][point] > @@ -1717,7 +1765,10 @@ static ssize_t store_pwm_interpolate(struct device *dev,
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - unsigned long val = simple_strtoul(buf, NULL, 10);
> + unsigned long val;
> +
> + if (strict_strtoul(buf, 10, &val) = -EINVAL)
> + return -EINVAL;
>
> mutex_lock(&data->update_lock);
> data->pwm_auto_point_mapping[nr] > @@ -1753,7 +1804,10 @@ static ssize_t store_pwm_auto_point_channel(struct device *dev,
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - long val = simple_strtol(buf, NULL, 10);
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) = -EINVAL)
> + return -EINVAL;
>
> switch (val) {
> case 1:
> @@ -1800,7 +1854,12 @@ static ssize_t store_pwm_auto_point_temp(struct device *dev,
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int pwm = to_sensor_dev_attr_2(devattr)->index;
> int point = to_sensor_dev_attr_2(devattr)->nr;
> - long val = simple_strtol(buf, NULL, 10) / 1000;
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) = -EINVAL)
> + return -EINVAL;
> +
> + val /= 1000;
>
> if (data->type = f71889fg)
> val = SENSORS_LIMIT(val, -128, 127);
--
Jean Delvare
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
WARNING: multiple messages have this Message-ID (diff)
From: Jean Delvare <khali@linux-fr.org>
To: Giel van Schijndel <me@mortis.eu>
Cc: Hans de Goede <hdegoede@redhat.com>,
Jonathan Cameron <jic23@cam.ac.uk>,
lm-sensors@lm-sensors.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] Hwmon: f71882fg: use strict_stro(l|ul) instead of simple_strto$1
Date: Mon, 22 Mar 2010 11:23:08 +0100 [thread overview]
Message-ID: <20100322112308.13d58db4@hyperion.delvare> (raw)
In-Reply-To: <1269185834-10266-2-git-send-email-me@mortis.eu>
On Sun, 21 Mar 2010 16:37:14 +0100, Giel van Schijndel wrote:
> Use the strict_strol and strict_stroul functions instead of simple_strol
> and simple_stroul respectively in sysfs functions.
>
> Signed-off-by: Giel van Schijndel <me@mortis.eu>
> ---
> drivers/hwmon/f71882fg.c | 89 ++++++++++++++++++++++++++++++++++++++--------
> 1 files changed, 74 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c
> index 21bc661..5c725a3 100644
> --- a/drivers/hwmon/f71882fg.c
> +++ b/drivers/hwmon/f71882fg.c
> @@ -1128,7 +1128,10 @@ static ssize_t store_fan_full_speed(struct device *dev,
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - long val = simple_strtol(buf, NULL, 10);
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) == -EINVAL)
> + return -EINVAL;
That's not correct. You want to return an error if strict_strtol()
returns _any_ error, not just -EINVAL. Maybe the current implementation
can't return any other error code, but you should not assume this will
always be the case in the future.
>
> val = SENSORS_LIMIT(val, 23, 1500000);
> val = fan_to_reg(val);
> @@ -1158,7 +1161,10 @@ static ssize_t store_fan_beep(struct device *dev, struct device_attribute
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - unsigned long val = simple_strtoul(buf, NULL, 10);
> + unsigned long val;
> +
> + if (strict_strtoul(buf, 10, &val) == -EINVAL)
> + return -EINVAL;
>
> mutex_lock(&data->update_lock);
> data->fan_beep = f71882fg_read8(data, F71882FG_REG_FAN_BEEP);
> @@ -1206,7 +1212,12 @@ static ssize_t store_in_max(struct device *dev, struct device_attribute
> *devattr, const char *buf, size_t count)
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> - long val = simple_strtol(buf, NULL, 10) / 8;
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) == -EINVAL)
> + return -EINVAL;
> +
> + val /= 8;
> val = SENSORS_LIMIT(val, 0, 255);
>
> mutex_lock(&data->update_lock);
> @@ -1234,7 +1245,10 @@ static ssize_t store_in_beep(struct device *dev, struct device_attribute
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - unsigned long val = simple_strtoul(buf, NULL, 10);
> + unsigned long val;
> +
> + if (strict_strtoul(buf, 10, &val) == -EINVAL)
> + return -EINVAL;
>
> mutex_lock(&data->update_lock);
> data->in_beep = f71882fg_read8(data, F71882FG_REG_IN_BEEP);
> @@ -1300,7 +1314,12 @@ static ssize_t store_temp_max(struct device *dev, struct device_attribute
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - long val = simple_strtol(buf, NULL, 10) / 1000;
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) == -EINVAL)
> + return -EINVAL;
> +
> + val /= 1000;
> val = SENSORS_LIMIT(val, 0, 255);
>
> mutex_lock(&data->update_lock);
> @@ -1334,9 +1353,14 @@ static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - long val = simple_strtol(buf, NULL, 10) / 1000;
> ssize_t ret = count;
> u8 reg;
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) == -EINVAL)
> + return -EINVAL;
> +
> + val /= 1000;
>
> mutex_lock(&data->update_lock);
>
> @@ -1373,7 +1397,12 @@ static ssize_t store_temp_crit(struct device *dev, struct device_attribute
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - long val = simple_strtol(buf, NULL, 10) / 1000;
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) == -EINVAL)
> + return -EINVAL;
> +
> + val /= 1000;
> val = SENSORS_LIMIT(val, 0, 255);
>
> mutex_lock(&data->update_lock);
> @@ -1428,7 +1457,10 @@ static ssize_t store_temp_beep(struct device *dev, struct device_attribute
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - unsigned long val = simple_strtoul(buf, NULL, 10);
> + unsigned long val;
> +
> + if (strict_strtoul(buf, 10, &val) == -EINVAL)
> + return -EINVAL;
>
> mutex_lock(&data->update_lock);
> data->temp_beep = f71882fg_read8(data, F71882FG_REG_TEMP_BEEP);
> @@ -1491,7 +1523,11 @@ static ssize_t store_pwm(struct device *dev,
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - long val = simple_strtol(buf, NULL, 10);
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) == -EINVAL)
> + return -EINVAL;
> +
> val = SENSORS_LIMIT(val, 0, 255);
>
> mutex_lock(&data->update_lock);
> @@ -1552,7 +1588,10 @@ static ssize_t store_pwm_enable(struct device *dev, struct device_attribute
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - long val = simple_strtol(buf, NULL, 10);
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) == -EINVAL)
> + return -EINVAL;
>
> /* Special case for F8000 pwm channel 3 which only does auto mode */
> if (data->type == f8000 && nr == 2 && val != 2)
> @@ -1628,7 +1667,11 @@ static ssize_t store_pwm_auto_point_pwm(struct device *dev,
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int pwm = to_sensor_dev_attr_2(devattr)->index;
> int point = to_sensor_dev_attr_2(devattr)->nr;
> - long val = simple_strtol(buf, NULL, 10);
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) == -EINVAL)
> + return -EINVAL;
> +
> val = SENSORS_LIMIT(val, 0, 255);
>
> mutex_lock(&data->update_lock);
> @@ -1676,8 +1719,13 @@ static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> int point = to_sensor_dev_attr_2(devattr)->nr;
> - long val = simple_strtol(buf, NULL, 10) / 1000;
> u8 reg;
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) == -EINVAL)
> + return -EINVAL;
> +
> + val /= 1000;
>
> mutex_lock(&data->update_lock);
> data->pwm_auto_point_temp[nr][point] =
> @@ -1717,7 +1765,10 @@ static ssize_t store_pwm_interpolate(struct device *dev,
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - unsigned long val = simple_strtoul(buf, NULL, 10);
> + unsigned long val;
> +
> + if (strict_strtoul(buf, 10, &val) == -EINVAL)
> + return -EINVAL;
>
> mutex_lock(&data->update_lock);
> data->pwm_auto_point_mapping[nr] =
> @@ -1753,7 +1804,10 @@ static ssize_t store_pwm_auto_point_channel(struct device *dev,
> {
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int nr = to_sensor_dev_attr_2(devattr)->index;
> - long val = simple_strtol(buf, NULL, 10);
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) == -EINVAL)
> + return -EINVAL;
>
> switch (val) {
> case 1:
> @@ -1800,7 +1854,12 @@ static ssize_t store_pwm_auto_point_temp(struct device *dev,
> struct f71882fg_data *data = dev_get_drvdata(dev);
> int pwm = to_sensor_dev_attr_2(devattr)->index;
> int point = to_sensor_dev_attr_2(devattr)->nr;
> - long val = simple_strtol(buf, NULL, 10) / 1000;
> + long val;
> +
> + if (strict_strtol(buf, 10, &val) == -EINVAL)
> + return -EINVAL;
> +
> + val /= 1000;
>
> if (data->type == f71889fg)
> val = SENSORS_LIMIT(val, -128, 127);
--
Jean Delvare
next prev parent reply other threads:[~2010-03-22 10:23 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-21 15:37 [lm-sensors] [PATCH 1/2] Hwmon: f71882fg: fixed braces coding style Giel van Schijndel
2010-03-21 15:37 ` [PATCH 1/2] Hwmon: f71882fg: fixed braces coding style issues Giel van Schijndel
2010-03-21 15:37 ` [lm-sensors] [PATCH 2/2] Hwmon: f71882fg: use strict_stro(l|ul) Giel van Schijndel
2010-03-21 15:37 ` [PATCH 2/2] Hwmon: f71882fg: use strict_stro(l|ul) instead of simple_strto$1 Giel van Schijndel
2010-03-22 9:30 ` [lm-sensors] [PATCH 2/2] Hwmon: f71882fg: use strict_stro(l|ul) Hans de Goede
2010-03-22 9:30 ` [PATCH 2/2] Hwmon: f71882fg: use strict_stro(l|ul) instead of simple_strto$1 Hans de Goede
2010-03-22 10:23 ` Jean Delvare [this message]
2010-03-22 10:23 ` Jean Delvare
2010-03-22 11:41 ` [lm-sensors] [PATCH 2/2] Hwmon: f71882fg: use strict_stro(l|ul) Giel van Schijndel
2010-03-22 11:41 ` [PATCH 2/2] Hwmon: f71882fg: use strict_stro(l|ul) instead of simple_strto$1 Giel van Schijndel
2010-03-23 10:59 ` [lm-sensors] [PATCH 2/2] Hwmon: f71882fg: use strict_stro(l|ul) Jean Delvare
2010-03-23 10:59 ` [PATCH 2/2] Hwmon: f71882fg: use strict_stro(l|ul) instead of simple_strto$1 Jean Delvare
2010-03-23 11:07 ` [lm-sensors] [PATCH 2/2] Hwmon: f71882fg: use strict_stro(l|ul) Hans de Goede
2010-03-23 11:07 ` [PATCH 2/2] Hwmon: f71882fg: use strict_stro(l|ul) instead of simple_strto$1 Hans de Goede
2010-03-22 9:30 ` [lm-sensors] [PATCH 1/2] Hwmon: f71882fg: fixed braces coding Hans de Goede
2010-03-22 9:30 ` [PATCH 1/2] Hwmon: f71882fg: fixed braces coding style issues Hans de Goede
2010-03-22 10:20 ` [lm-sensors] [PATCH 1/2] Hwmon: f71882fg: fixed braces coding Jean Delvare
2010-03-22 10:20 ` [PATCH 1/2] Hwmon: f71882fg: fixed braces coding style issues Jean Delvare
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=20100322112308.13d58db4@hyperion.delvare \
--to=khali@linux-fr.org \
--cc=hdegoede@redhat.com \
--cc=jic23@cam.ac.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=lm-sensors@lm-sensors.org \
--cc=me@mortis.eu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.