diff options
author | Hans de Goede <hdegoede@redhat.com> | 2009-01-07 10:37:28 -0500 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2009-01-07 10:37:28 -0500 |
commit | ce0bfa5ee25ddbe4072b16054e809f552bf72320 (patch) | |
tree | 35418be8a28fcaf8cc65cf3d829d13f1f0ef4f3d /drivers/hwmon/f71882fg.c | |
parent | 7567a0435520fe61420ff2cdc4cec1b5399a5134 (diff) |
hwmon: (f71882fg) Fix various sysfs callback function issues
While working on adding F8000 support I noticed that various of the
store sysfs functions (and a few of the show also) had issues.
This patch fixes the following issues in these functions:
* store: storing the result of strto[u]l in an int, resulting in a possible
overflow before boundary checking
* store: use of f71882fg_update_device(), we don't want to read the whole
device in store functions, just the registers we need
* store: use of cached register values instead of reading the needed regs
in the store function, including cases where f71882fg_update_device() was
not used, this could cause real isues
* show: shown value is a calculation of 2 or more cached register reads,
without locking the data struct.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon/f71882fg.c')
-rw-r--r-- | drivers/hwmon/f71882fg.c | 122 |
1 files changed, 73 insertions, 49 deletions
diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c index 2604c6d7ea58..345f465aa288 100644 --- a/drivers/hwmon/f71882fg.c +++ b/drivers/hwmon/f71882fg.c | |||
@@ -835,6 +835,7 @@ static ssize_t store_fan_full_speed(struct device *dev, | |||
835 | val = fan_to_reg(val); | 835 | val = fan_to_reg(val); |
836 | 836 | ||
837 | mutex_lock(&data->update_lock); | 837 | mutex_lock(&data->update_lock); |
838 | data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE); | ||
838 | if (data->pwm_enable & (1 << (2 * nr))) | 839 | if (data->pwm_enable & (1 << (2 * nr))) |
839 | /* PWM mode */ | 840 | /* PWM mode */ |
840 | count = -EINVAL; | 841 | count = -EINVAL; |
@@ -865,9 +866,10 @@ static ssize_t store_fan_beep(struct device *dev, struct device_attribute | |||
865 | { | 866 | { |
866 | struct f71882fg_data *data = dev_get_drvdata(dev); | 867 | struct f71882fg_data *data = dev_get_drvdata(dev); |
867 | int nr = to_sensor_dev_attr_2(devattr)->index; | 868 | int nr = to_sensor_dev_attr_2(devattr)->index; |
868 | int val = simple_strtoul(buf, NULL, 10); | 869 | unsigned long val = simple_strtoul(buf, NULL, 10); |
869 | 870 | ||
870 | mutex_lock(&data->update_lock); | 871 | mutex_lock(&data->update_lock); |
872 | data->fan_beep = f71882fg_read8(data, F71882FG_REG_FAN_BEEP); | ||
871 | if (val) | 873 | if (val) |
872 | data->fan_beep |= 1 << nr; | 874 | data->fan_beep |= 1 << nr; |
873 | else | 875 | else |
@@ -912,10 +914,8 @@ static ssize_t store_in_max(struct device *dev, struct device_attribute | |||
912 | *devattr, const char *buf, size_t count) | 914 | *devattr, const char *buf, size_t count) |
913 | { | 915 | { |
914 | struct f71882fg_data *data = dev_get_drvdata(dev); | 916 | struct f71882fg_data *data = dev_get_drvdata(dev); |
915 | int val = simple_strtoul(buf, NULL, 10) / 8; | 917 | long val = simple_strtol(buf, NULL, 10) / 8; |
916 | 918 | val = SENSORS_LIMIT(val, 0, 255); | |
917 | if (val > 255) | ||
918 | val = 255; | ||
919 | 919 | ||
920 | mutex_lock(&data->update_lock); | 920 | mutex_lock(&data->update_lock); |
921 | f71882fg_write8(data, F71882FG_REG_IN1_HIGH, val); | 921 | f71882fg_write8(data, F71882FG_REG_IN1_HIGH, val); |
@@ -942,9 +942,10 @@ static ssize_t store_in_beep(struct device *dev, struct device_attribute | |||
942 | { | 942 | { |
943 | struct f71882fg_data *data = dev_get_drvdata(dev); | 943 | struct f71882fg_data *data = dev_get_drvdata(dev); |
944 | int nr = to_sensor_dev_attr_2(devattr)->index; | 944 | int nr = to_sensor_dev_attr_2(devattr)->index; |
945 | int val = simple_strtoul(buf, NULL, 10); | 945 | unsigned long val = simple_strtoul(buf, NULL, 10); |
946 | 946 | ||
947 | mutex_lock(&data->update_lock); | 947 | mutex_lock(&data->update_lock); |
948 | data->in_beep = f71882fg_read8(data, F71882FG_REG_IN_BEEP); | ||
948 | if (val) | 949 | if (val) |
949 | data->in_beep |= 1 << nr; | 950 | data->in_beep |= 1 << nr; |
950 | else | 951 | else |
@@ -991,10 +992,8 @@ static ssize_t store_temp_max(struct device *dev, struct device_attribute | |||
991 | { | 992 | { |
992 | struct f71882fg_data *data = dev_get_drvdata(dev); | 993 | struct f71882fg_data *data = dev_get_drvdata(dev); |
993 | int nr = to_sensor_dev_attr_2(devattr)->index; | 994 | int nr = to_sensor_dev_attr_2(devattr)->index; |
994 | int val = simple_strtoul(buf, NULL, 10) / 1000; | 995 | long val = simple_strtol(buf, NULL, 10) / 1000; |
995 | 996 | val = SENSORS_LIMIT(val, 0, 255); | |
996 | if (val > 255) | ||
997 | val = 255; | ||
998 | 997 | ||
999 | mutex_lock(&data->update_lock); | 998 | mutex_lock(&data->update_lock); |
1000 | f71882fg_write8(data, F71882FG_REG_TEMP_HIGH(nr), val); | 999 | f71882fg_write8(data, F71882FG_REG_TEMP_HIGH(nr), val); |
@@ -1009,9 +1008,13 @@ static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute | |||
1009 | { | 1008 | { |
1010 | struct f71882fg_data *data = f71882fg_update_device(dev); | 1009 | struct f71882fg_data *data = f71882fg_update_device(dev); |
1011 | int nr = to_sensor_dev_attr_2(devattr)->index; | 1010 | int nr = to_sensor_dev_attr_2(devattr)->index; |
1011 | int temp_max_hyst; | ||
1012 | 1012 | ||
1013 | return sprintf(buf, "%d\n", | 1013 | mutex_lock(&data->update_lock); |
1014 | (data->temp_high[nr] - data->temp_hyst[nr]) * 1000); | 1014 | temp_max_hyst = (data->temp_high[nr] - data->temp_hyst[nr]) * 1000; |
1015 | mutex_unlock(&data->update_lock); | ||
1016 | |||
1017 | return sprintf(buf, "%d\n", temp_max_hyst); | ||
1015 | } | 1018 | } |
1016 | 1019 | ||
1017 | static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute | 1020 | static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute |
@@ -1019,37 +1022,38 @@ static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute | |||
1019 | { | 1022 | { |
1020 | struct f71882fg_data *data = dev_get_drvdata(dev); | 1023 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1021 | int nr = to_sensor_dev_attr_2(devattr)->index; | 1024 | int nr = to_sensor_dev_attr_2(devattr)->index; |
1022 | int val = simple_strtoul(buf, NULL, 10) / 1000; | 1025 | long val = simple_strtol(buf, NULL, 10) / 1000; |
1023 | ssize_t ret = count; | 1026 | ssize_t ret = count; |
1027 | u8 reg; | ||
1024 | 1028 | ||
1025 | mutex_lock(&data->update_lock); | 1029 | mutex_lock(&data->update_lock); |
1026 | 1030 | ||
1027 | /* convert abs to relative and check */ | 1031 | /* convert abs to relative and check */ |
1032 | data->temp_high[nr] = f71882fg_read8(data, F71882FG_REG_TEMP_HIGH(nr)); | ||
1033 | val = SENSORS_LIMIT(val, data->temp_high[nr] - 15, | ||
1034 | data->temp_high[nr]); | ||
1028 | val = data->temp_high[nr] - val; | 1035 | val = data->temp_high[nr] - val; |
1029 | if (val < 0 || val > 15) { | ||
1030 | ret = -EINVAL; | ||
1031 | goto store_temp_max_hyst_exit; | ||
1032 | } | ||
1033 | |||
1034 | data->temp_hyst[nr] = val; | 1036 | data->temp_hyst[nr] = val; |
1035 | 1037 | ||
1036 | /* convert value to register contents */ | 1038 | /* convert value to register contents */ |
1037 | switch (nr) { | 1039 | switch (nr) { |
1038 | case 1: | 1040 | case 1: |
1039 | val = val << 4; | 1041 | reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST1); |
1042 | reg = (reg & 0x0f) | (val << 4); | ||
1040 | break; | 1043 | break; |
1041 | case 2: | 1044 | case 2: |
1042 | val = val | (data->temp_hyst[3] << 4); | 1045 | reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST23); |
1046 | reg = (reg & 0xf0) | val; | ||
1043 | break; | 1047 | break; |
1044 | case 3: | 1048 | case 3: |
1045 | val = data->temp_hyst[2] | (val << 4); | 1049 | reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST23); |
1050 | reg = (reg & 0x0f) | (val << 4); | ||
1046 | break; | 1051 | break; |
1047 | } | 1052 | } |
1048 | 1053 | ||
1049 | f71882fg_write8(data, (nr <= 1) ? F71882FG_REG_TEMP_HYST1 : | 1054 | f71882fg_write8(data, (nr <= 1) ? F71882FG_REG_TEMP_HYST1 : |
1050 | F71882FG_REG_TEMP_HYST23, val); | 1055 | F71882FG_REG_TEMP_HYST23, reg); |
1051 | 1056 | ||
1052 | store_temp_max_hyst_exit: | ||
1053 | mutex_unlock(&data->update_lock); | 1057 | mutex_unlock(&data->update_lock); |
1054 | return ret; | 1058 | return ret; |
1055 | } | 1059 | } |
@@ -1068,10 +1072,8 @@ static ssize_t store_temp_crit(struct device *dev, struct device_attribute | |||
1068 | { | 1072 | { |
1069 | struct f71882fg_data *data = dev_get_drvdata(dev); | 1073 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1070 | int nr = to_sensor_dev_attr_2(devattr)->index; | 1074 | int nr = to_sensor_dev_attr_2(devattr)->index; |
1071 | int val = simple_strtoul(buf, NULL, 10) / 1000; | 1075 | long val = simple_strtol(buf, NULL, 10) / 1000; |
1072 | 1076 | val = SENSORS_LIMIT(val, 0, 255); | |
1073 | if (val > 255) | ||
1074 | val = 255; | ||
1075 | 1077 | ||
1076 | mutex_lock(&data->update_lock); | 1078 | mutex_lock(&data->update_lock); |
1077 | f71882fg_write8(data, F71882FG_REG_TEMP_OVT(nr), val); | 1079 | f71882fg_write8(data, F71882FG_REG_TEMP_OVT(nr), val); |
@@ -1086,9 +1088,13 @@ static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute | |||
1086 | { | 1088 | { |
1087 | struct f71882fg_data *data = f71882fg_update_device(dev); | 1089 | struct f71882fg_data *data = f71882fg_update_device(dev); |
1088 | int nr = to_sensor_dev_attr_2(devattr)->index; | 1090 | int nr = to_sensor_dev_attr_2(devattr)->index; |
1091 | int temp_crit_hyst; | ||
1089 | 1092 | ||
1090 | return sprintf(buf, "%d\n", | 1093 | mutex_lock(&data->update_lock); |
1091 | (data->temp_ovt[nr] - data->temp_hyst[nr]) * 1000); | 1094 | temp_crit_hyst = (data->temp_ovt[nr] - data->temp_hyst[nr]) * 1000; |
1095 | mutex_unlock(&data->update_lock); | ||
1096 | |||
1097 | return sprintf(buf, "%d\n", temp_crit_hyst); | ||
1092 | } | 1098 | } |
1093 | 1099 | ||
1094 | static ssize_t show_temp_type(struct device *dev, struct device_attribute | 1100 | static ssize_t show_temp_type(struct device *dev, struct device_attribute |
@@ -1117,9 +1123,10 @@ static ssize_t store_temp_beep(struct device *dev, struct device_attribute | |||
1117 | { | 1123 | { |
1118 | struct f71882fg_data *data = dev_get_drvdata(dev); | 1124 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1119 | int nr = to_sensor_dev_attr_2(devattr)->index; | 1125 | int nr = to_sensor_dev_attr_2(devattr)->index; |
1120 | int val = simple_strtoul(buf, NULL, 10); | 1126 | unsigned long val = simple_strtoul(buf, NULL, 10); |
1121 | 1127 | ||
1122 | mutex_lock(&data->update_lock); | 1128 | mutex_lock(&data->update_lock); |
1129 | data->temp_beep = f71882fg_read8(data, F71882FG_REG_TEMP_BEEP); | ||
1123 | if (val) | 1130 | if (val) |
1124 | data->temp_beep |= 1 << nr; | 1131 | data->temp_beep |= 1 << nr; |
1125 | else | 1132 | else |
@@ -1160,16 +1167,16 @@ static ssize_t show_pwm(struct device *dev, | |||
1160 | { | 1167 | { |
1161 | struct f71882fg_data *data = f71882fg_update_device(dev); | 1168 | struct f71882fg_data *data = f71882fg_update_device(dev); |
1162 | int val, nr = to_sensor_dev_attr_2(devattr)->index; | 1169 | int val, nr = to_sensor_dev_attr_2(devattr)->index; |
1170 | mutex_lock(&data->update_lock); | ||
1163 | if (data->pwm_enable & (1 << (2 * nr))) | 1171 | if (data->pwm_enable & (1 << (2 * nr))) |
1164 | /* PWM mode */ | 1172 | /* PWM mode */ |
1165 | val = data->pwm[nr]; | 1173 | val = data->pwm[nr]; |
1166 | else { | 1174 | else { |
1167 | /* RPM mode */ | 1175 | /* RPM mode */ |
1168 | mutex_lock(&data->update_lock); | ||
1169 | val = 255 * fan_from_reg(data->fan_target[nr]) | 1176 | val = 255 * fan_from_reg(data->fan_target[nr]) |
1170 | / fan_from_reg(data->fan_full_speed[nr]); | 1177 | / fan_from_reg(data->fan_full_speed[nr]); |
1171 | mutex_unlock(&data->update_lock); | ||
1172 | } | 1178 | } |
1179 | mutex_unlock(&data->update_lock); | ||
1173 | return sprintf(buf, "%d\n", val); | 1180 | return sprintf(buf, "%d\n", val); |
1174 | } | 1181 | } |
1175 | 1182 | ||
@@ -1177,23 +1184,26 @@ static ssize_t store_pwm(struct device *dev, | |||
1177 | struct device_attribute *devattr, const char *buf, | 1184 | struct device_attribute *devattr, const char *buf, |
1178 | size_t count) | 1185 | size_t count) |
1179 | { | 1186 | { |
1180 | /* struct f71882fg_data *data = dev_get_drvdata(dev); */ | 1187 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1181 | struct f71882fg_data *data = f71882fg_update_device(dev); | ||
1182 | int nr = to_sensor_dev_attr_2(devattr)->index; | 1188 | int nr = to_sensor_dev_attr_2(devattr)->index; |
1183 | long val = simple_strtol(buf, NULL, 10); | 1189 | long val = simple_strtol(buf, NULL, 10); |
1184 | val = SENSORS_LIMIT(val, 0, 255); | 1190 | val = SENSORS_LIMIT(val, 0, 255); |
1185 | 1191 | ||
1186 | mutex_lock(&data->update_lock); | 1192 | mutex_lock(&data->update_lock); |
1193 | data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE); | ||
1187 | if (data->pwm_enable & (1 << (2 * nr))) { | 1194 | if (data->pwm_enable & (1 << (2 * nr))) { |
1188 | /* PWM mode */ | 1195 | /* PWM mode */ |
1189 | f71882fg_write8(data, F71882FG_REG_PWM(nr), val); | 1196 | f71882fg_write8(data, F71882FG_REG_PWM(nr), val); |
1190 | data->pwm[nr] = val; | 1197 | data->pwm[nr] = val; |
1191 | } else { | 1198 | } else { |
1192 | /* RPM mode */ | 1199 | /* RPM mode */ |
1193 | int target = val * fan_from_reg(data->fan_full_speed[nr]) / 255; | 1200 | int target, full_speed; |
1194 | f71882fg_write16(data, F71882FG_REG_FAN_TARGET(nr), | 1201 | full_speed = f71882fg_read16(data, |
1195 | fan_to_reg(target)); | 1202 | F71882FG_REG_FAN_FULL_SPEED(nr)); |
1196 | data->fan_target[nr] = fan_to_reg(target); | 1203 | target = fan_to_reg(val * fan_from_reg(full_speed) / 255); |
1204 | f71882fg_write16(data, F71882FG_REG_FAN_TARGET(nr), target); | ||
1205 | data->fan_target[nr] = target; | ||
1206 | data->fan_full_speed[nr] = full_speed; | ||
1197 | } | 1207 | } |
1198 | mutex_unlock(&data->update_lock); | 1208 | mutex_unlock(&data->update_lock); |
1199 | 1209 | ||
@@ -1225,6 +1235,7 @@ static ssize_t store_pwm_enable(struct device *dev, struct device_attribute | |||
1225 | return -EINVAL; | 1235 | return -EINVAL; |
1226 | 1236 | ||
1227 | mutex_lock(&data->update_lock); | 1237 | mutex_lock(&data->update_lock); |
1238 | data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE); | ||
1228 | switch (val) { | 1239 | switch (val) { |
1229 | case 1: | 1240 | case 1: |
1230 | data->pwm_enable |= 2 << (2 * nr); | 1241 | data->pwm_enable |= 2 << (2 * nr); |
@@ -1258,6 +1269,7 @@ static ssize_t show_pwm_auto_point_pwm(struct device *dev, | |||
1258 | int pwm = to_sensor_dev_attr_2(devattr)->index; | 1269 | int pwm = to_sensor_dev_attr_2(devattr)->index; |
1259 | int point = to_sensor_dev_attr_2(devattr)->nr; | 1270 | int point = to_sensor_dev_attr_2(devattr)->nr; |
1260 | 1271 | ||
1272 | mutex_lock(&data->update_lock); | ||
1261 | if (data->pwm_enable & (1 << (2 * pwm))) { | 1273 | if (data->pwm_enable & (1 << (2 * pwm))) { |
1262 | /* PWM mode */ | 1274 | /* PWM mode */ |
1263 | result = data->pwm_auto_point_pwm[pwm][point]; | 1275 | result = data->pwm_auto_point_pwm[pwm][point]; |
@@ -1265,6 +1277,7 @@ static ssize_t show_pwm_auto_point_pwm(struct device *dev, | |||
1265 | /* RPM mode */ | 1277 | /* RPM mode */ |
1266 | result = 32 * 255 / (32 + data->pwm_auto_point_pwm[pwm][point]); | 1278 | result = 32 * 255 / (32 + data->pwm_auto_point_pwm[pwm][point]); |
1267 | } | 1279 | } |
1280 | mutex_unlock(&data->update_lock); | ||
1268 | 1281 | ||
1269 | return sprintf(buf, "%d\n", result); | 1282 | return sprintf(buf, "%d\n", result); |
1270 | } | 1283 | } |
@@ -1273,14 +1286,14 @@ static ssize_t store_pwm_auto_point_pwm(struct device *dev, | |||
1273 | struct device_attribute *devattr, | 1286 | struct device_attribute *devattr, |
1274 | const char *buf, size_t count) | 1287 | const char *buf, size_t count) |
1275 | { | 1288 | { |
1276 | /* struct f71882fg_data *data = dev_get_drvdata(dev); */ | 1289 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1277 | struct f71882fg_data *data = f71882fg_update_device(dev); | ||
1278 | int pwm = to_sensor_dev_attr_2(devattr)->index; | 1290 | int pwm = to_sensor_dev_attr_2(devattr)->index; |
1279 | int point = to_sensor_dev_attr_2(devattr)->nr; | 1291 | int point = to_sensor_dev_attr_2(devattr)->nr; |
1280 | int val = simple_strtoul(buf, NULL, 10); | 1292 | long val = simple_strtol(buf, NULL, 10); |
1281 | val = SENSORS_LIMIT(val, 0, 255); | 1293 | val = SENSORS_LIMIT(val, 0, 255); |
1282 | 1294 | ||
1283 | mutex_lock(&data->update_lock); | 1295 | mutex_lock(&data->update_lock); |
1296 | data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE); | ||
1284 | if (data->pwm_enable & (1 << (2 * pwm))) { | 1297 | if (data->pwm_enable & (1 << (2 * pwm))) { |
1285 | /* PWM mode */ | 1298 | /* PWM mode */ |
1286 | } else { | 1299 | } else { |
@@ -1331,16 +1344,25 @@ static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev, | |||
1331 | struct device_attribute *devattr, | 1344 | struct device_attribute *devattr, |
1332 | const char *buf, size_t count) | 1345 | const char *buf, size_t count) |
1333 | { | 1346 | { |
1334 | struct f71882fg_data *data = f71882fg_update_device(dev); | 1347 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1335 | int nr = to_sensor_dev_attr_2(devattr)->index; | 1348 | int nr = to_sensor_dev_attr_2(devattr)->index; |
1336 | int point = to_sensor_dev_attr_2(devattr)->nr; | 1349 | int point = to_sensor_dev_attr_2(devattr)->nr; |
1337 | long val = simple_strtol(buf, NULL, 10) / 1000; | 1350 | long val = simple_strtol(buf, NULL, 10) / 1000; |
1338 | 1351 | ||
1339 | mutex_lock(&data->update_lock); | 1352 | mutex_lock(&data->update_lock); |
1353 | data->pwm_auto_point_temp[nr][point] = | ||
1354 | f71882fg_read8(data, F71882FG_REG_POINT_TEMP(nr, point)); | ||
1340 | val = SENSORS_LIMIT(val, data->pwm_auto_point_temp[nr][point] - 15, | 1355 | val = SENSORS_LIMIT(val, data->pwm_auto_point_temp[nr][point] - 15, |
1341 | data->pwm_auto_point_temp[nr][point]); | 1356 | data->pwm_auto_point_temp[nr][point]); |
1342 | val = data->pwm_auto_point_temp[nr][point] - val; | 1357 | val = data->pwm_auto_point_temp[nr][point] - val; |
1343 | 1358 | ||
1359 | if (nr == 0 || nr == 1) { | ||
1360 | data->pwm_auto_point_hyst[0] = | ||
1361 | f71882fg_read8(data, F71882FG_REG_FAN_HYST0); | ||
1362 | } else { | ||
1363 | data->pwm_auto_point_hyst[1] = | ||
1364 | f71882fg_read8(data, F71882FG_REG_FAN_HYST1); | ||
1365 | } | ||
1344 | switch (nr) { | 1366 | switch (nr) { |
1345 | case 0: | 1367 | case 0: |
1346 | val = (data->pwm_auto_point_hyst[0] & 0xf0) | val; | 1368 | val = (data->pwm_auto_point_hyst[0] & 0xf0) | val; |
@@ -1383,11 +1405,13 @@ static ssize_t store_pwm_interpolate(struct device *dev, | |||
1383 | struct device_attribute *devattr, | 1405 | struct device_attribute *devattr, |
1384 | const char *buf, size_t count) | 1406 | const char *buf, size_t count) |
1385 | { | 1407 | { |
1386 | /* struct f71882fg_data *data = dev_get_drvdata(dev); */ | 1408 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1387 | struct f71882fg_data *data = f71882fg_update_device(dev); | ||
1388 | int nr = to_sensor_dev_attr_2(devattr)->index; | 1409 | int nr = to_sensor_dev_attr_2(devattr)->index; |
1389 | int val = simple_strtoul(buf, NULL, 10); | 1410 | unsigned long val = simple_strtoul(buf, NULL, 10); |
1411 | |||
1390 | mutex_lock(&data->update_lock); | 1412 | mutex_lock(&data->update_lock); |
1413 | data->pwm_auto_point_mapping[nr] = | ||
1414 | f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr)); | ||
1391 | if (val) | 1415 | if (val) |
1392 | val = data->pwm_auto_point_mapping[nr] | (1 << 4); | 1416 | val = data->pwm_auto_point_mapping[nr] | (1 << 4); |
1393 | else | 1417 | else |
@@ -1416,8 +1440,7 @@ static ssize_t store_pwm_auto_point_channel(struct device *dev, | |||
1416 | struct device_attribute *devattr, | 1440 | struct device_attribute *devattr, |
1417 | const char *buf, size_t count) | 1441 | const char *buf, size_t count) |
1418 | { | 1442 | { |
1419 | /* struct f71882fg_data *data = dev_get_drvdata(dev); */ | 1443 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1420 | struct f71882fg_data *data = f71882fg_update_device(dev); | ||
1421 | int nr = to_sensor_dev_attr_2(devattr)->index; | 1444 | int nr = to_sensor_dev_attr_2(devattr)->index; |
1422 | long val = simple_strtol(buf, NULL, 10); | 1445 | long val = simple_strtol(buf, NULL, 10); |
1423 | switch (val) { | 1446 | switch (val) { |
@@ -1434,6 +1457,8 @@ static ssize_t store_pwm_auto_point_channel(struct device *dev, | |||
1434 | return -EINVAL; | 1457 | return -EINVAL; |
1435 | } | 1458 | } |
1436 | mutex_lock(&data->update_lock); | 1459 | mutex_lock(&data->update_lock); |
1460 | data->pwm_auto_point_mapping[nr] = | ||
1461 | f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr)); | ||
1437 | val = (data->pwm_auto_point_mapping[nr] & 0xfc) | val; | 1462 | val = (data->pwm_auto_point_mapping[nr] & 0xfc) | val; |
1438 | f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val); | 1463 | f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val); |
1439 | data->pwm_auto_point_mapping[nr] = val; | 1464 | data->pwm_auto_point_mapping[nr] = val; |
@@ -1459,8 +1484,7 @@ static ssize_t store_pwm_auto_point_temp(struct device *dev, | |||
1459 | struct device_attribute *devattr, | 1484 | struct device_attribute *devattr, |
1460 | const char *buf, size_t count) | 1485 | const char *buf, size_t count) |
1461 | { | 1486 | { |
1462 | /* struct f71882fg_data *data = dev_get_drvdata(dev); */ | 1487 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1463 | struct f71882fg_data *data = f71882fg_update_device(dev); | ||
1464 | int pwm = to_sensor_dev_attr_2(devattr)->index; | 1488 | int pwm = to_sensor_dev_attr_2(devattr)->index; |
1465 | int point = to_sensor_dev_attr_2(devattr)->nr; | 1489 | int point = to_sensor_dev_attr_2(devattr)->nr; |
1466 | long val = simple_strtol(buf, NULL, 10) / 1000; | 1490 | long val = simple_strtol(buf, NULL, 10) / 1000; |