Commit d17436813a07b217027eccfa9561e59f9d3f479a

Authored by Guenter Roeck
Committed by Guenter Roeck
1 parent 2185696d7d

hwmon: (w83792d) Fix checkpatch issues

Fixed:
ERROR: code indent should use tabs where possible
ERROR: do not use assignment in if condition
ERROR: space prohibited after that open parenthesis '('
ERROR: space required after that ',' (ctx:VxV)
ERROR: space required after that ',' (ctx:WxV)
ERROR: spaces required around that ':' (ctx:VxE)
ERROR: spaces required around that '<=' (ctx:VxV)
ERROR: spaces required around that '<' (ctx:VxV)
ERROR: spaces required around that '==' (ctx:VxV)
ERROR: spaces required around that '=' (ctx:VxV)
ERROR: spaces required around that '||' (ctx:VxV)
ERROR: spaces required around that ':' (ctx:VxV)
ERROR: spaces required around that '?' (ctx:VxV)
WARNING: braces {} are not necessary for any arm of this statement
WARNING: braces {} are not necessary for single statement blocks
WARNING: line over 80 characters
WARNING: simple_strtol is obsolete, use kstrtol instead
WARNING: simple_strtoul is obsolete, use kstrtoul instead
WARNING: space prohibited between function name and open parenthesis '('

Modify multi-line comments to follow Documentation/CodingStyle.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Showing 1 changed file with 229 additions and 148 deletions Side-by-side Diff

drivers/hwmon/w83792d.c
1 1 /*
2   - w83792d.c - Part of lm_sensors, Linux kernel modules for hardware
3   - monitoring
4   - Copyright (C) 2004, 2005 Winbond Electronics Corp.
5   - Chunhao Huang <DZShen@Winbond.com.tw>,
6   - Rudolf Marek <r.marek@assembler.cz>
  2 + * w83792d.c - Part of lm_sensors, Linux kernel modules for hardware
  3 + * monitoring
  4 + * Copyright (C) 2004, 2005 Winbond Electronics Corp.
  5 + * Chunhao Huang <DZShen@Winbond.com.tw>,
  6 + * Rudolf Marek <r.marek@assembler.cz>
  7 + *
  8 + * This program is free software; you can redistribute it and/or modify
  9 + * it under the terms of the GNU General Public License as published by
  10 + * the Free Software Foundation; either version 2 of the License, or
  11 + * (at your option) any later version.
  12 + *
  13 + * This program is distributed in the hope that it will be useful,
  14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 + * GNU General Public License for more details.
  17 + *
  18 + * You should have received a copy of the GNU General Public License
  19 + * along with this program; if not, write to the Free Software
  20 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21 + *
  22 + * Note:
  23 + * 1. This driver is only for 2.6 kernel, 2.4 kernel need a different driver.
  24 + * 2. This driver is only for Winbond W83792D C version device, there
  25 + * are also some motherboards with B version W83792D device. The
  26 + * calculation method to in6-in7(measured value, limits) is a little
  27 + * different between C and B version. C or B version can be identified
  28 + * by CR[0x49h].
  29 + */
7 30  
8   - This program is free software; you can redistribute it and/or modify
9   - it under the terms of the GNU General Public License as published by
10   - the Free Software Foundation; either version 2 of the License, or
11   - (at your option) any later version.
12   -
13   - This program is distributed in the hope that it will be useful,
14   - but WITHOUT ANY WARRANTY; without even the implied warranty of
15   - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16   - GNU General Public License for more details.
17   -
18   - You should have received a copy of the GNU General Public License
19   - along with this program; if not, write to the Free Software
20   - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21   -
22   - Note:
23   - 1. This driver is only for 2.6 kernel, 2.4 kernel need a different driver.
24   - 2. This driver is only for Winbond W83792D C version device, there
25   - are also some motherboards with B version W83792D device. The
26   - calculation method to in6-in7(measured value, limits) is a little
27   - different between C and B version. C or B version can be identified
28   - by CR[0x49h].
29   -*/
30   -
31 31 /*
32   - Supports following chips:
  32 + * Supports following chips:
  33 + *
  34 + * Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
  35 + * w83792d 9 7 7 3 0x7a 0x5ca3 yes no
  36 + */
33 37  
34   - Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
35   - w83792d 9 7 7 3 0x7a 0x5ca3 yes no
36   -*/
37   -
38 38 #include <linux/module.h>
39 39 #include <linux/init.h>
40 40 #include <linux/slab.h>
... ... @@ -218,14 +218,16 @@
218 218 #define W83792D_REG_VBAT 0x5D
219 219 #define W83792D_REG_I2C_ADDR 0x48
220 220  
221   -/* Conversions. Rounding and limit checking is only done on the TO_REG
222   - variants. Note that you should be a bit careful with which arguments
223   - these macros are called: arguments may be evaluated more than once.
224   - Fixing this is just not worth it. */
225   -#define IN_FROM_REG(nr,val) (((nr)<=1)?(val*2): \
226   - ((((nr)==6)||((nr)==7))?(val*6):(val*4)))
227   -#define IN_TO_REG(nr,val) (((nr)<=1)?(val/2): \
228   - ((((nr)==6)||((nr)==7))?(val/6):(val/4)))
  221 +/*
  222 + * Conversions. Rounding and limit checking is only done on the TO_REG
  223 + * variants. Note that you should be a bit careful with which arguments
  224 + * these macros are called: arguments may be evaluated more than once.
  225 + * Fixing this is just not worth it.
  226 + */
  227 +#define IN_FROM_REG(nr, val) (((nr) <= 1) ? ((val) * 2) : \
  228 + ((((nr) == 6) || ((nr) == 7)) ? ((val) * 6) : ((val) * 4)))
  229 +#define IN_TO_REG(nr, val) (((nr) <= 1) ? ((val) / 2) : \
  230 + ((((nr) == 6) || ((nr) == 7)) ? ((val) / 6) : ((val) / 4)))
229 231  
230 232 static inline u8
231 233 FAN_TO_REG(long rpm, int div)
... ... @@ -236,7 +238,7 @@
236 238 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
237 239 }
238 240  
239   -#define FAN_FROM_REG(val,div) ((val) == 0 ? -1 : \
  241 +#define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \
240 242 ((val) == 255 ? 0 : \
241 243 1350000 / ((val) * (div))))
242 244  
... ... @@ -287,8 +289,10 @@
287 289 u8 temp1[3]; /* current, over, thyst */
288 290 u8 temp_add[2][6]; /* Register value */
289 291 u8 fan_div[7]; /* Register encoding, shifted right */
290   - u8 pwm[7]; /* We only consider the first 3 set of pwm,
291   - although 792 chip has 7 set of pwm. */
  292 + u8 pwm[7]; /*
  293 + * We only consider the first 3 set of pwm,
  294 + * although 792 chip has 7 set of pwm.
  295 + */
292 296 u8 pwmenable[3];
293 297 u32 alarms; /* realtime status register encoding,combined */
294 298 u8 chassis; /* Chassis status */
... ... @@ -336,9 +340,11 @@
336 340 return (data->in[nr] << 2) | ((data->low_bits >> (2 * nr)) & 0x03);
337 341 }
338 342  
339   -/* The SMBus locks itself. The Winbond W83792D chip has a bank register,
340   - but the driver only accesses registers in bank 0, so we don't have
341   - to switch banks and lock access between switches. */
  343 +/*
  344 + * The SMBus locks itself. The Winbond W83792D chip has a bank register,
  345 + * but the driver only accesses registers in bank 0, so we don't have
  346 + * to switch banks and lock access between switches.
  347 + */
342 348 static inline int w83792d_read_value(struct i2c_client *client, u8 reg)
343 349 {
344 350 return i2c_smbus_read_byte_data(client, reg);
345 351  
346 352  
347 353  
348 354  
349 355  
350 356  
... ... @@ -357,37 +363,43 @@
357 363 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
358 364 int nr = sensor_attr->index;
359 365 struct w83792d_data *data = w83792d_update_device(dev);
360   - return sprintf(buf,"%ld\n", IN_FROM_REG(nr,(in_count_from_reg(nr, data))));
  366 + return sprintf(buf, "%ld\n",
  367 + IN_FROM_REG(nr, in_count_from_reg(nr, data)));
361 368 }
362 369  
363 370 #define show_in_reg(reg) \
364 371 static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
365 372 char *buf) \
366 373 { \
367   - struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
  374 + struct sensor_device_attribute *sensor_attr \
  375 + = to_sensor_dev_attr(attr); \
368 376 int nr = sensor_attr->index; \
369 377 struct w83792d_data *data = w83792d_update_device(dev); \
370   - return sprintf(buf,"%ld\n", (long)(IN_FROM_REG(nr, (data->reg[nr])*4))); \
  378 + return sprintf(buf, "%ld\n", \
  379 + (long)(IN_FROM_REG(nr, data->reg[nr]) * 4)); \
371 380 }
372 381  
373 382 show_in_reg(in_min);
374 383 show_in_reg(in_max);
375 384  
376 385 #define store_in_reg(REG, reg) \
377   -static ssize_t store_in_##reg (struct device *dev, \
  386 +static ssize_t store_in_##reg(struct device *dev, \
