Commit 1c720093f635af490e103c79c056e7408aee6618
Committed by
Jean Delvare
1 parent
16b5dda22e
Exists in
master
and in
6 other branches
hwmon: (adm1031) Fix coding style issues
Fix almost all coding style issues except for the multi-line macro errors, which do not really apply since the macros are not multi-line statements but declarations. Based on merged patch series from Zac Storer; fixed remaining checkpatch errors and warnings. Cc: Zac Storer <zac.3.14159@gmail.com> Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com> Signed-off-by: Jean Delvare <khali@linux-fr.org>
Showing 1 changed file with 103 additions and 50 deletions Side-by-side Diff
drivers/hwmon/adm1031.c
... | ... | @@ -155,7 +155,8 @@ |
155 | 155 | #define TEMP_OFFSET_FROM_REG(val) TEMP_FROM_REG((val) < 0 ? \ |
156 | 156 | (val) | 0x70 : (val)) |
157 | 157 | |
158 | -#define FAN_FROM_REG(reg, div) ((reg) ? (11250 * 60) / ((reg) * (div)) : 0) | |
158 | +#define FAN_FROM_REG(reg, div) ((reg) ? \ | |
159 | + (11250 * 60) / ((reg) * (div)) : 0) | |
159 | 160 | |
160 | 161 | static int FAN_TO_REG(int reg, int div) |
161 | 162 | { |
... | ... | @@ -174,8 +175,8 @@ |
174 | 175 | (((reg) & 0x1F) | (((val) << 5) & 0xe0)) |
175 | 176 | |
176 | 177 | #define AUTO_TEMP_MIN_TO_REG(val, reg) \ |
177 | - ((((val)/500) & 0xf8)|((reg) & 0x7)) | |
178 | -#define AUTO_TEMP_RANGE_FROM_REG(reg) (5000 * (1<< ((reg)&0x7))) | |
178 | + ((((val) / 500) & 0xf8) | ((reg) & 0x7)) | |
179 | +#define AUTO_TEMP_RANGE_FROM_REG(reg) (5000 * (1 << ((reg) & 0x7))) | |
179 | 180 | #define AUTO_TEMP_MIN_FROM_REG(reg) (1000 * ((((reg) >> 3) & 0x1f) << 2)) |
180 | 181 | |
181 | 182 | #define AUTO_TEMP_MIN_FROM_REG_DEG(reg) ((((reg) >> 3) & 0x1f) << 2) |
... | ... | @@ -202,7 +203,7 @@ |
202 | 203 | |
203 | 204 | /* FAN auto control */ |
204 | 205 | #define GET_FAN_AUTO_BITFIELD(data, idx) \ |
205 | - (*(data)->chan_select_table)[FAN_CHAN_FROM_REG((data)->conf1)][idx%2] | |
206 | + (*(data)->chan_select_table)[FAN_CHAN_FROM_REG((data)->conf1)][idx % 2] | |
206 | 207 | |
207 | 208 | /* The tables below contains the possible values for the auto fan |
208 | 209 | * control bitfields. the index in the table is the register value. |
... | ... | @@ -230,7 +231,7 @@ |
230 | 231 | */ |
231 | 232 | static int |
232 | 233 | get_fan_auto_nearest(struct adm1031_data *data, |
233 | - int chan, u8 val, u8 reg, u8 * new_reg) | |
234 | + int chan, u8 val, u8 reg, u8 *new_reg) | |
234 | 235 | { |
235 | 236 | int i; |
236 | 237 | int first_match = -1, exact_match = -1; |
237 | 238 | |
238 | 239 | |
239 | 240 | |
... | ... | @@ -258,13 +259,13 @@ |
258 | 259 | } |
259 | 260 | } |
260 | 261 | |
261 | - if (exact_match >= 0) { | |
262 | + if (exact_match >= 0) | |
262 | 263 | *new_reg = exact_match; |
263 | - } else if (first_match >= 0) { | |
264 | + else if (first_match >= 0) | |
264 | 265 | *new_reg = first_match; |
265 | - } else { | |
266 | + else | |
266 | 267 | return -EINVAL; |
267 | - } | |
268 | + | |
268 | 269 | return 0; |
269 | 270 | } |
270 | 271 | |
271 | 272 | |
272 | 273 | |
273 | 274 | |
... | ... | @@ -283,23 +284,28 @@ |
283 | 284 | struct i2c_client *client = to_i2c_client(dev); |
284 | 285 | struct adm1031_data *data = i2c_get_clientdata(client); |
285 | 286 | int nr = to_sensor_dev_attr(attr)->index; |
286 | - int val = simple_strtol(buf, NULL, 10); | |
287 | + long val; | |
287 | 288 | u8 reg; |
288 | 289 | int ret; |
289 | 290 | u8 old_fan_mode; |
290 | 291 | |
292 | + ret = kstrtol(buf, 10, &val); | |
293 | + if (ret) | |
294 | + return ret; | |
295 | + | |
291 | 296 | old_fan_mode = data->conf1; |
292 | 297 | |
293 | 298 | mutex_lock(&data->update_lock); |
294 | 299 | |
295 | - if ((ret = get_fan_auto_nearest(data, nr, val, data->conf1, ®))) { | |
300 | + ret = get_fan_auto_nearest(data, nr, val, data->conf1, ®); | |
301 | + if (ret) { | |
296 | 302 | mutex_unlock(&data->update_lock); |
297 | 303 | return ret; |
298 | 304 | } |
299 | 305 | data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1); |
300 | 306 | if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) ^ |
301 | 307 | (old_fan_mode & ADM1031_CONF1_AUTO_MODE)) { |
302 | - if (data->conf1 & ADM1031_CONF1_AUTO_MODE){ | |
308 | + if (data->conf1 & ADM1031_CONF1_AUTO_MODE) { | |
303 | 309 | /* Switch to Auto Fan Mode |
304 | 310 | * Save PWM registers |
305 | 311 | * Set PWM registers to 33% Both */ |
306 | 312 | |
... | ... | @@ -350,8 +356,13 @@ |
350 | 356 | struct i2c_client *client = to_i2c_client(dev); |
351 | 357 | struct adm1031_data *data = i2c_get_clientdata(client); |
352 | 358 | int nr = to_sensor_dev_attr(attr)->index; |
353 | - int val = simple_strtol(buf, NULL, 10); | |
359 | + long val; | |
360 | + int ret; | |
354 | 361 | |
362 | + ret = kstrtol(buf, 10, &val); | |
363 | + if (ret) | |
364 | + return ret; | |
365 | + | |
355 | 366 | mutex_lock(&data->update_lock); |
356 | 367 | data->auto_temp[nr] = AUTO_TEMP_MIN_TO_REG(val, data->auto_temp[nr]); |
357 | 368 | adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr), |
358 | 369 | |
359 | 370 | |
... | ... | @@ -374,10 +385,16 @@ |
374 | 385 | struct i2c_client *client = to_i2c_client(dev); |
375 | 386 | struct adm1031_data *data = i2c_get_clientdata(client); |
376 | 387 | int nr = to_sensor_dev_attr(attr)->index; |
377 | - int val = simple_strtol(buf, NULL, 10); | |
388 | + long val; | |
389 | + int ret; | |
378 | 390 | |
391 | + ret = kstrtol(buf, 10, &val); | |
392 | + if (ret) | |
393 | + return ret; | |
394 | + | |
379 | 395 | mutex_lock(&data->update_lock); |
380 | - data->temp_max[nr] = AUTO_TEMP_MAX_TO_REG(val, data->auto_temp[nr], data->pwm[nr]); | |
396 | + data->temp_max[nr] = AUTO_TEMP_MAX_TO_REG(val, data->auto_temp[nr], | |
397 | + data->pwm[nr]); | |
381 | 398 | adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr), |
382 | 399 | data->temp_max[nr]); |
383 | 400 | mutex_unlock(&data->update_lock); |
384 | 401 | |
... | ... | @@ -410,9 +427,13 @@ |
410 | 427 | struct i2c_client *client = to_i2c_client(dev); |
411 | 428 | struct adm1031_data *data = i2c_get_clientdata(client); |
412 | 429 | int nr = to_sensor_dev_attr(attr)->index; |
413 | - int val = simple_strtol(buf, NULL, 10); | |
414 | - int reg; | |
430 | + long val; | |
431 | + int ret, reg; | |
415 | 432 | |
433 | + ret = kstrtol(buf, 10, &val); | |
434 | + if (ret) | |
435 | + return ret; | |
436 | + | |
416 | 437 | mutex_lock(&data->update_lock); |
417 | 438 | if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) && |
418 | 439 | (((val>>4) & 0xf) != 5)) { |
419 | 440 | |
... | ... | @@ -449,9 +470,13 @@ |
449 | 470 | |
450 | 471 | if (data->conf1 & ADM1031_CONF1_AUTO_MODE) { |
451 | 472 | switch (data->conf1 & 0x60) { |
452 | - case 0x00: /* remote temp1 controls fan1 remote temp2 controls fan2 */ | |
473 | + case 0x00: | |
474 | + /* | |
475 | + * remote temp1 controls fan1, | |
476 | + * remote temp2 controls fan2 | |
477 | + */ | |
453 | 478 | res = data->temp[chan+1] >= |
454 | - AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[chan+1]); | |
479 | + AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[chan+1]); | |
455 | 480 | break; |
456 | 481 | case 0x20: /* remote temp1 controls both fans */ |
457 | 482 | res = |
458 | 483 | |
... | ... | @@ -515,8 +540,13 @@ |
515 | 540 | struct i2c_client *client = to_i2c_client(dev); |
516 | 541 | struct adm1031_data *data = i2c_get_clientdata(client); |
517 | 542 | int nr = to_sensor_dev_attr(attr)->index; |
518 | - int val = simple_strtol(buf, NULL, 10); | |
543 | + long val; | |
544 | + int ret; | |
519 | 545 | |
546 | + ret = kstrtol(buf, 10, &val); | |
547 | + if (ret) | |
548 | + return ret; | |
549 | + | |
520 | 550 | mutex_lock(&data->update_lock); |
521 | 551 | if (val) { |
522 | 552 | data->fan_min[nr] = |
523 | 553 | |
524 | 554 | |
... | ... | @@ -534,11 +564,16 @@ |
534 | 564 | struct i2c_client *client = to_i2c_client(dev); |
535 | 565 | struct adm1031_data *data = i2c_get_clientdata(client); |
536 | 566 | int nr = to_sensor_dev_attr(attr)->index; |
537 | - int val = simple_strtol(buf, NULL, 10); | |
567 | + long val; | |
538 | 568 | u8 tmp; |
539 | 569 | int old_div; |
540 | 570 | int new_min; |
571 | + int ret; | |
541 | 572 | |
573 | + ret = kstrtol(buf, 10, &val); | |
574 | + if (ret) | |
575 | + return ret; | |
576 | + | |
542 | 577 | tmp = val == 8 ? 0xc0 : |
543 | 578 | val == 4 ? 0x80 : |
544 | 579 | val == 2 ? 0x40 : |
545 | 580 | |
... | ... | @@ -631,9 +666,13 @@ |
631 | 666 | struct i2c_client *client = to_i2c_client(dev); |
632 | 667 | struct adm1031_data *data = i2c_get_clientdata(client); |
633 | 668 | int nr = to_sensor_dev_attr(attr)->index; |
634 | - int val; | |
669 | + long val; | |
670 | + int ret; | |
635 | 671 | |
636 | - val = simple_strtol(buf, NULL, 10); | |
672 | + ret = kstrtol(buf, 10, &val); | |
673 | + if (ret) | |
674 | + return ret; | |
675 | + | |
637 | 676 | val = SENSORS_LIMIT(val, -15000, 15000); |
638 | 677 | mutex_lock(&data->update_lock); |
639 | 678 | data->temp_offset[nr] = TEMP_OFFSET_TO_REG(val); |
640 | 679 | |
... | ... | @@ -648,9 +687,13 @@ |
648 | 687 | struct i2c_client *client = to_i2c_client(dev); |
649 | 688 | struct adm1031_data *data = i2c_get_clientdata(client); |
650 | 689 | int nr = to_sensor_dev_attr(attr)->index; |
651 | - int val; | |
690 | + long val; | |
691 | + int ret; | |
652 | 692 | |
653 | - val = simple_strtol(buf, NULL, 10); | |
693 | + ret = kstrtol(buf, 10, &val); | |
694 | + if (ret) | |
695 | + return ret; | |
696 | + | |
654 | 697 | val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875); |
655 | 698 | mutex_lock(&data->update_lock); |
656 | 699 | data->temp_min[nr] = TEMP_TO_REG(val); |
657 | 700 | |
... | ... | @@ -665,9 +708,13 @@ |
665 | 708 | struct i2c_client *client = to_i2c_client(dev); |
666 | 709 | struct adm1031_data *data = i2c_get_clientdata(client); |
667 | 710 | int nr = to_sensor_dev_attr(attr)->index; |
668 | - int val; | |
711 | + long val; | |
712 | + int ret; | |
669 | 713 | |
670 | - val = simple_strtol(buf, NULL, 10); | |
714 | + ret = kstrtol(buf, 10, &val); | |
715 | + if (ret) | |
716 | + return ret; | |
717 | + | |
671 | 718 | val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875); |
672 | 719 | mutex_lock(&data->update_lock); |
673 | 720 | data->temp_max[nr] = TEMP_TO_REG(val); |
674 | 721 | |
... | ... | @@ -682,9 +729,13 @@ |
682 | 729 | struct i2c_client *client = to_i2c_client(dev); |
683 | 730 | struct adm1031_data *data = i2c_get_clientdata(client); |
684 | 731 | int nr = to_sensor_dev_attr(attr)->index; |
685 | - int val; | |
732 | + long val; | |
733 | + int ret; | |
686 | 734 | |
687 | - val = simple_strtol(buf, NULL, 10); | |
735 | + ret = kstrtol(buf, 10, &val); | |
736 | + if (ret) | |
737 | + return ret; | |
738 | + | |
688 | 739 | val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875); |
689 | 740 | mutex_lock(&data->update_lock); |
690 | 741 | data->temp_crit[nr] = TEMP_TO_REG(val); |
... | ... | @@ -711,7 +762,8 @@ |
711 | 762 | temp_reg(3); |
712 | 763 | |
713 | 764 | /* Alarms */ |
714 | -static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) | |
765 | +static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, | |
766 | + char *buf) | |
715 | 767 | { |
716 | 768 | struct adm1031_data *data = adm1031_update_device(dev); |
717 | 769 | return sprintf(buf, "%d\n", data->alarm); |
718 | 770 | |
... | ... | @@ -919,12 +971,13 @@ |
919 | 971 | adm1031_init_client(client); |
920 | 972 | |
921 | 973 | /* Register sysfs hooks */ |
922 | - if ((err = sysfs_create_group(&client->dev.kobj, &adm1031_group))) | |
974 | + err = sysfs_create_group(&client->dev.kobj, &adm1031_group); | |
975 | + if (err) | |
923 | 976 | goto exit_free; |
924 | 977 | |
925 | 978 | if (data->chip_type == adm1031) { |
926 | - if ((err = sysfs_create_group(&client->dev.kobj, | |
927 | - &adm1031_group_opt))) | |
979 | + err = sysfs_create_group(&client->dev.kobj, &adm1031_group_opt); | |
980 | + if (err) | |
928 | 981 | goto exit_remove; |
929 | 982 | } |
930 | 983 | |
931 | 984 | |
... | ... | @@ -970,14 +1023,13 @@ |
970 | 1023 | } |
971 | 1024 | /* Initialize the ADM1031 chip (enables fan speed reading ) */ |
972 | 1025 | read_val = adm1031_read_value(client, ADM1031_REG_CONF2); |
973 | - if ((read_val | mask) != read_val) { | |
974 | - adm1031_write_value(client, ADM1031_REG_CONF2, read_val | mask); | |
975 | - } | |
1026 | + if ((read_val | mask) != read_val) | |
1027 | + adm1031_write_value(client, ADM1031_REG_CONF2, read_val | mask); | |
976 | 1028 | |
977 | 1029 | read_val = adm1031_read_value(client, ADM1031_REG_CONF1); |
978 | 1030 | if ((read_val | ADM1031_CONF1_MONITOR_ENABLE) != read_val) { |
979 | - adm1031_write_value(client, ADM1031_REG_CONF1, read_val | | |
980 | - ADM1031_CONF1_MONITOR_ENABLE); | |
1031 | + adm1031_write_value(client, ADM1031_REG_CONF1, | |
1032 | + read_val | ADM1031_CONF1_MONITOR_ENABLE); | |
981 | 1033 | } |
982 | 1034 | |
983 | 1035 | /* Read the chip's update rate */ |
... | ... | @@ -1024,8 +1076,7 @@ |
1024 | 1076 | /* oldh is actually newer */ |
1025 | 1077 | if (newh != oldh) |
1026 | 1078 | dev_warn(&client->dev, |
1027 | - "Remote temperature may be " | |
1028 | - "wrong.\n"); | |
1079 | + "Remote temperature may be wrong.\n"); | |
1029 | 1080 | #endif |
1030 | 1081 | } |
1031 | 1082 | data->temp[chan] = newh; |
1032 | 1083 | |
1033 | 1084 | |
1034 | 1085 | |
1035 | 1086 | |
1036 | 1087 | |
1037 | 1088 | |
... | ... | @@ -1052,22 +1103,24 @@ |
1052 | 1103 | data->conf2 = adm1031_read_value(client, ADM1031_REG_CONF2); |
1053 | 1104 | |
1054 | 1105 | data->alarm = adm1031_read_value(client, ADM1031_REG_STATUS(0)) |
1055 | - | (adm1031_read_value(client, ADM1031_REG_STATUS(1)) | |
1056 | - << 8); | |
1057 | - if (data->chip_type == adm1030) { | |
1106 | + | (adm1031_read_value(client, ADM1031_REG_STATUS(1)) << 8); | |
1107 | + if (data->chip_type == adm1030) | |
1058 | 1108 | data->alarm &= 0xc0ff; |
1059 | - } | |
1060 | 1109 | |
1061 | - for (chan=0; chan<(data->chip_type == adm1030 ? 1 : 2); chan++) { | |
1110 | + for (chan = 0; chan < (data->chip_type == adm1030 ? 1 : 2); | |
1111 | + chan++) { | |
1062 | 1112 | data->fan_div[chan] = |
1063 | - adm1031_read_value(client, ADM1031_REG_FAN_DIV(chan)); | |
1113 | + adm1031_read_value(client, | |
1114 | + ADM1031_REG_FAN_DIV(chan)); | |
1064 | 1115 | data->fan_min[chan] = |
1065 | - adm1031_read_value(client, ADM1031_REG_FAN_MIN(chan)); | |
1116 | + adm1031_read_value(client, | |
1117 | + ADM1031_REG_FAN_MIN(chan)); | |
1066 | 1118 | data->fan[chan] = |
1067 | - adm1031_read_value(client, ADM1031_REG_FAN_SPEED(chan)); | |
1119 | + adm1031_read_value(client, | |
1120 | + ADM1031_REG_FAN_SPEED(chan)); | |
1068 | 1121 | data->pwm[chan] = |
1069 | - 0xf & (adm1031_read_value(client, ADM1031_REG_PWM) >> | |
1070 | - (4*chan)); | |
1122 | + (adm1031_read_value(client, | |
1123 | + ADM1031_REG_PWM) >> (4 * chan)) & 0x0f; | |
1071 | 1124 | } |
1072 | 1125 | data->last_updated = jiffies; |
1073 | 1126 | data->valid = 1; |