提交 366716e6 编写于 作者: C Corentin Labbe 提交者: Jean Delvare

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: NCorentin Labbe <corentin.labbe@geomatys.fr>
Signed-off-by: NJean Delvare <khali@linux-fr.org>
上级 d664a480
...@@ -179,7 +179,8 @@ show_fan(struct device *dev, struct device_attribute *devattr, char *buf) ...@@ -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 sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct adm1029_data *data = adm1029_update_device(dev); struct adm1029_data *data = adm1029_update_device(dev);
u16 val; 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) { || data->fan[attr->index] == 255) {
return sprintf(buf, "0\n"); return sprintf(buf, "0\n");
} }
...@@ -194,7 +195,7 @@ show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf) ...@@ -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 sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct adm1029_data *data = adm1029_update_device(dev); 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, "0\n");
return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[attr->index])); return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[attr->index]));
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册