Skip to contentSkip to conversation

hwmon: (emc6w201) Fix DIV_ROUND_CLOSEST problem with unsigned divisors

PATCH Applied Guenter Roeck 2 participants 6 messages Dec 19, 2012 Hardware monitoring

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH v2 1/1 hwmon: (emc6w201) Fix DIV_ROUND_CLOSEST problem with unsigned divisors

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

---
v2: Fix by changing divisor variable type instead of dividend variable type

 drivers/hwmon/emc6w201.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/emc6w201.c +1 -1
index a98c917..789bd4f 100644
@@ -187,7 +187,7 @@ static struct emc6w201_data *emc6w201_update_device(struct device *dev)
  * Sysfs callback functions
  */
 
-static const u16 nominal_mv[6] = { 2500, 1500, 3300, 5000, 1500, 1500 };
+static const s16 nominal_mv[6] = { 2500, 1500, 3300, 5000, 1500, 1500 };
 
 static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
 	char *buf)
Signature · 7 lines
1.7.9.7


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Applied
#1 lore raw

Hi Guenter,

Quoted 15 lines · Guenter Roeck

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

---
v2: Fix by changing divisor variable type instead of dividend variable type

 drivers/hwmon/emc6w201.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/emc6w201.c +0 -0
index a98c917..789bd4f 100644

drivers/hwmon/emc6w201.c static struct emc6w201_data *emc6w201_update_device(struct device *dev) · line 193

Quoted 8 lines
drivers/hwmon/emc6w201.c +1 -1
@@ -187,7 +187,7 @@ static struct emc6w201_data *emc6w201_update_device(struct device *dev)
  * Sysfs callback functions
  */
 
-static const u16 nominal_mv[6] = { 2500, 1500, 3300, 5000, 1500, 1500 };
+static const s16 nominal_mv[6] = { 2500, 1500, 3300, 5000, 1500, 1500 };
 
 static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
 	char *buf)

Applied, thanks.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
author maintainer
#2 lore raw
In reply to Guenter Roeck
Quoted 21 lines · Jean Delvare

Hi Guenter,

Quoted 18 lines · Guenter Roeck

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

---
v2: Fix by changing divisor variable type instead of dividend variable type

 drivers/hwmon/emc6w201.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/emc6w201.c +0 -0
index a98c917..789bd4f 100644
@@ -187,7 +187,7 @@ static struct emc6w201_data *emc6w201_update_device(struct device *dev)
  * Sysfs callback functions
  */
 
Quoted 8 lines

drivers/hwmon/emc6w201.c static struct emc6w201_data *emc6w201_update_device(struct device *dev) · line 193

Quoted 5 lines
drivers/hwmon/emc6w201.c +1 -1
-static const u16 nominal_mv[6] = { 2500, 1500, 3300, 5000, 1500, 1500 };
+static const s16 nominal_mv[6] = { 2500, 1500, 3300, 5000, 1500, 1500 };
 
 static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
 	char *buf)

Applied, thanks.

Hi Jean,

Can you take the kernel.h patch as well ?

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#3 lore raw
In reply to Guenter Roeck
Quoted 25 lines · Guenter Roeck
Quoted 24 lines · Jean Delvare

Hi Guenter,

Quoted 21 lines · Guenter Roeck

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

---
v2: Fix by changing divisor variable type instead of dividend variable type

 drivers/hwmon/emc6w201.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/emc6w201.c +1 -1
index a98c917..789bd4f 100644
@@ -187,7 +187,7 @@ static struct emc6w201_data *emc6w201_update_device(struct device *dev)
  * Sysfs callback functions
  */
 
-static const u16 nominal_mv[6] = { 2500, 1500, 3300, 5000, 1500, 1500 };
+static const s16 nominal_mv[6] = { 2500, 1500, 3300, 5000, 1500, 1500 };
 
Quoted 6 lines
Quoted 4 lines

drivers/hwmon/emc6w201.c static struct emc6w201_data *emc6w201_update_device(struct device *dev) · line 193

Quoted 2 lines
drivers/hwmon/emc6w201.c +0 -0
 static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
 	char *buf)

Applied, thanks.

Can you take the kernel.h patch as well ?

Yes I can. I'm sending my hwmon patches to Linus tonight.

For clarity: both patches are needed but they are otherwise independent, right?

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#4 lore raw
In reply to Guenter Roeck
Quoted 31 lines · Jean Delvare
Quoted 30 lines · Guenter Roeck
Quoted 28 lines · Jean Delvare

Hi Guenter,

Quoted 15 lines · Guenter Roeck

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

---
v2: Fix by changing divisor variable type instead of dividend variable type

 drivers/hwmon/emc6w201.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/emc6w201.c +0 -0
index a98c917..789bd4f 100644

drivers/hwmon/emc6w201.c static struct emc6w201_data *emc6w201_update_device(struct device *dev) · line 193

Quoted 8 lines
drivers/hwmon/emc6w201.c +1 -1
@@ -187,7 +187,7 @@ static struct emc6w201_data *emc6w201_update_device(struct device *dev)
  * Sysfs callback functions
  */
 
-static const u16 nominal_mv[6] = { 2500, 1500, 3300, 5000, 1500, 1500 };
+static const s16 nominal_mv[6] = { 2500, 1500, 3300, 5000, 1500, 1500 };
 
 static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
 	char *buf)

Applied, thanks.

Quoted 6 lines
Quoted 1 line

Can you take the kernel.h patch as well ?

Yes I can. I'm sending my hwmon patches to Linus tonight.

For clarity: both patches are needed but they are otherwise independent, right?

Note: I finally refrained from including both commits in my pull request, I want to take a closer look first. If nothing else, to decide whether they should go to stable trees or not.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
author maintainer
#5 lore raw
In reply to Guenter Roeck
Quoted 34 lines · Jean Delvare
Quoted 33 lines · Jean Delvare
Quoted 31 lines · Guenter Roeck
Quoted 21 lines · Jean Delvare

Hi Guenter,

Quoted 18 lines · Guenter Roeck

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

---
v2: Fix by changing divisor variable type instead of dividend variable type

 drivers/hwmon/emc6w201.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/emc6w201.c +0 -0
index a98c917..789bd4f 100644
@@ -187,7 +187,7 @@ static struct emc6w201_data *emc6w201_update_device(struct device *dev)
  * Sysfs callback functions
  */
 
Quoted 7 lines

drivers/hwmon/emc6w201.c static struct emc6w201_data *emc6w201_update_device(struct device *dev) · line 193

Quoted 5 lines
drivers/hwmon/emc6w201.c +1 -1
-static const u16 nominal_mv[6] = { 2500, 1500, 3300, 5000, 1500, 1500 };
+static const s16 nominal_mv[6] = { 2500, 1500, 3300, 5000, 1500, 1500 };
 
 static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
 	char *buf)

Applied, thanks.

Can you take the kernel.h patch as well ?

Quoted 9 lines
Quoted 4 lines

Yes I can. I'm sending my hwmon patches to Linus tonight.

For clarity: both patches are needed but they are otherwise independent, right?

Note: I finally refrained from including both commits in my pull request, I want to take a closer look first. If nothing else, to decide whether they should go to stable trees or not.

Yes - 3.6 and later.

Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors