Commit dc71afe5ac7e8d049bb991330518e4c898a7d92e
1 parent
a44908d742
Exists in
master
and in
7 other branches
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
Showing 3 changed files with 11 additions and 15 deletions Side-by-side Diff
drivers/hwmon/fschmd.c
... | ... | @@ -267,7 +267,7 @@ |
267 | 267 | struct list_head list; /* member of the watchdog_data_list */ |
268 | 268 | struct kref kref; |
269 | 269 | struct miscdevice watchdog_miscdev; |
270 | - int kind; | |
270 | + enum chips kind; | |
271 | 271 | unsigned long watchdog_is_open; |
272 | 272 | char watchdog_expect_close; |
273 | 273 | char watchdog_name[10]; /* must be unique to avoid sysfs conflict */ |
... | ... | @@ -325,8 +325,7 @@ |
325 | 325 | int index = to_sensor_dev_attr(devattr)->index; |
326 | 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 */ | |
329 | - if (data->kind == (fscher - 1) || data->kind >= (fschrc - 1)) | |
328 | + if (data->kind == fscher || data->kind >= fschrc) | |
330 | 329 | return sprintf(buf, "%d\n", (data->volt[index] * dmi_vref * |
331 | 330 | dmi_mult[index]) / 255 + dmi_offset[index]); |
332 | 331 | else |
... | ... | @@ -492,7 +491,7 @@ |
492 | 491 | int val = data->fan_min[index]; |
493 | 492 | |
494 | 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 | 495 | val = val / 2 + 128; |
497 | 496 | |
498 | 497 | return sprintf(buf, "%d\n", val); |
... | ... | @@ -506,7 +505,7 @@ |
506 | 505 | unsigned long v = simple_strtoul(buf, NULL, 10); |
507 | 506 | |
508 | 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 | 509 | v = SENSORS_LIMIT(v, 128, 255); |
511 | 510 | v = (v - 128) * 2 + 1; |
512 | 511 | } |
... | ... | @@ -1037,7 +1036,7 @@ |
1037 | 1036 | else |
1038 | 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 | 1041 | return 0; |
1043 | 1042 | } |
... | ... | @@ -1065,6 +1064,7 @@ |
1065 | 1064 | (where the client is found through a data ptr instead of the |
1066 | 1065 | otherway around) */ |
1067 | 1066 | data->client = client; |
1067 | + data->kind = kind; | |
1068 | 1068 | |
1069 | 1069 | if (kind == fscpos) { |
1070 | 1070 | /* The Poseidon has hardwired temp limits, fill these |
... | ... | @@ -1084,9 +1084,6 @@ |
1084 | 1084 | dmi_vref = 33; |
1085 | 1085 | } |
1086 | 1086 | } |
1087 | - | |
1088 | - /* i2c kind goes from 1-6, we want from 0-5 to address arrays */ | |
1089 | - data->kind = kind - 1; | |
1090 | 1087 | |
1091 | 1088 | /* Read in some never changing registers */ |
1092 | 1089 | data->revision = i2c_smbus_read_byte_data(client, FSCHMD_REG_REVISION); |
drivers/hwmon/tmp401.c
... | ... | @@ -134,7 +134,7 @@ |
134 | 134 | struct mutex update_lock; |
135 | 135 | char valid; /* zero until following fields are valid */ |
136 | 136 | unsigned long last_updated; /* in jiffies */ |
137 | - int kind; | |
137 | + enum chips kind; | |
138 | 138 | |
139 | 139 | /* register values */ |
140 | 140 | u8 status; |
... | ... | @@ -524,7 +524,7 @@ |
524 | 524 | if (reg > 15) |
525 | 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 | 529 | return 0; |
530 | 530 | } |
... | ... | @@ -572,8 +572,7 @@ |
572 | 572 | goto exit_remove; |
573 | 573 | } |
574 | 574 | |
575 | - dev_info(&client->dev, "Detected TI %s chip\n", | |
576 | - names[data->kind - 1]); | |
575 | + dev_info(&client->dev, "Detected TI %s chip\n", names[data->kind]); | |
577 | 576 | |
578 | 577 | return 0; |
579 | 578 |
drivers/hwmon/tmp421.c
... | ... | @@ -254,9 +254,9 @@ |
254 | 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 | 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 | 261 | return 0; |
262 | 262 | } |