Skip to content

Commit

Permalink
hwmon: (adm1029) Use mask for fan_div value
Browse files Browse the repository at this point in the history
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 <corentin.labbe@geomatys.fr>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
  • Loading branch information
Corentin Labbe authored and Jean Delvare committed Oct 17, 2008
1 parent d664a48 commit 366716e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/hwmon/adm1029.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ show_fan(struct device *dev, struct device_attribute *devattr, char *buf)
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct adm1029_data *data = adm1029_update_device(dev);
u16 val;
if (data->fan[attr->index] == 0 || data->fan_div[attr->index] == 0
if (data->fan[attr->index] == 0
|| (data->fan_div[attr->index] & 0xC0) == 0
|| data->fan[attr->index] == 255) {
return sprintf(buf, "0\n");
}
Expand All @@ -194,7 +195,7 @@ show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct adm1029_data *data = adm1029_update_device(dev);
if (data->fan_div[attr->index] == 0)
if ((data->fan_div[attr->index] & 0xC0) == 0)
return sprintf(buf, "0\n");
return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[attr->index]));
}
Expand Down

0 comments on commit 366716e

Please sign in to comment.