Skip to content

Commit 366716e

Browse files
Corentin LabbeJean Delvare
authored andcommitted
hwmon: (adm1029) Use mask for fan_div value
This is my patch for testing correct values of fan div in adm1029 and prevent a division by 0 for some (unlikely) register values. Signed-off-by: Corentin Labbe <[email protected]> Signed-off-by: Jean Delvare <[email protected]>
1 parent d664a48 commit 366716e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/hwmon/adm1029.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ show_fan(struct device *dev, struct device_attribute *devattr, char *buf)
179179
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
180180
struct adm1029_data *data = adm1029_update_device(dev);
181181
u16 val;
182-
if (data->fan[attr->index] == 0 || data->fan_div[attr->index] == 0
182+
if (data->fan[attr->index] == 0
183+
|| (data->fan_div[attr->index] & 0xC0) == 0
183184
|| data->fan[attr->index] == 255) {
184185
return sprintf(buf, "0\n");
185186
}
@@ -194,7 +195,7 @@ show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf)
194195
{
195196
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
196197
struct adm1029_data *data = adm1029_update_device(dev);
197-
if (data->fan_div[attr->index] == 0)
198+
if ((data->fan_div[attr->index] & 0xC0) == 0)
198199
return sprintf(buf, "0\n");
199200
return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[attr->index]));
200201
}

0 commit comments

Comments
 (0)