Skip to contentSkip to conversation

ADT746X: logical-bitwise & confusion in set_max_duty_at_crit()

PATCH Roel Kluin 5 participants 10 messages Mar 10, 2008 Hardware monitoring

lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

logical-bitwise & confusion

---

drivers/hwmon/adt7473.c +1 -1
index 9587869..8ea7da2 100644
@@ -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;
#2 lore raw
In reply to Colin Leroy
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

---

drivers/hwmon/adt7473.c +1 -1
index 9587869..8ea7da2 100644
@@ -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;
#1 lore raw
In reply to Roel Kluin

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

---

drivers/hwmon/adt7473.c +1 -1
index 9587869..8ea7da2 100644
@@ -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
author
#3 lore raw
In reply to Benjamin Herrenschmidt
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
index 9587869..8ea7da2 100644
@@ -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;
#4 lore raw
Quoted 13 lines
drivers/hwmon/adt7473.c +1 -1
index 9587869..8ea7da2 100644
@@ -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

author
#5 lore raw
Quoted 12 lines · Segher Boessenkool
Quoted 12 lines
drivers/hwmon/adt7473.c +1 -1
index 9587869..8ea7da2 100644
@@ -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 -0
     mutex_lock(&data->lock);
     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).

Maybe someone can test this?
---
logical-bitwise & confusion

---

drivers/hwmon/adt7473.c +3 -3
index 9587869..2a2de73 100644
@@ -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;
#6 lore raw
Quoted 6 lines · Roel Kluin
Quoted 4 lines

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).

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

author
#7 lore raw
In reply to Segher Boessenkool

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
index 9587869..2a2de73 100644
@@ -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;
#8 lore raw

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

author
#9 lore raw
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
index 9587869..98937d3 100644
@@ -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;