ADT746X: logical-bitwise & confusion in set_max_duty_at_crit()
logical-bitwise & confusion
---
drivers/hwmon/adt7473.c +1 -1
@@ -570,7 +570,7 @@ static ssize_t set_max_duty_at_crit(struct device *dev,struct i2c_client *client =to_i2c_client (dev);struct adt7473_data *data =i2c_get_clientdata (client);int temp =simple_strtol (buf,NULL ,10 ); - temp = temp &&0xFF ; + temp &=0xFF ;mutex_lock (&data->lock); data->max_duty_at_overheat = temp;
Quoted 8 lines · Colin Leroy
On Mon, 10 Mar 2008 01:04:33 +0100, Roel Kluin wrote:
Hi,
Quoted 1 line
logical-bitwise & confusion
Looks good to me, but I'm not really maintaining that anymore :-) I'm not sure who does, Cc:ing Benjamin as he'll probably know.
Nobody is U suspect...
Send it to the list [email protected], it should be picked up anyway.
Ben.
Quoted 17 lines
Quoted 16 lines
Signed-off-by Roel Kluin <[email protected]>---
drivers/hwmon/adt7473.c +1
-1@@ -570,7 +570,7 @@ static ssize_t set_max_duty_at_crit(struct device *dev, struct i2c_client *client = to_i2c_client(dev);struct adt7473_data *data =i2c_get_clientdata (client);int temp =simple_strtol (buf,NULL ,10 ); - temp = temp &&0xFF ; + temp &=0xFF ;mutex_lock (&data->lock); data->max_duty_at_overheat = temp;
On Mon, 10 Mar 2008 01:04:33 +0100, Roel Kluin wrote:
Hi,
Quoted 1 line
logical-bitwise & confusion
Looks good to me, but I'm not really maintaining that anymore :-) I'm not sure who does, Cc:ing Benjamin as he'll probably know.
Quoted 16 lines
Signed-off-by Roel Kluin <[email protected]>---
drivers/hwmon/adt7473.c +1
-1@@ -570,7 +570,7 @@ static ssize_t set_max_duty_at_crit(struct device *dev, struct i2c_client *client = to_i2c_client(dev);struct adt7473_data *data =i2c_get_clientdata (client);int temp =simple_strtol (buf,NULL ,10 ); - temp = temp &&0xFF ; + temp &=0xFF ;mutex_lock (&data->lock); data->max_duty_at_overheat = temp;
Signature · 1 line
Colin
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 5 lines · Colin Leroy
Quoted 1 line · Roel Kluin
logical-bitwise & confusion
Looks good to me, but I'm not really maintaining that anymore :-) I'm not sure who does, Cc:ing Benjamin as he'll probably know.
Nobody is U suspect...
Send it to the list [email protected], it should be picked up anyway.
(linuxppc-dev CC'd)
---
logical-bitwise & confusion
---
drivers/hwmon/adt7473.c +1 -1
@@ -570,7 +570,7 @@ static ssize_t set_max_duty_at_crit(struct device *dev,struct i2c_client *client =to_i2c_client (dev);struct adt7473_data *data =i2c_get_clientdata (client);int temp =simple_strtol (buf,NULL ,10 ); - temp = temp &&0xFF ; + temp &=0xFF ;mutex_lock (&data->lock); data->max_duty_at_overheat = temp;
Quoted 13 lines
drivers/hwmon/adt7473.c +1
-1@@ -570,7 +570,7 @@ static ssize_t set_max_duty_at_crit(struct device *dev, struct i2c_client *client = to_i2c_client(dev);struct adt7473_data *data =i2c_get_clientdata (client);int temp =simple_strtol (buf,NULL ,10 ); - temp = temp &&0xFF ; + temp &=0xFF ;mutex_lock (&data->lock);
Quoted 1 line
data->max_duty_at_overheat= temp;
The & 0xff here is bogus anyway; temp is only ever used as an u8, so just declare it as that, or do proper overflow/underflow checking on it. The patch will need testing on hardware too, since it changes behaviour (it should be a bugfix, but who knows).
Segher
Quoted 12 lines · Segher Boessenkool
Quoted 12 lines
drivers/hwmon/adt7473.c +1
-1@@ -570,7 +570,7 @@ static ssize_t set_max_duty_at_crit(struct device *dev, struct i2c_client *client = to_i2c_client(dev);struct adt7473_data *data =i2c_get_clientdata (client);int temp =simple_strtol (buf,NULL ,10 ); - temp = temp &&0xFF ; + temp &=0xFF ;
Quoted 7 lines
Quoted 2 lines
drivers/hwmon/adt7473.c +0
-0mutex_lock (&data->lock);data->max_duty_at_overheat = temp;The &
0xffhere is bogus anyway; temp is only ever used as an u8, so just declare it as that, or do proper overflow/underflow checking on it. The patch will need testing on hardware too, since it changes behaviour (it should be a bugfix, but who knows).
Maybe someone can test this?
---
logical-bitwise & confusion
---
drivers/hwmon/adt7473.c +3 -3
@@ -566,11 +566,11 @@ static ssize_t set_max_duty_at_crit(struct device *dev,const char *buf, size_t count) { - u8 reg; + u8 reg, temp;struct i2c_client *client =to_i2c_client (dev);struct adt7473_data *data =i2c_get_clientdata (client); -int temp =simple_strtol (buf,NULL ,10 ); - temp = temp &&0xFF ; + + temp =simple_strtol (buf,NULL ,10 ) &0xFF ;mutex_lock (&data->lock); data->max_duty_at_overheat = temp;
Darrick J. Wong
Acked-byQuoted 6 lines · Roel Kluin
Quoted 4 lines
The &
0xffhere is bogus anyway; temp is only ever used as an u8, so just declare it as that, or do proper overflow/underflow checking on it. The patch will need testing on hardware too, since it changes behaviour (it should be a bugfix, but who knows).Maybe someone can test this?
I did. No regressions observed and it fixes that bug as well. Sorry I didn't catch it earlier... :/
--D
Andrew, I think you may want this patch instead of the other adt746x-logical-bitwise-confusion-in-set_max_duty_at_crit.patch
It includes suggested changes by Segher Boessenkool and I think this version was tested by Darrick J. Wong
---
logical-bitwise & confusion
---
drivers/hwmon/adt7473.c +3 -3
@@ -566,11 +566,11 @@ static ssize_t set_max_duty_at_crit(struct device *dev,const char *buf, size_t count) { - u8 reg; + u8 reg, temp;struct i2c_client *client =to_i2c_client (dev);struct adt7473_data *data =i2c_get_clientdata (client); -int temp =simple_strtol (buf,NULL ,10 ); - temp = temp &&0xFF ; + + temp =simple_strtol (buf,NULL ,10 ) &0xFF ;mutex_lock (&data->lock); data->max_duty_at_overheat = temp;
drivers/hwmon/adt7473.c static ssize_t set_max_duty_at_crit(struct device *dev, · line 573
Quoted 11 lines
It includes suggested changes by Segher Boessenkool and I think this version was tested by Darrick J. Wong
drivers/hwmon/adt7473.c +3
-3-u8 reg; +u8 reg, temp;struct i2c_client *client =to_i2c_client (dev);struct adt7473_data *data =i2c_get_clientdata (client); -int temp =simple_strtol (buf,NULL ,10 ); - temp = temp &&0xFF ; + + temp =simple_strtol (buf,NULL ,10 ) &0xFF ;
It still does this superfluous "& 0xff", which hides the lack of range checking.
Segher
Quoted 12 lines · Segher Boessenkool
Review
Quoted 11 lines
It includes suggested changes by Segher Boessenkool and I think this version was tested by Darrick J. Wong
(quoted diff) +3
-3- u8 reg; + u8 reg, temp; struct i2c_client *client = to_i2c_client(dev); struct adt7473_data *data = i2c_get_clientdata(client); - int temp = simple_strtol(buf, NULL, 10); - temp = temp && 0xFF; + + temp = simple_strtol(buf, NULL, 10) & 0xFF;
Quoted 2 lines
It still does this superfluous "&
0xff", which hides the lack of range checking.
Sorry didn't quite grep that
---
logical-bitwise & confusion
---
drivers/hwmon/adt7473.c +3 -3
@@ -566,11 +566,11 @@ static ssize_t set_max_duty_at_crit(struct device *dev,const char *buf, size_t count) { - u8 reg; + u8 reg, temp;struct i2c_client *client =to_i2c_client (dev);struct adt7473_data *data =i2c_get_clientdata (client); -int temp =simple_strtol (buf,NULL ,10 ); - temp = temp &&0xFF ; + + temp =simple_strtol (buf,NULL ,10 );mutex_lock (&data->lock); data->max_duty_at_overheat = temp;