diff options
author | Jean Delvare <khali@linux-fr.org> | 2010-03-05 16:17:26 -0500 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2010-03-05 16:17:26 -0500 |
commit | dc71afe5ac7e8d049bb991330518e4c898a7d92e (patch) | |
tree | d4062a740a4a287a933483a74c3393ddea67821d /drivers | |
parent | a44908d742a577fb5ccb9a8c082326d4cea234c2 (diff) |
hwmon: Fix off-by-one kind values
Recent changes on the I2C front have left off-by-one array indexes in
3 hwmon drivers. Fix them.
Faulty commit:
e5e9f44c2 i2c: Drop I2C_CLIENT_INSMOD_2 to 8
Reported-by: Dan Carpenter <error27@gmail.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Hans de Goede <hdegoede@redhat.com>
Cc: Andre Prendel <andre.prendel@gmx.de>
Cc: stable@kernel.org
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/hwmon/fschmd.c | 15 | ||||
-rw-r--r-- | drivers/hwmon/tmp401.c | 7 | ||||
-rw-r--r-- | drivers/hwmon/tmp421.c | 4 |
3 files changed, 11 insertions, 15 deletions
diff --git a/drivers/hwmon/fschmd.c b/drivers/hwmon/fschmd.c index fa0728232e71..0627f7a5b9b8 100644 --- a/drivers/hwmon/fschmd.c +++ b/drivers/hwmon/fschmd.c | |||
@@ -267,7 +267,7 @@ struct fschmd_data { | |||
267 | struct list_head list; /* member of the watchdog_data_list */ | 267 | struct list_head list; /* member of the watchdog_data_list */ |
268 | struct kref kref; | 268 | struct kref kref; |
269 | struct miscdevice watchdog_miscdev; | 269 | struct miscdevice watchdog_miscdev; |
270 | int kind; | 270 | enum chips kind; |
271 | unsigned long watchdog_is_open; | 271 | unsigned long watchdog_is_open; |
272 | char watchdog_expect_close; | 272 | char watchdog_expect_close; |
273 | char watchdog_name[10]; /* must be unique to avoid sysfs conflict */ | 273 | char watchdog_name[10]; /* must be unique to avoid sysfs conflict */ |
@@ -325,8 +325,7 @@ static ssize_t show_in_value(struct device *dev, | |||
325 | int index = to_sensor_dev_attr(devattr)->index; | 325 | int index = to_sensor_dev_attr(devattr)->index; |
326 | struct fschmd_data *data = fschmd_update_device(dev); | 326 | struct fschmd_data *data = fschmd_update_device(dev); |
327 | 327 | ||
328 | /* fscher / fschrc - 1 as data->kind is an array index, not a chips */ | 328 | if (data->kind == fscher || data->kind >= fschrc) |
329 | if (data->kind == (fscher - 1) || data->kind >= (fschrc - 1)) | ||
330 | return sprintf(buf, "%d\n", (data->volt[index] * dmi_vref * | 329 | return sprintf(buf, "%d\n", (data->volt[index] * dmi_vref * |
331 | dmi_mult[index]) / 255 + dmi_offset[index]); | 330 | dmi_mult[index]) / 255 + dmi_offset[index]); |
332 | else | 331 | else |
@@ -492,7 +491,7 @@ static ssize_t show_pwm_auto_point1_pwm(struct device *dev, | |||
492 | int val = data->fan_min[index]; | 491 | int val = data->fan_min[index]; |
493 | 492 | ||
494 | /* 0 = allow turning off (except on the syl), 1-255 = 50-100% */ | 493 | /* 0 = allow turning off (except on the syl), 1-255 = 50-100% */ |
495 | if (val || data->kind == fscsyl - 1) | 494 | if (val || data->kind == fscsyl) |
496 | val = val / 2 + 128; | 495 | val = val / 2 + 128; |
497 | 496 | ||
498 | return sprintf(buf, "%d\n", val); | 497 | return sprintf(buf, "%d\n", val); |
@@ -506,7 +505,7 @@ static ssize_t store_pwm_auto_point1_pwm(struct device *dev, | |||
506 | unsigned long v = simple_strtoul(buf, NULL, 10); | 505 | unsigned long v = simple_strtoul(buf, NULL, 10); |
507 | 506 | ||
508 | /* reg: 0 = allow turning off (except on the syl), 1-255 = 50-100% */ | 507 | /* reg: 0 = allow turning off (except on the syl), 1-255 = 50-100% */ |
509 | if (v || data->kind == fscsyl - 1) { | 508 | if (v || data->kind == fscsyl) { |
510 | v = SENSORS_LIMIT(v, 128, 255); | 509 | v = SENSORS_LIMIT(v, 128, 255); |
511 | v = (v - 128) * 2 + 1; | 510 | v = (v - 128) * 2 + 1; |
512 | } | 511 | } |
@@ -1037,7 +1036,7 @@ static int fschmd_detect(struct i2c_client *client, | |||
1037 | else | 1036 | else |
1038 | return -ENODEV; | 1037 | return -ENODEV; |
1039 | 1038 | ||
1040 | strlcpy(info->type, fschmd_id[kind - 1].name, I2C_NAME_SIZE); | 1039 | strlcpy(info->type, fschmd_id[kind].name, I2C_NAME_SIZE); |
1041 | 1040 | ||
1042 | return 0; | 1041 | return 0; |
1043 | } | 1042 | } |
@@ -1065,6 +1064,7 @@ static int fschmd_probe(struct i2c_client *client, | |||
1065 | (where the client is found through a data ptr instead of the | 1064 | (where the client is found through a data ptr instead of the |
1066 | otherway around) */ | 1065 | otherway around) */ |
1067 | data->client = client; | 1066 | data->client = client; |
1067 | data->kind = kind; | ||
1068 | 1068 | ||
1069 | if (kind == fscpos) { | 1069 | if (kind == fscpos) { |
1070 | /* The Poseidon has hardwired temp limits, fill these | 1070 | /* The Poseidon has hardwired temp limits, fill these |
@@ -1085,9 +1085,6 @@ static int fschmd_probe(struct i2c_client *client, | |||
1085 | } | 1085 | } |
1086 | } | 1086 | } |
1087 | 1087 | ||
1088 | /* i2c kind goes from 1-6, we want from 0-5 to address arrays */ | ||
1089 | data->kind = kind - 1; | ||
1090 | |||
1091 | /* Read in some never changing registers */ | 1088 | /* Read in some never changing registers */ |
1092 | data->revision = i2c_smbus_read_byte_data(client, FSCHMD_REG_REVISION); | 1089 | data->revision = i2c_smbus_read_byte_data(client, FSCHMD_REG_REVISION); |
1093 | data->global_control = i2c_smbus_read_byte_data(client, | 1090 | data->global_control = i2c_smbus_read_byte_data(client, |
diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c index a13b30e8d8d8..d14a1af9f550 100644 --- a/drivers/hwmon/tmp401.c +++ b/drivers/hwmon/tmp401.c | |||
@@ -134,7 +134,7 @@ struct tmp401_data { | |||
134 | struct mutex update_lock; | 134 | struct mutex update_lock; |
135 | char valid; /* zero until following fields are valid */ | 135 | char valid; /* zero until following fields are valid */ |
136 | unsigned long last_updated; /* in jiffies */ | 136 | unsigned long last_updated; /* in jiffies */ |
137 | int kind; | 137 | enum chips kind; |
138 | 138 | ||
139 | /* register values */ | 139 | /* register values */ |
140 | u8 status; | 140 | u8 status; |
@@ -524,7 +524,7 @@ static int tmp401_detect(struct i2c_client *client, | |||
524 | if (reg > 15) | 524 | if (reg > 15) |
525 | return -ENODEV; | 525 | return -ENODEV; |
526 | 526 | ||
527 | strlcpy(info->type, tmp401_id[kind - 1].name, I2C_NAME_SIZE); | 527 | strlcpy(info->type, tmp401_id[kind].name, I2C_NAME_SIZE); |
528 | 528 | ||
529 | return 0; | 529 | return 0; |
530 | } | 530 | } |
@@ -572,8 +572,7 @@ static int tmp401_probe(struct i2c_client *client, | |||
572 | goto exit_remove; | 572 | goto exit_remove; |
573 | } | 573 | } |
574 | 574 | ||
575 | dev_info(&client->dev, "Detected TI %s chip\n", | 575 | dev_info(&client->dev, "Detected TI %s chip\n", names[data->kind]); |
576 | names[data->kind - 1]); | ||
577 | 576 | ||
578 | return 0; | 577 | return 0; |
579 | 578 | ||
diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c index bb9760d7e8b6..738c472ece27 100644 --- a/drivers/hwmon/tmp421.c +++ b/drivers/hwmon/tmp421.c | |||
@@ -254,9 +254,9 @@ static int tmp421_detect(struct i2c_client *client, | |||
254 | return -ENODEV; | 254 | return -ENODEV; |
255 | } | 255 | } |
256 | 256 | ||
257 | strlcpy(info->type, tmp421_id[kind - 1].name, I2C_NAME_SIZE); | 257 | strlcpy(info->type, tmp421_id[kind].name, I2C_NAME_SIZE); |
258 | dev_info(&adapter->dev, "Detected TI %s chip at 0x%02x\n", | 258 | dev_info(&adapter->dev, "Detected TI %s chip at 0x%02x\n", |
259 | names[kind - 1], client->addr); | 259 | names[kind], client->addr); |
260 | 260 | ||
261 | return 0; | 261 | return 0; |
262 | } | 262 | } |