378 387 struct device_attribute *attr, \
379 388 const char *buf, size_t count) \
380 389 { \
381   - struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
  390 + struct sensor_device_attribute *sensor_attr \
  391 + = to_sensor_dev_attr(attr); \
382 392 int nr = sensor_attr->index; \
383 393 struct i2c_client *client = to_i2c_client(dev); \
384 394 struct w83792d_data *data = i2c_get_clientdata(client); \
385   - u32 val; \
386   - \
387   - val = simple_strtoul(buf, NULL, 10); \
  395 + unsigned long val; \
  396 + int err = kstrtoul(buf, 10, &val); \
  397 + if (err) \
  398 + return err; \
388 399 mutex_lock(&data->update_lock); \
389   - data->in_##reg[nr] = SENSORS_LIMIT(IN_TO_REG(nr, val)/4, 0, 255); \
390   - w83792d_write_value(client, W83792D_REG_IN_##REG[nr], data->in_##reg[nr]); \
  400 + data->in_##reg[nr] = SENSORS_LIMIT(IN_TO_REG(nr, val) / 4, 0, 255); \
  401 + w83792d_write_value(client, W83792D_REG_IN_##REG[nr], \
  402 + data->in_##reg[nr]); \
391 403 mutex_unlock(&data->update_lock); \
392 404 \
393 405 return count; \
394 406  
395 407  
... ... @@ -396,13 +408,14 @@
396 408 store_in_reg(MAX, max);
397 409  
398 410 #define show_fan_reg(reg) \
399   -static ssize_t show_##reg (struct device *dev, struct device_attribute *attr, \
  411 +static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
400 412 char *buf) \
401 413 { \
402   - struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
  414 + struct sensor_device_attribute *sensor_attr \
  415 + = to_sensor_dev_attr(attr); \
403 416 int nr = sensor_attr->index - 1; \
404 417 struct w83792d_data *data = w83792d_update_device(dev); \
405   - return sprintf(buf,"%d\n", \
  418 + return sprintf(buf, "%d\n", \
406 419 FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \
407 420 }
408 421  
409 422  
... ... @@ -417,9 +430,13 @@
417 430 int nr = sensor_attr->index - 1;
418 431 struct i2c_client *client = to_i2c_client(dev);
419 432 struct w83792d_data *data = i2c_get_clientdata(client);
420   - u32 val;
  433 + unsigned long val;
  434 + int err;
421 435  
422   - val = simple_strtoul(buf, NULL, 10);
  436 + err = kstrtoul(buf, 10, &val);
  437 + if (err)
  438 + return err;
  439 +
423 440 mutex_lock(&data->update_lock);
424 441 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
425 442 w83792d_write_value(client, W83792D_REG_FAN_MIN[nr],
... ... @@ -439,10 +456,12 @@
439 456 return sprintf(buf, "%u\n", DIV_FROM_REG(data->fan_div[nr - 1]));
440 457 }
441 458  
442   -/* Note: we save and restore the fan minimum here, because its value is
443   - determined in part by the fan divisor. This follows the principle of
444   - least surprise; the user doesn't expect the fan minimum to change just
445   - because the divisor changed. */
  459 +/*
  460 + * Note: we save and restore the fan minimum here, because its value is
  461 + * determined in part by the fan divisor. This follows the principle of
  462 + * least surprise; the user doesn't expect the fan minimum to change just
  463 + * because the divisor changed.
  464 + */
446 465 static ssize_t
447 466 store_fan_div(struct device *dev, struct device_attribute *attr,
448 467 const char *buf, size_t count)
449 468  
450 469  
... ... @@ -455,13 +474,19 @@
455 474 /*u8 reg;*/
456 475 u8 fan_div_reg = 0;
457 476 u8 tmp_fan_div;
  477 + unsigned long val;
  478 + int err;
458 479  
  480 + err = kstrtoul(buf, 10, &val);
  481 + if (err)
  482 + return err;
  483 +
459 484 /* Save fan_min */
460 485 mutex_lock(&data->update_lock);
461 486 min = FAN_FROM_REG(data->fan_min[nr],
462 487 DIV_FROM_REG(data->fan_div[nr]));
463 488  
464   - data->fan_div[nr] = DIV_TO_REG(simple_strtoul(buf, NULL, 10));
  489 + data->fan_div[nr] = DIV_TO_REG(val);
465 490  
466 491 fan_div_reg = w83792d_read_value(client, W83792D_REG_FAN_DIV[nr >> 1]);
467 492 fan_div_reg &= (nr & 0x01) ? 0x8f : 0xf8;
468 493  
... ... @@ -496,9 +521,13 @@
496 521 int nr = sensor_attr->index;
497 522 struct i2c_client *client = to_i2c_client(dev);
498 523 struct w83792d_data *data = i2c_get_clientdata(client);
499   - s32 val;
  524 + long val;
  525 + int err;
500 526  
501   - val = simple_strtol(buf, NULL, 10);
  527 + err = kstrtol(buf, 10, &val);
  528 + if (err)
  529 + return err;
  530 +
502 531 mutex_lock(&data->update_lock);
503 532 data->temp1[nr] = TEMP1_TO_REG(val);
504 533 w83792d_write_value(client, W83792D_REG_TEMP1[nr],
505 534  
... ... @@ -513,11 +542,12 @@
513 542 static ssize_t show_temp23(struct device *dev, struct device_attribute *attr,
514 543 char *buf)
515 544 {
516   - struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr);
  545 + struct sensor_device_attribute_2 *sensor_attr
  546 + = to_sensor_dev_attr_2(attr);
517 547 int nr = sensor_attr->nr;
518 548 int index = sensor_attr->index;
519 549 struct w83792d_data *data = w83792d_update_device(dev);
520   - return sprintf(buf,"%ld\n",
  550 + return sprintf(buf, "%ld\n",
521 551 (long)TEMP_ADD_FROM_REG(data->temp_add[nr][index],
522 552 data->temp_add[nr][index+1]));
523 553 }
524 554  
525 555  
... ... @@ -525,14 +555,19 @@
525 555 static ssize_t store_temp23(struct device *dev, struct device_attribute *attr,
526 556 const char *buf, size_t count)
527 557 {
528   - struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr);
  558 + struct sensor_device_attribute_2 *sensor_attr
  559 + = to_sensor_dev_attr_2(attr);
529 560 int nr = sensor_attr->nr;
530 561 int index = sensor_attr->index;
531 562 struct i2c_client *client = to_i2c_client(dev);
532 563 struct w83792d_data *data = i2c_get_clientdata(client);
533   - s32 val;
  564 + long val;
  565 + int err;
534 566  
535   - val = simple_strtol(buf, NULL, 10);
  567 + err = kstrtol(buf, 10, &val);
  568 + if (err)
  569 + return err;
  570 +
536 571 mutex_lock(&data->update_lock);
537 572 data->temp_add[nr][index] = TEMP_ADD_TO_REG_HIGH(val);
538 573 data->temp_add[nr][index+1] = TEMP_ADD_TO_REG_LOW(val);
539 574  
... ... @@ -604,8 +639,14 @@
604 639 int nr = sensor_attr->index;
605 640 struct i2c_client *client = to_i2c_client(dev);
606 641 struct w83792d_data *data = i2c_get_clientdata(client);
607   - u8 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 255) >> 4;
  642 + unsigned long val;
  643 + int err;
608 644  
  645 + err = kstrtoul(buf, 10, &val);
  646 + if (err)
  647 + return err;
  648 + val = SENSORS_LIMIT(val, 0, 255) >> 4;
  649 +
609 650 mutex_lock(&data->update_lock);
610 651 val |= w83792d_read_value(client, W83792D_REG_PWM[nr]) & 0xf0;
611 652 data->pwm[nr] = val;
612 653  
613 654  
... ... @@ -623,10 +664,14 @@
623 664 int nr = sensor_attr->index - 1;
624 665 struct i2c_client *client = to_i2c_client(dev);
625 666 struct w83792d_data *data = i2c_get_clientdata(client);
626   - u32 val;
627 667 u8 fan_cfg_tmp, cfg1_tmp, cfg2_tmp, cfg3_tmp, cfg4_tmp;
  668 + unsigned long val;
  669 + int err;
628 670  
629   - val = simple_strtoul(buf, NULL, 10);
  671 + err = kstrtoul(buf, 10, &val);
  672 + if (err)
  673 + return err;
  674 +
630 675 if (val < 1 || val > 3)
631 676 return -EINVAL;
632 677  
... ... @@ -645,7 +690,7 @@
645 690 cfg1_tmp = data->pwmenable[0];
646 691 cfg2_tmp = (data->pwmenable[1]) << 2;
647 692 cfg3_tmp = (data->pwmenable[2]) << 4;
648   - cfg4_tmp = w83792d_read_value(client,W83792D_REG_FAN_CFG) & 0xc0;
  693 + cfg4_tmp = w83792d_read_value(client, W83792D_REG_FAN_CFG) & 0xc0;
649 694 fan_cfg_tmp = ((cfg4_tmp | cfg3_tmp) | cfg2_tmp) | cfg1_tmp;
650 695 w83792d_write_value(client, W83792D_REG_FAN_CFG, fan_cfg_tmp);
651 696 mutex_unlock(&data->update_lock);
652 697  
... ... @@ -671,10 +716,13 @@
671 716 int nr = sensor_attr->index;
672 717 struct i2c_client *client = to_i2c_client(dev);
673 718 struct w83792d_data *data = i2c_get_clientdata(client);
674   - u32 val;
  719 + unsigned long val;
  720 + int err;
675 721  
676   - val = simple_strtoul(buf, NULL, 10);
677   - if (val != 0 && val != 1)
  722 + err = kstrtoul(buf, 10, &val);
  723 + if (err)
  724 + return err;
  725 + if (val > 1)
678 726 return -EINVAL;
679 727  
680 728 mutex_lock(&data->update_lock);
681 729  
682 730  
... ... @@ -721,16 +769,20 @@
721 769 {
722 770 struct i2c_client *client = to_i2c_client(dev);
723 771 struct w83792d_data *data = i2c_get_clientdata(client);
724   - u32 val;
  772 + unsigned long val;
  773 + int err;
725 774 u8 temp1 = 0, temp2 = 0;
726 775  
727 776 dev_warn(dev,
728 777 "Attribute %s is deprecated, use intrusion0_alarm instead\n",
729 778 "chassis_clear");
730 779  
731   - val = simple_strtoul(buf, NULL, 10);
  780 + err = kstrtoul(buf, 10, &val);
  781 + if (err)
  782 + return err;
  783 +
732 784 mutex_lock(&data->update_lock);
733   - data->chassis_clear = SENSORS_LIMIT(val, 0 ,1);
  785 + data->chassis_clear = SENSORS_LIMIT(val, 0, 1);
734 786 temp1 = ((data->chassis_clear) << 7) & 0x80;
735 787 temp2 = w83792d_read_value(client,
736 788 W83792D_REG_CHASSIS_CLR) & 0x7f;
737 789  
738 790  
... ... @@ -780,14 +832,19 @@
780 832 int nr = sensor_attr->index - 1;
781 833 struct i2c_client *client = to_i2c_client(dev);
782 834 struct w83792d_data *data = i2c_get_clientdata(client);
783   - u32 val;
784   - u8 target_tmp=0, target_mask=0;
  835 + u8 target_tmp = 0, target_mask = 0;
  836 + unsigned long val;
  837 + int err;
785 838  
786   - val = simple_strtoul(buf, NULL, 10);
  839 + err = kstrtoul(buf, 10, &val);
  840 + if (err)
  841 + return err;
  842 +
787 843 target_tmp = val;
788 844 target_tmp = target_tmp & 0x7f;
789 845 mutex_lock(&data->update_lock);
790   - target_mask = w83792d_read_value(client, W83792D_REG_THERMAL[nr]) & 0x80;
  846 + target_mask = w83792d_read_value(client,
  847 + W83792D_REG_THERMAL[nr]) & 0x80;
791 848 data->thermal_cruise[nr] = SENSORS_LIMIT(target_tmp, 0, 255);
792 849 w83792d_write_value(client, W83792D_REG_THERMAL[nr],
793 850 (data->thermal_cruise[nr]) | target_mask);
794 851  
795 852  
796 853  
797 854  
... ... @@ -815,19 +872,22 @@
815 872 int nr = sensor_attr->index - 1;
816 873 struct i2c_client *client = to_i2c_client(dev);
817 874 struct w83792d_data *data = i2c_get_clientdata(client);
818   - u32 val;
819 875 u8 tol_tmp, tol_mask;
  876 + unsigned long val;
  877 + int err;
820 878  
821   - val = simple_strtoul(buf, NULL, 10);
  879 + err = kstrtoul(buf, 10, &val);
  880 + if (err)
  881 + return err;
  882 +
822 883 mutex_lock(&data->update_lock);
823 884 tol_mask = w83792d_read_value(client,
824 885 W83792D_REG_TOLERANCE[nr]) & ((nr == 1) ? 0x0f : 0xf0);
825 886 tol_tmp = SENSORS_LIMIT(val, 0, 15);
826 887 tol_tmp &= 0x0f;
827 888 data->tolerance[nr] = tol_tmp;
828   - if (nr == 1) {
  889 + if (nr == 1)
829 890 tol_tmp <<= 4;
830   - }
831 891 w83792d_write_value(client, W83792D_REG_TOLERANCE[nr],
832 892 tol_mask | tol_tmp);
833 893 mutex_unlock(&data->update_lock);
... ... @@ -840,7 +900,8 @@
840 900 show_sf2_point(struct device *dev, struct device_attribute *attr,
841 901 char *buf)
842 902 {
843   - struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr);
  903 + struct sensor_device_attribute_2 *sensor_attr
  904 + = to_sensor_dev_attr_2(attr);
844 905 int nr = sensor_attr->nr;
845 906 int index = sensor_attr->index;
846 907 struct w83792d_data *data = w83792d_update_device(dev);
847 908  
848 909  
849 910  
... ... @@ -851,15 +912,20 @@
851 912 store_sf2_point(struct device *dev, struct device_attribute *attr,
852 913 const char *buf, size_t count)
853 914 {
854   - struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr);
  915 + struct sensor_device_attribute_2 *sensor_attr
  916 + = to_sensor_dev_attr_2(attr);
855 917 int nr = sensor_attr->nr - 1;
856 918 int index = sensor_attr->index - 1;
857 919 struct i2c_client *client = to_i2c_client(dev);
858 920 struct w83792d_data *data = i2c_get_clientdata(client);
859   - u32 val;
860 921 u8 mask_tmp = 0;
  922 + unsigned long val;
  923 + int err;
861 924  
862   - val = simple_strtoul(buf, NULL, 10);
  925 + err = kstrtoul(buf, 10, &val);
  926 + if (err)
  927 + return err;
  928 +
863 929 mutex_lock(&data->update_lock);
864 930 data->sf2_points[index][nr] = SENSORS_LIMIT(val, 0, 127);
865 931 mask_tmp = w83792d_read_value(client,
... ... @@ -875,7 +941,8 @@
875 941 show_sf2_level(struct device *dev, struct device_attribute *attr,
876 942 char *buf)
877 943 {
878   - struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr);
  944 + struct sensor_device_attribute_2 *sensor_attr
  945 + = to_sensor_dev_attr_2(attr);
879 946 int nr = sensor_attr->nr;
880 947 int index = sensor_attr->index;
881 948 struct w83792d_data *data = w83792d_update_device(dev);
882 949  
883 950  
884 951  
885 952  
886 953  
... ... @@ -887,25 +954,30 @@
887 954 store_sf2_level(struct device *dev, struct device_attribute *attr,
888 955 const char *buf, size_t count)
889 956 {
890   - struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr);
  957 + struct sensor_device_attribute_2 *sensor_attr
  958 + = to_sensor_dev_attr_2(attr);
891 959 int nr = sensor_attr->nr;
892 960 int index = sensor_attr->index - 1;
893 961 struct i2c_client *client = to_i2c_client(dev);
894 962 struct w83792d_data *data = i2c_get_clientdata(client);
895   - u32 val;
896   - u8 mask_tmp=0, level_tmp=0;
  963 + u8 mask_tmp = 0, level_tmp = 0;
  964 + unsigned long val;
  965 + int err;
897 966  
898   - val = simple_strtoul(buf, NULL, 10);
  967 + err = kstrtoul(buf, 10, &val);
  968 + if (err)
  969 + return err;
  970 +
899 971 mutex_lock(&data->update_lock);
900 972 data->sf2_levels[index][nr] = SENSORS_LIMIT((val * 15) / 100, 0, 15);
901 973 mask_tmp = w83792d_read_value(client, W83792D_REG_LEVELS[index][nr])
902   - & ((nr==3) ? 0xf0 : 0x0f);
903   - if (nr==3) {
  974 + & ((nr == 3) ? 0xf0 : 0x0f);
  975 + if (nr == 3)
904 976 level_tmp = data->sf2_levels[index][nr];
905   - } else {
  977 + else
906 978 level_tmp = data->sf2_levels[index][nr] << 4;
907   - }
908   - w83792d_write_value(client, W83792D_REG_LEVELS[index][nr], level_tmp | mask_tmp);
  979 + w83792d_write_value(client, W83792D_REG_LEVELS[index][nr],
  980 + level_tmp | mask_tmp);
909 981 mutex_unlock(&data->update_lock);
910 982  
911 983 return count;
912 984  
... ... @@ -939,9 +1011,8 @@
939 1011 }
940 1012  
941 1013 val = w83792d_read_value(new_client, W83792D_REG_I2C_SUBADDR);
942   - if (!(val & 0x08)) {
  1014 + if (!(val & 0x08))
943 1015 data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (val & 0x7));
944   - }
945 1016 if (!(val & 0x80)) {
946 1017 if ((data->lm75[0] != NULL) &&
947 1018 ((val & 0x7) == ((val >> 4) & 0x7))) {
948 1019  
... ... @@ -1306,9 +1377,8 @@
1306 1377 int val1, val2;
1307 1378 unsigned short address = client->addr;
1308 1379  
1309   - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
  1380 + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1310 1381 return -ENODEV;
1311   - }
1312 1382  
1313 1383 if (w83792d_read_value(client, W83792D_REG_CONFIG) & 0x80)
1314 1384 return -ENODEV;
1315 1385  
... ... @@ -1318,11 +1388,13 @@
1318 1388 /* Check for Winbond ID if in bank 0 */
1319 1389 if (!(val1 & 0x07)) { /* is Bank0 */
1320 1390 if ((!(val1 & 0x80) && val2 != 0xa3) ||
1321   - ( (val1 & 0x80) && val2 != 0x5c))
  1391 + ((val1 & 0x80) && val2 != 0x5c))
1322 1392 return -ENODEV;
1323 1393 }
1324   - /* If Winbond chip, address of chip and W83792D_REG_I2C_ADDR
1325   - should match */
  1394 + /*
  1395 + * If Winbond chip, address of chip and W83792D_REG_I2C_ADDR
  1396 + * should match
  1397 + */
1326 1398 if (w83792d_read_value(client, W83792D_REG_I2C_ADDR) != address)
1327 1399 return -ENODEV;
1328 1400  
1329 1401  
1330 1402  
1331 1403  
1332 1404  
1333 1405  
1334 1406  
1335 1407  
1336 1408  
1337 1409  
... ... @@ -1374,33 +1446,40 @@
1374 1446 }
1375 1447  
1376 1448 /* Register sysfs hooks */
1377   - if ((err = sysfs_create_group(&dev->kobj, &w83792d_group)))
  1449 + err = sysfs_create_group(&dev->kobj, &w83792d_group);
  1450 + if (err)
1378 1451 goto ERROR3;
1379 1452  
1380   - /* Read GPIO enable register to check if pins for fan 4,5 are used as
1381   - GPIO */
  1453 + /*
  1454 + * Read GPIO enable register to check if pins for fan 4,5 are used as
  1455 + * GPIO
  1456 + */
1382 1457 val1 = w83792d_read_value(client, W83792D_REG_GPIO_EN);
1383 1458  
1384   - if (!(val1 & 0x40))
1385   - if ((err = sysfs_create_group(&dev->kobj,
1386   - &w83792d_group_fan[0])))
  1459 + if (!(val1 & 0x40)) {
  1460 + err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[0]);
  1461 + if (err)
1387 1462 goto exit_remove_files;
  1463 + }
1388 1464  
1389   - if (!(val1 & 0x20))
1390   - if ((err = sysfs_create_group(&dev->kobj,
1391   - &w83792d_group_fan[1])))
  1465 + if (!(val1 & 0x20)) {
  1466 + err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[1]);
  1467 + if (err)
1392 1468 goto exit_remove_files;
  1469 + }
1393 1470  
1394 1471 val1 = w83792d_read_value(client, W83792D_REG_PIN);
1395   - if (val1 & 0x40)
1396   - if ((err = sysfs_create_group(&dev->kobj,
1397   - &w83792d_group_fan[2])))
  1472 + if (val1 & 0x40) {
  1473 + err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[2]);
  1474 + if (err)
1398 1475 goto exit_remove_files;
  1476 + }
