Skip to contentSkip to conversation

hwmon: (acpi_power_meter) Remove unnecessary if statement

PATCH Superseded Guenter Roeck 2 participants 3 messages Jun 19, 2012 – Jun 20, 2012 Hardware monitoring

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 3/4 hwmon: (acpi_power_meter) Remove unnecessary if statement

An unsigned value is never smaller than 0. Remove the check for it.

---
 drivers/hwmon/acpi_power_meter.c |    2 --
 1 file changed, 2 deletions(-)
drivers/hwmon/acpi_power_meter.c +0 -2
index 34ad5a2..e2b0ae8 100644
@@ -308,8 +308,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
 		return res;
 
 	temp /= 1000;
-	if (temp < 0)
-		return -EINVAL;
 
 	mutex_lock(&resource->lock);
 	resource->trip[attr->index - 7] = temp;
Signature · 7 lines
1.7.9.7


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Acked-by on v1 3/4
#1 lore raw
Quoted 12 lines · Guenter Roeck

An unsigned value is never smaller than 0. Remove the check for it.

---
 drivers/hwmon/acpi_power_meter.c |    2 --
 1 file changed, 2 deletions(-)
drivers/hwmon/acpi_power_meter.c +0 -0
index 34ad5a2..e2b0ae8 100644

drivers/hwmon/acpi_power_meter.c static ssize_t set_trip(struct device *dev, struct device_attribute *devattr, · line 313

Quoted 8 lines
drivers/hwmon/acpi_power_meter.c +0 -2
@@ -308,8 +308,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
 		return res;
 
 	temp /= 1000;
-	if (temp < 0)
-		return -EINVAL;
 
 	mutex_lock(&resource->lock);
 	resource->trip[attr->index - 7] = temp;

That being said, DIV_ROUND_CLOSEST would be better to use than /=, and some clamping on the value would be good to have too, as you can't always fit an unsigned long into an int (there may even be other constraints, I don't know.)

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 24 lines · Jean Delvare
Quoted 12 lines · Guenter Roeck

An unsigned value is never smaller than 0. Remove the check for it.

---
 drivers/hwmon/acpi_power_meter.c |    2 --
 1 file changed, 2 deletions(-)
drivers/hwmon/acpi_power_meter.c +0 -0
index 34ad5a2..e2b0ae8 100644

drivers/hwmon/acpi_power_meter.c static ssize_t set_trip(struct device *dev, struct device_attribute *devattr, · line 313

Quoted 8 lines
drivers/hwmon/acpi_power_meter.c +0 -2
@@ -308,8 +308,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
 		return res;
 
 	temp /= 1000;
-	if (temp < 0)
-		return -EINVAL;
 
 	mutex_lock(&resource->lock);
 	resource->trip[attr->index - 7] = temp;
Quoted 4 lines

That being said, DIV_ROUND_CLOSEST would be better to use than /=, and some clamping on the value would be good to have too, as you can't always fit an unsigned long into an int (there may even be other constraints, I don't know.)

I thought about doing that as separate patch, but since the above doesn't really fix a bug anyway, it does not hurt to put it together into one. I'll do that and resubmit.

Guenter

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