From: Jean Delvare <khali@linux-fr.org>
To: lm-sensors@vger.kernel.org
Subject: Re: [lm-sensors] [PATCH 11/12] adt7470: Check input range when
Date: Thu, 09 Oct 2008 09:09:54 +0000 [thread overview]
Message-ID: <20081009110954.2d5a9201@hyperion.delvare> (raw)
In-Reply-To: <20081007011919.12701.2422.stgit@elm3a70.beaverton.ibm.com>
Hi Darrick,
On Mon, 06 Oct 2008 18:19:19 -0700, Darrick J. Wong wrote:
>
No description for this patch? IMHO it's large enough to deserve one.
> Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
> ---
>
> drivers/hwmon/adt7470.c | 77 +++++++++++++++++++++++++++++++++++++++--------
> 1 files changed, 64 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
> index ef26014..5acc800 100644
> --- a/drivers/hwmon/adt7470.c
> +++ b/drivers/hwmon/adt7470.c
> @@ -345,6 +345,11 @@ static ssize_t show_temp_min(struct device *dev,
> return sprintf(buf, "%d\n", 1000 * data->temp_min[attr->index]);
> }
>
> +static int range_check(const long val, const long min, const long max)
> +{
> + return val >= min && val <= max;
> +}
Should definitely be inlined.
> +
> static ssize_t set_temp_min(struct device *dev,
> struct device_attribute *devattr,
> const char *buf,
> @@ -353,7 +358,14 @@ static ssize_t set_temp_min(struct device *dev,
> struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> struct i2c_client *client = to_i2c_client(dev);
> struct adt7470_data *data = i2c_get_clientdata(client);
> - int temp = simple_strtol(buf, NULL, 10) / 1000;
> + long temp;
> +
> + if (strict_strtol(buf, 10, &temp))
> + return -EINVAL;
> +
> + temp /= 1000;
While you're here, proper rounding would be welcome.
> + if (!range_check(temp, 0, 255))
> + return -EINVAL;
For temperature, voltage and fan speed values, the standard behavior is
best effort: we pick the nearest available value instead of returning
an error. We have a function for that: SENSORS_LIMIT(). Please use it.
Rationale: the boundaries for these values are chip-dependent so it
isn't fair to cause user commands to fail. We do range checks for
values which are normalized, such as PWM values (range 0-255 for all
chips) or when discrete values have specific meanings so picking the
nearest possible value makes no sense (e.g. PWM modes.)
>
> mutex_lock(&data->lock);
> data->temp_min[attr->index] = temp;
> @@ -381,7 +393,14 @@ static ssize_t set_temp_max(struct device *dev,
> struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> struct i2c_client *client = to_i2c_client(dev);
> struct adt7470_data *data = i2c_get_clientdata(client);
> - int temp = simple_strtol(buf, NULL, 10) / 1000;
> + long temp;
> +
> + if (strict_strtol(buf, 10, &temp))
> + return -EINVAL;
> +
> + temp /= 1000;
> + if (!range_check(temp, 0, 255))
> + return -EINVAL;
>
> mutex_lock(&data->lock);
> data->temp_max[attr->index] = temp;
> @@ -430,11 +449,14 @@ static ssize_t set_fan_max(struct device *dev,
> struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> struct i2c_client *client = to_i2c_client(dev);
> struct adt7470_data *data = i2c_get_clientdata(client);
> - int temp = simple_strtol(buf, NULL, 10);
> + long temp;
>
> - if (!temp)
> + if (strict_strtol(buf, 10, &temp) || !temp)
> return -EINVAL;
> +
> temp = FAN_RPM_TO_PERIOD(temp);
> + if (!range_check(temp, 0, 65535))
Do you really want to accept 0 as a valid value? show_fan_max() will
consider it an invalid value.
> + return -EINVAL;
>
> mutex_lock(&data->lock);
> data->fan_max[attr->index] = temp;
> @@ -465,11 +487,14 @@ static ssize_t set_fan_min(struct device *dev,
> struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> struct i2c_client *client = to_i2c_client(dev);
> struct adt7470_data *data = i2c_get_clientdata(client);
> - int temp = simple_strtol(buf, NULL, 10);
> + long temp;
>
> - if (!temp)
> + if (strict_strtol(buf, 10, &temp) || !temp)
> return -EINVAL;
> +
> temp = FAN_RPM_TO_PERIOD(temp);
> + if (!range_check(temp, 0, 65535))
Ditto.
> + return -EINVAL;
>
> mutex_lock(&data->lock);
> data->fan_min[attr->index] = temp;
> @@ -507,9 +532,12 @@ static ssize_t set_force_pwm_max(struct device *dev,
> {
> struct i2c_client *client = to_i2c_client(dev);
> struct adt7470_data *data = i2c_get_clientdata(client);
> - int temp = simple_strtol(buf, NULL, 10);
> + long temp;
> u8 reg;
>
> + if (strict_strtol(buf, 10, &temp))
> + return -EINVAL;
> +
> mutex_lock(&data->lock);
> data->force_pwm_max = temp;
> reg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG);
> @@ -537,7 +565,10 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr,
> struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> struct i2c_client *client = to_i2c_client(dev);
> struct adt7470_data *data = i2c_get_clientdata(client);
> - int temp = simple_strtol(buf, NULL, 10);
> + long temp;
> +
> + if (strict_strtol(buf, 10, &temp) || !range_check(temp, 0, 255))
> + return -EINVAL;
>
> mutex_lock(&data->lock);
> data->pwm[attr->index] = temp;
> @@ -564,7 +595,10 @@ static ssize_t set_pwm_max(struct device *dev,
> struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> struct i2c_client *client = to_i2c_client(dev);
> struct adt7470_data *data = i2c_get_clientdata(client);
> - int temp = simple_strtol(buf, NULL, 10);
> + long temp;
> +
> + if (strict_strtol(buf, 10, &temp) || !range_check(temp, 0, 255))
> + return -EINVAL;
>
> mutex_lock(&data->lock);
> data->pwm_max[attr->index] = temp;
> @@ -592,7 +626,10 @@ static ssize_t set_pwm_min(struct device *dev,
> struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> struct i2c_client *client = to_i2c_client(dev);
> struct adt7470_data *data = i2c_get_clientdata(client);
> - int temp = simple_strtol(buf, NULL, 10);
> + long temp;
> +
> + if (strict_strtol(buf, 10, &temp) || !range_check(temp, 0, 255))
> + return -EINVAL;
>
> mutex_lock(&data->lock);
> data->pwm_min[attr->index] = temp;
> @@ -630,7 +667,14 @@ static ssize_t set_pwm_tmin(struct device *dev,
> struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> struct i2c_client *client = to_i2c_client(dev);
> struct adt7470_data *data = i2c_get_clientdata(client);
> - int temp = simple_strtol(buf, NULL, 10) / 1000;
> + long temp;
> +
> + if (strict_strtol(buf, 10, &temp))
> + return -EINVAL;
> +
> + temp /= 1000;
> + if (!range_check(temp, 0, 255))
> + return -EINVAL;
>
> mutex_lock(&data->lock);
> data->pwm_tmin[attr->index] = temp;
> @@ -658,11 +702,14 @@ static ssize_t set_pwm_auto(struct device *dev,
> struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> struct i2c_client *client = to_i2c_client(dev);
> struct adt7470_data *data = i2c_get_clientdata(client);
> - int temp = simple_strtol(buf, NULL, 10);
> int pwm_auto_reg = ADT7470_REG_PWM_CFG(attr->index);
> int pwm_auto_reg_mask;
> + long temp;
> u8 reg;
>
> + if (strict_strtol(buf, 10, &temp))
> + return -EINVAL;
> +
> if (attr->index % 2)
> pwm_auto_reg_mask = ADT7470_PWM2_AUTO_MASK;
> else
> @@ -716,10 +763,14 @@ static ssize_t set_pwm_auto_temp(struct device *dev,
> struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> struct i2c_client *client = to_i2c_client(dev);
> struct adt7470_data *data = i2c_get_clientdata(client);
> - int temp = cvt_auto_temp(simple_strtol(buf, NULL, 10));
> int pwm_auto_reg = ADT7470_REG_PWM_AUTO_TEMP(attr->index);
> + long temp;
> u8 reg;
>
> + if (strict_strtol(buf, 10, &temp))
> + return -EINVAL;
> +
> + temp = cvt_auto_temp(temp);
> if (temp < 0)
> return temp;
>
Please send an updated patch.
Same comments apply to the adt7473 patch as well.
--
Jean Delvare
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
next prev parent reply other threads:[~2008-10-09 9:09 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-07 1:18 [PATCH 00/12] Various hwmon patches Darrick J. Wong
2008-10-07 1:18 ` [lm-sensors] " Darrick J. Wong
2008-10-07 1:18 ` [PATCH 01/12] hwmon: Define sysfs interface for energy consumption register Darrick J. Wong
2008-10-07 1:18 ` [lm-sensors] [PATCH 01/12] hwmon: Define sysfs interface for energy Darrick J. Wong
2008-10-08 8:09 ` [lm-sensors] [PATCH 01/12] hwmon: Define sysfs interface for energy consumption register Jean Delvare
2008-10-08 8:09 ` [lm-sensors] [PATCH 01/12] hwmon: Define sysfs interface for Jean Delvare
2008-10-07 1:18 ` [PATCH 02/12] adt7462: New hwmon driver Darrick J. Wong
2008-10-07 1:18 ` [lm-sensors] " Darrick J. Wong
2008-10-07 1:18 ` [PATCH 03/12] adt7473: Fix some bogosity in documentation file Darrick J. Wong
2008-10-07 1:18 ` [lm-sensors] [PATCH 03/12] adt7473: Fix some bogosity in Darrick J. Wong
2008-10-08 9:08 ` [lm-sensors] [PATCH 03/12] adt7473: Fix some bogosity in documentation file Jean Delvare
2008-10-08 9:08 ` [lm-sensors] [PATCH 03/12] adt7473: Fix some bogosity in Jean Delvare
2008-10-07 1:18 ` [PATCH 04/12] adt7470: Fix pwm*-auto-point* to be temp*-auto-point* Darrick J. Wong
2008-10-07 1:18 ` [lm-sensors] [PATCH 04/12] adt7470: Fix pwm*-auto-point* to be Darrick J. Wong
2008-10-08 9:25 ` [lm-sensors] [PATCH 04/12] adt7470: Fix pwm*-auto-point* to be temp*-auto-point* Jean Delvare
2008-10-08 9:25 ` [lm-sensors] [PATCH 04/12] adt7470: Fix pwm*-auto-point* to be Jean Delvare
2008-10-08 18:36 ` [lm-sensors] [PATCH 04/12] adt7470: Fix pwm*-auto-point* to Darrick J. Wong
2008-10-07 1:18 ` [PATCH 05/12] adt7470: Add documentation Darrick J. Wong
2008-10-07 1:18 ` [lm-sensors] " Darrick J. Wong
2008-10-08 9:46 ` Jean Delvare
2008-10-08 9:46 ` Jean Delvare
2008-10-08 18:50 ` Darrick J. Wong
2008-10-09 10:31 ` Jean Delvare
2008-10-09 21:25 ` Darrick J. Wong
2008-10-10 8:25 ` Jean Delvare
2008-10-07 1:18 ` [PATCH 06/12] adt7470: Load automatically on IntelliStation Z30 via DMI Darrick J. Wong
2008-10-07 1:18 ` [lm-sensors] [PATCH 06/12] adt7470: Load automatically on Darrick J. Wong
2008-10-08 11:08 ` [lm-sensors] [PATCH 06/12] adt7470: Load automatically on IntelliStation Z30 via DMI Jean Delvare
2008-10-08 11:08 ` [lm-sensors] [PATCH 06/12] adt7470: Load automatically on Jean Delvare
2008-10-07 1:18 ` [PATCH 07/12] ics932s401: New driver Darrick J. Wong
2008-10-07 1:18 ` [lm-sensors] " Darrick J. Wong
2008-10-08 11:09 ` Jean Delvare
2008-10-08 11:09 ` Jean Delvare
2008-10-08 18:26 ` Darrick J. Wong
2008-10-09 11:37 ` Jean Delvare
2008-10-07 1:19 ` [PATCH 08/12] i5k_amb: Load automatically on all 5000/5400 chipsets Darrick J. Wong
2008-10-07 1:19 ` [lm-sensors] [PATCH 08/12] i5k_amb: Load automatically on all Darrick J. Wong
2008-10-08 11:13 ` [lm-sensors] [PATCH 08/12] i5k_amb: Load automatically on all 5000/5400 chipsets Jean Delvare
2008-10-08 11:13 ` [lm-sensors] [PATCH 08/12] i5k_amb: Load automatically on all Jean Delvare
2008-10-08 18:19 ` [lm-sensors] [PATCH 08/12] i5k_amb: Load automatically on Darrick J. Wong
2008-10-09 11:43 ` [lm-sensors] [PATCH 08/12] i5k_amb: Load automatically on all Jean Delvare
2008-10-10 17:54 ` [lm-sensors] [PATCH 08/12] i5k_amb: Load automatically on Darrick J. Wong
2008-10-15 8:48 ` [lm-sensors] [PATCH 08/12] i5k_amb: Load automatically on all Jean Delvare
2008-10-07 1:19 ` [PATCH 09/12] ibmpex: Automatically load on IBM systems via DMI Darrick J. Wong
2008-10-07 1:19 ` [lm-sensors] [PATCH 09/12] ibmpex: Automatically load on IBM Darrick J. Wong
2008-10-08 12:01 ` [lm-sensors] [PATCH 09/12] ibmpex: Automatically load on IBM systems via DMI Jean Delvare
2008-10-08 12:01 ` [lm-sensors] [PATCH 09/12] ibmpex: Automatically load on IBM Jean Delvare
2008-10-08 14:33 ` [lm-sensors] [PATCH 09/12] ibmpex: Automatically load on IBM systems via DMI Christian Krafft
2008-10-08 14:33 ` [lm-sensors] [PATCH 09/12] ibmpex: Automatically load on IBM Christian Krafft
2008-10-08 18:09 ` [lm-sensors] [PATCH 09/12] ibmpex: Automatically load on Darrick J. Wong
2008-10-09 11:47 ` [lm-sensors] [PATCH 09/12] ibmpex: Automatically load on IBM Jean Delvare
2008-10-09 17:21 ` [lm-sensors] [PATCH 09/12] ibmpex: Automatically load on Darrick J. Wong
2008-10-07 1:19 ` [PATCH 10/12] ibmaem: Automatically load on IBM systems via DMI Darrick J. Wong
2008-10-07 1:19 ` [lm-sensors] [PATCH 10/12] ibmaem: Automatically load on IBM Darrick J. Wong
2008-10-07 1:19 ` [PATCH 11/12] adt7470: Check input range when sysfs files are written Darrick J. Wong
2008-10-07 1:19 ` [lm-sensors] [PATCH 11/12] adt7470: Check input range when sysfs Darrick J. Wong
2008-10-09 9:09 ` Jean Delvare [this message]
2008-10-07 1:19 ` [PATCH 12/12] adt7473: Check inputs from sysfs writes Darrick J. Wong
2008-10-07 1:19 ` [lm-sensors] " Darrick J. Wong
2008-10-07 1:27 ` [PATCH 00/12] Various hwmon patches Darrick J. Wong
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=20081009110954.2d5a9201@hyperion.delvare \
--to=khali@linux-fr.org \
--cc=lm-sensors@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 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.