Skip to contentSkip to conversation

missing parentheses?

PATCH In review Roel Kluin 2 participants 2 messages May 14, 2009 Hardware monitoring

lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

PATCH 1/1 missing parentheses?

Add missing parentheses.

---
The original code looks odd, but I am not sure whether my patch is correct. So please review.

drivers/hwmon/lm63.c +2 -2
index 3195a26..a5a511b 100644
@@ -219,9 +219,9 @@ static ssize_t show_pwm1(struct device *dev, struct device_attribute *dummy,
 			 char *buf)
 {
 	struct lm63_data *data = lm63_update_device(dev);
-	return sprintf(buf, "%d\n", data->pwm1_value >= 2 * data->pwm1_freq ?
+	return sprintf(buf, "%d\n", data->pwm1_value >= 2 * (data->pwm1_freq ?
 		       255 : (data->pwm1_value * 255 + data->pwm1_freq) /
-		       (2 * data->pwm1_freq));
+		       (2 * data->pwm1_freq)));
 }
 
 static ssize_t set_pwm1(struct device *dev, struct device_attribute *dummy,

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

#1 lore raw

Hi Roel,

Quoted 6 lines · Roel Kluin

Add missing parentheses.

---
The original code looks odd, but I am not sure whether my patch is correct. So please review.

The original code looks good to me and your patch doesn't.

Quoted 6 lines
drivers/hwmon/lm63.c +0 -0
index 3195a26..a5a511b 100644

drivers/hwmon/lm63.c static ssize_t show_pwm1(struct device *dev, struct device_attribute *dummy, · line 224

Quoted 8 lines
drivers/hwmon/lm63.c +2 -2
@@ -219,9 +219,9 @@ static ssize_t show_pwm1(struct device *dev, struct device_attribute *dummy,
 			 char *buf)
 {
 	struct lm63_data *data = lm63_update_device(dev);
-	return sprintf(buf, "%d\n", data->pwm1_value >= 2 * data->pwm1_freq ?
+	return sprintf(buf, "%d\n", data->pwm1_value >= 2 * (data->pwm1_freq ?
 		       255 : (data->pwm1_value * 255 + data->pwm1_freq) /
-		       (2 * data->pwm1_freq));
+		       (2 * data->pwm1_freq)));

The correct parentheses would be:

	return sprintf(buf, "%d\n", (data->pwm1_value >= 2 * data->pwm1_freq) ?
		       255 : ((data->pwm1_value * 255 + data->pwm1_freq) /
		       (2 * data->pwm1_freq)));

Which I think is equivalent to what we already have, since the ?:
operator has low precedence.

Quoted 3 lines
drivers/hwmon/lm63.c +0 -0
 }
 
 static ssize_t set_pwm1(struct device *dev, struct device_attribute *dummy,
Signature · 6 lines
Jean Delvare

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