1399 1477  
1400   - if (val1 & 0x04)
1401   - if ((err = sysfs_create_group(&dev->kobj,
1402   - &w83792d_group_fan[3])))
  1478 + if (val1 & 0x04) {
  1479 + err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[3]);
  1480 + if (err)
1403 1481 goto exit_remove_files;
  1482 + }
1404 1483  
1405 1484 data->hwmon_dev = hwmon_device_register(dev);
1406 1485 if (IS_ERR(data->hwmon_dev)) {
1407 1486  
... ... @@ -1451,14 +1530,16 @@
1451 1530 {
1452 1531 u8 temp2_cfg, temp3_cfg, vid_in_b;
1453 1532  
1454   - if (init) {
  1533 + if (init)
1455 1534 w83792d_write_value(client, W83792D_REG_CONFIG, 0x80);
1456   - }
1457   - /* Clear the bit6 of W83792D_REG_VID_IN_B(set it into 0):
1458   - W83792D_REG_VID_IN_B bit6 = 0: the high/low limit of
1459   - vin0/vin1 can be modified by user;
1460   - W83792D_REG_VID_IN_B bit6 = 1: the high/low limit of
1461   - vin0/vin1 auto-updated, can NOT be modified by user. */
  1535 +
  1536 + /*
  1537 + * Clear the bit6 of W83792D_REG_VID_IN_B(set it into 0):
  1538 + * W83792D_REG_VID_IN_B bit6 = 0: the high/low limit of
  1539 + * vin0/vin1 can be modified by user;
  1540 + * W83792D_REG_VID_IN_B bit6 = 1: the high/low limit of
  1541 + * vin0/vin1 auto-updated, can NOT be modified by user.
  1542 + */
1462 1543 vid_in_b = w83792d_read_value(client, W83792D_REG_VID_IN_B);
1463 1544 w83792d_write_value(client, W83792D_REG_VID_IN_B,
1464 1545 vid_in_b & 0xbf);
... ... @@ -1527,7 +1608,7 @@
1527 1608 for (i = 0; i < 2; i++) {
1528 1609 for (j = 0; j < 6; j++) {
1529 1610 data->temp_add[i][j] = w83792d_read_value(
1530   - client,W83792D_REG_TEMP_ADD[i][j]);
  1611 + client, W83792D_REG_TEMP_ADD[i][j]);
1531 1612 }
1532 1613 }
1533 1614  
... ... @@ -1572,8 +1653,9 @@
1572 1653 /* Update Smart Fan II temperature points */
1573 1654 for (i = 0; i < 3; i++) {
1574 1655 for (j = 0; j < 4; j++) {
1575   - data->sf2_points[i][j] = w83792d_read_value(
1576   - client,W83792D_REG_POINTS[i][j]) & 0x7f;
  1656 + data->sf2_points[i][j]
  1657 + = w83792d_read_value(client,
  1658 + W83792D_REG_POINTS[i][j]) & 0x7f;
1577 1659 }
1578 1660 }
1579 1661  
1580 1662  
... ... @@ -1605,10 +1687,10 @@
1605 1687 #ifdef DEBUG
1606 1688 static void w83792d_print_debug(struct w83792d_data *data, struct device *dev)
1607 1689 {
1608   - int i=0, j=0;
  1690 + int i = 0, j = 0;
1609 1691 dev_dbg(dev, "==========The following is the debug message...========\n");
1610 1692 dev_dbg(dev, "9 set of Voltages: =====>\n");
1611   - for (i=0; i<9; i++) {
  1693 + for (i = 0; i < 9; i++) {
1612 1694 dev_dbg(dev, "vin[%d] is: 0x%x\n", i, data->in[i]);
1613 1695 dev_dbg(dev, "vin[%d] max is: 0x%x\n", i, data->in_max[i]);
1614 1696 dev_dbg(dev, "vin[%d] min is: 0x%x\n", i, data->in_min[i]);
1615 1697  
1616 1698  
1617 1699  
1618 1700  
1619 1701  
... ... @@ -1616,27 +1698,26 @@
1616 1698 dev_dbg(dev, "Low Bit1 is: 0x%x\n", data->low_bits & 0xff);
1617 1699 dev_dbg(dev, "Low Bit2 is: 0x%x\n", data->low_bits >> 8);
1618 1700 dev_dbg(dev, "7 set of Fan Counts and Duty Cycles: =====>\n");
1619   - for (i=0; i<7; i++) {
  1701 + for (i = 0; i < 7; i++) {
1620 1702 dev_dbg(dev, "fan[%d] is: 0x%x\n", i, data->fan[i]);
1621 1703 dev_dbg(dev, "fan[%d] min is: 0x%x\n", i, data->fan_min[i]);
1622 1704 dev_dbg(dev, "pwm[%d] is: 0x%x\n", i, data->pwm[i]);
1623 1705 }
1624 1706 dev_dbg(dev, "3 set of Temperatures: =====>\n");
1625   - for (i=0; i<3; i++) {
  1707 + for (i = 0; i < 3; i++)
1626 1708 dev_dbg(dev, "temp1[%d] is: 0x%x\n", i, data->temp1[i]);
1627   - }
1628 1709  
1629   - for (i=0; i<2; i++) {
1630   - for (j=0; j<6; j++) {
  1710 + for (i = 0; i < 2; i++) {
  1711 + for (j = 0; j < 6; j++) {
1631 1712 dev_dbg(dev, "temp_add[%d][%d] is: 0x%x\n", i, j,
1632 1713 data->temp_add[i][j]);
1633 1714 }
1634 1715 }
1635 1716  
1636   - for (i=0; i<7; i++) {
  1717 + for (i = 0; i < 7; i++)
1637 1718 dev_dbg(dev, "fan_div[%d] is: 0x%x\n", i, data->fan_div[i]);
1638   - }
1639   - dev_dbg(dev, "==========End of the debug message...==================\n");
  1719 +
  1720 + dev_dbg(dev, "==========End of the debug message...================\n");
1640 1721 dev_dbg(dev, "\n");
1641 1722 }
1642 1723 #endif