All of lore.kernel.org
 help / color / mirror / Atom feed
* [lm-sensors] [PATCH] hwmon: (emc6w201) Fix DIV_ROUND_CLOSEST problem with unsigned divisors
@ 2012-12-19 14:44 Guenter Roeck
  2012-12-19 14:58 ` Jean Delvare
  2012-12-19 16:00 ` Guenter Roeck
  0 siblings, 2 replies; 3+ messages in thread
From: Guenter Roeck @ 2012-12-19 14:44 UTC (permalink / raw)
  To: lm-sensors

Result of DIV_ROUND_CLOSEST is undefined for negative dividends if the divisor
variable type is unsigned. Fix by declaring dividend as unsigned.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/emc6w201.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/emc6w201.c b/drivers/hwmon/emc6w201.c
index a98c917..c450c7d 100644
--- a/drivers/hwmon/emc6w201.c
+++ b/drivers/hwmon/emc6w201.c
@@ -208,10 +208,10 @@ static ssize_t set_in(struct device *dev, struct device_attribute *devattr,
 	int sf = to_sensor_dev_attr_2(devattr)->index;
 	int nr = to_sensor_dev_attr_2(devattr)->nr;
 	int err;
-	long val;
+	unsigned long val;
 	u8 reg;
 
-	err = kstrtol(buf, 10, &val);
+	err = kstrtoul(buf, 10, &val);
 	if (err < 0)
 		return err;
 
-- 
1.7.9.7


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

* Re: [lm-sensors] [PATCH] hwmon: (emc6w201) Fix DIV_ROUND_CLOSEST problem with unsigned divisors
  2012-12-19 14:44 [lm-sensors] [PATCH] hwmon: (emc6w201) Fix DIV_ROUND_CLOSEST problem with unsigned divisors Guenter Roeck
@ 2012-12-19 14:58 ` Jean Delvare
  2012-12-19 16:00 ` Guenter Roeck
  1 sibling, 0 replies; 3+ messages in thread
From: Jean Delvare @ 2012-12-19 14:58 UTC (permalink / raw)
  To: lm-sensors

On Wed, 19 Dec 2012 06:44:04 -0800, Guenter Roeck wrote:
> Result of DIV_ROUND_CLOSEST is undefined for negative dividends if the divisor
> variable type is unsigned. Fix by declaring dividend as unsigned.
> 
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
>  drivers/hwmon/emc6w201.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwmon/emc6w201.c b/drivers/hwmon/emc6w201.c
> index a98c917..c450c7d 100644
> --- a/drivers/hwmon/emc6w201.c
> +++ b/drivers/hwmon/emc6w201.c
> @@ -208,10 +208,10 @@ static ssize_t set_in(struct device *dev, struct device_attribute *devattr,
>  	int sf = to_sensor_dev_attr_2(devattr)->index;
>  	int nr = to_sensor_dev_attr_2(devattr)->nr;
>  	int err;
> -	long val;
> +	unsigned long val;
>  	u8 reg;
>  
> -	err = kstrtol(buf, 10, &val);
> +	err = kstrtoul(buf, 10, &val);
>  	if (err < 0)
>  		return err;
>  

Nack, sorry. Negative voltage input values must be supported (and
clamped to 0 if needs be). Rationale: the value written can result from
applying a compute formula, so the user may not even realize he/she is
trying to write a negative value.

Just change the type of nominal_mv to s16 or even int?

-- 
Jean Delvare

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

* Re: [lm-sensors] [PATCH] hwmon: (emc6w201) Fix DIV_ROUND_CLOSEST problem with unsigned divisors
  2012-12-19 14:44 [lm-sensors] [PATCH] hwmon: (emc6w201) Fix DIV_ROUND_CLOSEST problem with unsigned divisors Guenter Roeck
  2012-12-19 14:58 ` Jean Delvare
@ 2012-12-19 16:00 ` Guenter Roeck
  1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2012-12-19 16:00 UTC (permalink / raw)
  To: lm-sensors

On Wed, Dec 19, 2012 at 03:58:31PM +0100, Jean Delvare wrote:
> On Wed, 19 Dec 2012 06:44:04 -0800, Guenter Roeck wrote:
> > Result of DIV_ROUND_CLOSEST is undefined for negative dividends if the divisor
> > variable type is unsigned. Fix by declaring dividend as unsigned.
> > 
> > Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> > ---
> >  drivers/hwmon/emc6w201.c |    4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/hwmon/emc6w201.c b/drivers/hwmon/emc6w201.c
> > index a98c917..c450c7d 100644
> > --- a/drivers/hwmon/emc6w201.c
> > +++ b/drivers/hwmon/emc6w201.c
> > @@ -208,10 +208,10 @@ static ssize_t set_in(struct device *dev, struct device_attribute *devattr,
> >  	int sf = to_sensor_dev_attr_2(devattr)->index;
> >  	int nr = to_sensor_dev_attr_2(devattr)->nr;
> >  	int err;
> > -	long val;
> > +	unsigned long val;
> >  	u8 reg;
> >  
> > -	err = kstrtol(buf, 10, &val);
> > +	err = kstrtoul(buf, 10, &val);
> >  	if (err < 0)
> >  		return err;
> >  
> 
> Nack, sorry. Negative voltage input values must be supported (and
> clamped to 0 if needs be). Rationale: the value written can result from
> applying a compute formula, so the user may not even realize he/she is
> trying to write a negative value.
> 
> Just change the type of nominal_mv to s16 or even int?
> 
No problem, that was my other solution anyway. I'll send an updated patch in a
minute.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

end of thread, other threads:[~2012-12-19 16:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-19 14:44 [lm-sensors] [PATCH] hwmon: (emc6w201) Fix DIV_ROUND_CLOSEST problem with unsigned divisors Guenter Roeck
2012-12-19 14:58 ` Jean Delvare
2012-12-19 16:00 ` Guenter Roeck

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.