diff options
Diffstat (limited to 'drivers')
33 files changed, 522 insertions, 53 deletions
diff --git a/drivers/hwmon/adm1021.c b/drivers/hwmon/adm1021.c index d2c774c32f45..a483d96e4cef 100644 --- a/drivers/hwmon/adm1021.c +++ b/drivers/hwmon/adm1021.c | |||
@@ -25,6 +25,8 @@ | |||
25 | #include <linux/jiffies.h> | 25 | #include <linux/jiffies.h> |
26 | #include <linux/i2c.h> | 26 | #include <linux/i2c.h> |
27 | #include <linux/i2c-sensor.h> | 27 | #include <linux/i2c-sensor.h> |
28 | #include <linux/hwmon.h> | ||
29 | #include <linux/err.h> | ||
28 | 30 | ||
29 | 31 | ||
30 | /* Addresses to scan */ | 32 | /* Addresses to scan */ |
@@ -89,6 +91,7 @@ clearing it. Weird, ey? --Phil */ | |||
89 | /* Each client has this additional data */ | 91 | /* Each client has this additional data */ |
90 | struct adm1021_data { | 92 | struct adm1021_data { |
91 | struct i2c_client client; | 93 | struct i2c_client client; |
94 | struct class_device *class_dev; | ||
92 | enum chips type; | 95 | enum chips type; |
93 | 96 | ||
94 | struct semaphore update_lock; | 97 | struct semaphore update_lock; |
@@ -295,6 +298,12 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) | |||
295 | adm1021_init_client(new_client); | 298 | adm1021_init_client(new_client); |
296 | 299 | ||
297 | /* Register sysfs hooks */ | 300 | /* Register sysfs hooks */ |
301 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
302 | if (IS_ERR(data->class_dev)) { | ||
303 | err = PTR_ERR(data->class_dev); | ||
304 | goto error2; | ||
305 | } | ||
306 | |||
298 | device_create_file(&new_client->dev, &dev_attr_temp1_max); | 307 | device_create_file(&new_client->dev, &dev_attr_temp1_max); |
299 | device_create_file(&new_client->dev, &dev_attr_temp1_min); | 308 | device_create_file(&new_client->dev, &dev_attr_temp1_min); |
300 | device_create_file(&new_client->dev, &dev_attr_temp1_input); | 309 | device_create_file(&new_client->dev, &dev_attr_temp1_input); |
@@ -305,6 +314,8 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) | |||
305 | 314 | ||
306 | return 0; | 315 | return 0; |
307 | 316 | ||
317 | error2: | ||
318 | i2c_detach_client(new_client); | ||
308 | error1: | 319 | error1: |
309 | kfree(data); | 320 | kfree(data); |
310 | error0: | 321 | error0: |
@@ -322,14 +333,17 @@ static void adm1021_init_client(struct i2c_client *client) | |||
322 | 333 | ||
323 | static int adm1021_detach_client(struct i2c_client *client) | 334 | static int adm1021_detach_client(struct i2c_client *client) |
324 | { | 335 | { |
336 | struct adm1021_data *data = i2c_get_clientdata(client); | ||
325 | int err; | 337 | int err; |
326 | 338 | ||
339 | hwmon_device_unregister(data->class_dev); | ||
340 | |||
327 | if ((err = i2c_detach_client(client))) { | 341 | if ((err = i2c_detach_client(client))) { |
328 | dev_err(&client->dev, "Client deregistration failed, client not detached.\n"); | 342 | dev_err(&client->dev, "Client deregistration failed, client not detached.\n"); |
329 | return err; | 343 | return err; |
330 | } | 344 | } |
331 | 345 | ||
332 | kfree(i2c_get_clientdata(client)); | 346 | kfree(data); |
333 | return 0; | 347 | return 0; |
334 | } | 348 | } |
335 | 349 | ||
diff --git a/drivers/hwmon/adm1025.c b/drivers/hwmon/adm1025.c index e452d0daf906..b68b292c00d4 100644 --- a/drivers/hwmon/adm1025.c +++ b/drivers/hwmon/adm1025.c | |||
@@ -52,6 +52,8 @@ | |||
52 | #include <linux/i2c.h> | 52 | #include <linux/i2c.h> |
53 | #include <linux/i2c-sensor.h> | 53 | #include <linux/i2c-sensor.h> |
54 | #include <linux/i2c-vid.h> | 54 | #include <linux/i2c-vid.h> |
55 | #include <linux/hwmon.h> | ||
56 | #include <linux/err.h> | ||
55 | 57 | ||
56 | /* | 58 | /* |
57 | * Addresses to scan | 59 | * Addresses to scan |
@@ -132,6 +134,7 @@ static struct i2c_driver adm1025_driver = { | |||
132 | 134 | ||
133 | struct adm1025_data { | 135 | struct adm1025_data { |
134 | struct i2c_client client; | 136 | struct i2c_client client; |
137 | struct class_device *class_dev; | ||
135 | struct semaphore update_lock; | 138 | struct semaphore update_lock; |
136 | char valid; /* zero until following fields are valid */ | 139 | char valid; /* zero until following fields are valid */ |
137 | unsigned long last_updated; /* in jiffies */ | 140 | unsigned long last_updated; /* in jiffies */ |
@@ -416,6 +419,12 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind) | |||
416 | adm1025_init_client(new_client); | 419 | adm1025_init_client(new_client); |
417 | 420 | ||
418 | /* Register sysfs hooks */ | 421 | /* Register sysfs hooks */ |
422 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
423 | if (IS_ERR(data->class_dev)) { | ||
424 | err = PTR_ERR(data->class_dev); | ||
425 | goto exit_detach; | ||
426 | } | ||
427 | |||
419 | device_create_file(&new_client->dev, &dev_attr_in0_input); | 428 | device_create_file(&new_client->dev, &dev_attr_in0_input); |
420 | device_create_file(&new_client->dev, &dev_attr_in1_input); | 429 | device_create_file(&new_client->dev, &dev_attr_in1_input); |
421 | device_create_file(&new_client->dev, &dev_attr_in2_input); | 430 | device_create_file(&new_client->dev, &dev_attr_in2_input); |
@@ -452,6 +461,8 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind) | |||
452 | 461 | ||
453 | return 0; | 462 | return 0; |
454 | 463 | ||
464 | exit_detach: | ||
465 | i2c_detach_client(new_client); | ||
455 | exit_free: | 466 | exit_free: |
456 | kfree(data); | 467 | kfree(data); |
457 | exit: | 468 | exit: |
@@ -502,15 +513,18 @@ static void adm1025_init_client(struct i2c_client *client) | |||
502 | 513 | ||
503 | static int adm1025_detach_client(struct i2c_client *client) | 514 | static int adm1025_detach_client(struct i2c_client *client) |
504 | { | 515 | { |
516 | struct adm1025_data *data = i2c_get_clientdata(client); | ||
505 | int err; | 517 | int err; |
506 | 518 | ||
519 | hwmon_device_unregister(data->class_dev); | ||
520 | |||
507 | if ((err = i2c_detach_client(client))) { | 521 | if ((err = i2c_detach_client(client))) { |
508 | dev_err(&client->dev, "Client deregistration failed, " | 522 | dev_err(&client->dev, "Client deregistration failed, " |
509 | "client not detached.\n"); | 523 | "client not detached.\n"); |
510 | return err; | 524 | return err; |
511 | } | 525 | } |
512 | 526 | ||
513 | kfree(i2c_get_clientdata(client)); | 527 | kfree(data); |
514 | return 0; | 528 | return 0; |
515 | } | 529 | } |
516 | 530 | ||
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c index c8a7f47911f9..eb55133a13ee 100644 --- a/drivers/hwmon/adm1026.c +++ b/drivers/hwmon/adm1026.c | |||
@@ -31,6 +31,8 @@ | |||
31 | #include <linux/i2c-sensor.h> | 31 | #include <linux/i2c-sensor.h> |
32 | #include <linux/i2c-vid.h> | 32 | #include <linux/i2c-vid.h> |
33 | #include <linux/hwmon-sysfs.h> | 33 | #include <linux/hwmon-sysfs.h> |
34 | #include <linux/hwmon.h> | ||
35 | #include <linux/err.h> | ||
34 | 36 | ||
35 | /* Addresses to scan */ | 37 | /* Addresses to scan */ |
36 | static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; | 38 | static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; |
@@ -259,6 +261,7 @@ struct pwm_data { | |||
259 | 261 | ||
260 | struct adm1026_data { | 262 | struct adm1026_data { |
261 | struct i2c_client client; | 263 | struct i2c_client client; |
264 | struct class_device *class_dev; | ||
262 | struct semaphore lock; | 265 | struct semaphore lock; |
263 | enum chips type; | 266 | enum chips type; |
264 | 267 | ||
@@ -324,8 +327,10 @@ int adm1026_attach_adapter(struct i2c_adapter *adapter) | |||
324 | 327 | ||
325 | int adm1026_detach_client(struct i2c_client *client) | 328 | int adm1026_detach_client(struct i2c_client *client) |
326 | { | 329 | { |
330 | struct adm1026_data *data = i2c_get_clientdata(client); | ||
331 | hwmon_device_unregister(data->class_dev); | ||
327 | i2c_detach_client(client); | 332 | i2c_detach_client(client); |
328 | kfree(i2c_get_clientdata(client)); | 333 | kfree(data); |
329 | return 0; | 334 | return 0; |
330 | } | 335 | } |
331 | 336 | ||
@@ -1555,6 +1560,12 @@ int adm1026_detect(struct i2c_adapter *adapter, int address, | |||
1555 | adm1026_init_client(new_client); | 1560 | adm1026_init_client(new_client); |
1556 | 1561 | ||
1557 | /* Register sysfs hooks */ | 1562 | /* Register sysfs hooks */ |
1563 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
1564 | if (IS_ERR(data->class_dev)) { | ||
1565 | err = PTR_ERR(data->class_dev); | ||
1566 | goto exitdetach; | ||
1567 | } | ||
1568 | |||
1558 | device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr); | 1569 | device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr); |
1559 | device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr); | 1570 | device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr); |
1560 | device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr); | 1571 | device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr); |
@@ -1690,6 +1701,8 @@ int adm1026_detect(struct i2c_adapter *adapter, int address, | |||
1690 | return 0; | 1701 | return 0; |
1691 | 1702 | ||
1692 | /* Error out and cleanup code */ | 1703 | /* Error out and cleanup code */ |
1704 | exitdetach: | ||
1705 | i2c_detach_client(new_client); | ||
1693 | exitfree: | 1706 | exitfree: |
1694 | kfree(data); | 1707 | kfree(data); |
1695 | exit: | 1708 | exit: |
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c index 936250957270..ac3b1542556e 100644 --- a/drivers/hwmon/adm1031.c +++ b/drivers/hwmon/adm1031.c | |||
@@ -27,6 +27,8 @@ | |||
27 | #include <linux/jiffies.h> | 27 | #include <linux/jiffies.h> |
28 | #include <linux/i2c.h> | 28 | #include <linux/i2c.h> |
29 | #include <linux/i2c-sensor.h> | 29 | #include <linux/i2c-sensor.h> |
30 | #include <linux/hwmon.h> | ||
31 | #include <linux/err.h> | ||
30 | 32 | ||
31 | /* Following macros takes channel parameter starting from 0 to 2 */ | 33 | /* Following macros takes channel parameter starting from 0 to 2 */ |
32 | #define ADM1031_REG_FAN_SPEED(nr) (0x08 + (nr)) | 34 | #define ADM1031_REG_FAN_SPEED(nr) (0x08 + (nr)) |
@@ -69,6 +71,7 @@ typedef u8 auto_chan_table_t[8][2]; | |||
69 | /* Each client has this additional data */ | 71 | /* Each client has this additional data */ |
70 | struct adm1031_data { | 72 | struct adm1031_data { |
71 | struct i2c_client client; | 73 | struct i2c_client client; |
74 | struct class_device *class_dev; | ||
72 | struct semaphore update_lock; | 75 | struct semaphore update_lock; |
73 | int chip_type; | 76 | int chip_type; |
74 | char valid; /* !=0 if following fields are valid */ | 77 | char valid; /* !=0 if following fields are valid */ |
@@ -788,6 +791,12 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) | |||
788 | adm1031_init_client(new_client); | 791 | adm1031_init_client(new_client); |
789 | 792 | ||
790 | /* Register sysfs hooks */ | 793 | /* Register sysfs hooks */ |
794 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
795 | if (IS_ERR(data->class_dev)) { | ||
796 | err = PTR_ERR(data->class_dev); | ||
797 | goto exit_detach; | ||
798 | } | ||
799 | |||
791 | device_create_file(&new_client->dev, &dev_attr_fan1_input); | 800 | device_create_file(&new_client->dev, &dev_attr_fan1_input); |
792 | device_create_file(&new_client->dev, &dev_attr_fan1_div); | 801 | device_create_file(&new_client->dev, &dev_attr_fan1_div); |
793 | device_create_file(&new_client->dev, &dev_attr_fan1_min); | 802 | device_create_file(&new_client->dev, &dev_attr_fan1_min); |
@@ -833,6 +842,8 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) | |||
833 | 842 | ||
834 | return 0; | 843 | return 0; |
835 | 844 | ||
845 | exit_detach: | ||
846 | i2c_detach_client(new_client); | ||
836 | exit_free: | 847 | exit_free: |
837 | kfree(data); | 848 | kfree(data); |
838 | exit: | 849 | exit: |
@@ -841,11 +852,14 @@ exit: | |||
841 | 852 | ||
842 | static int adm1031_detach_client(struct i2c_client *client) | 853 | static int adm1031_detach_client(struct i2c_client *client) |
843 | { | 854 | { |
855 | struct adm1031_data *data = i2c_get_clientdata(client); | ||
844 | int ret; | 856 | int ret; |
857 | |||
858 | hwmon_device_unregister(data->class_dev); | ||
845 | if ((ret = i2c_detach_client(client)) != 0) { | 859 | if ((ret = i2c_detach_client(client)) != 0) { |
846 | return ret; | 860 | return ret; |
847 | } | 861 | } |
848 | kfree(i2c_get_clientdata(client)); | 862 | kfree(data); |
849 | return 0; | 863 | return 0; |
850 | } | 864 | } |
851 | 865 | ||
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c index ce2a6eb93f6e..7ef61206ba10 100644 --- a/drivers/hwmon/adm9240.c +++ b/drivers/hwmon/adm9240.c | |||
@@ -47,6 +47,8 @@ | |||
47 | #include <linux/i2c.h> | 47 | #include <linux/i2c.h> |
48 | #include <linux/i2c-sensor.h> | 48 | #include <linux/i2c-sensor.h> |
49 | #include <linux/i2c-vid.h> | 49 | #include <linux/i2c-vid.h> |
50 | #include <linux/hwmon.h> | ||
51 | #include <linux/err.h> | ||
50 | 52 | ||
51 | /* Addresses to scan */ | 53 | /* Addresses to scan */ |
52 | static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, | 54 | static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, |
@@ -150,6 +152,7 @@ static struct i2c_driver adm9240_driver = { | |||
150 | struct adm9240_data { | 152 | struct adm9240_data { |
151 | enum chips type; | 153 | enum chips type; |
152 | struct i2c_client client; | 154 | struct i2c_client client; |
155 | struct class_device *class_dev; | ||
153 | struct semaphore update_lock; | 156 | struct semaphore update_lock; |
154 | char valid; | 157 | char valid; |
155 | unsigned long last_updated_measure; | 158 | unsigned long last_updated_measure; |
@@ -582,6 +585,12 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) | |||
582 | adm9240_init_client(new_client); | 585 | adm9240_init_client(new_client); |
583 | 586 | ||
584 | /* populate sysfs filesystem */ | 587 | /* populate sysfs filesystem */ |
588 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
589 | if (IS_ERR(data->class_dev)) { | ||
590 | err = PTR_ERR(data->class_dev); | ||
591 | goto exit_detach; | ||
592 | } | ||
593 | |||
585 | device_create_file(&new_client->dev, &dev_attr_in0_input); | 594 | device_create_file(&new_client->dev, &dev_attr_in0_input); |
586 | device_create_file(&new_client->dev, &dev_attr_in0_min); | 595 | device_create_file(&new_client->dev, &dev_attr_in0_min); |
587 | device_create_file(&new_client->dev, &dev_attr_in0_max); | 596 | device_create_file(&new_client->dev, &dev_attr_in0_max); |
@@ -615,6 +624,9 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) | |||
615 | device_create_file(&new_client->dev, &dev_attr_cpu0_vid); | 624 | device_create_file(&new_client->dev, &dev_attr_cpu0_vid); |
616 | 625 | ||
617 | return 0; | 626 | return 0; |
627 | |||
628 | exit_detach: | ||
629 | i2c_detach_client(new_client); | ||
618 | exit_free: | 630 | exit_free: |
619 | kfree(data); | 631 | kfree(data); |
620 | exit: | 632 | exit: |
@@ -630,15 +642,18 @@ static int adm9240_attach_adapter(struct i2c_adapter *adapter) | |||
630 | 642 | ||
631 | static int adm9240_detach_client(struct i2c_client *client) | 643 | static int adm9240_detach_client(struct i2c_client *client) |
632 | { | 644 | { |
645 | struct adm9240_data *data = i2c_get_clientdata(client); | ||
633 | int err; | 646 | int err; |
634 | 647 | ||
648 | hwmon_device_unregister(data->class_dev); | ||
649 | |||
635 | if ((err = i2c_detach_client(client))) { | 650 | if ((err = i2c_detach_client(client))) { |
636 | dev_err(&client->dev, "Client deregistration failed, " | 651 | dev_err(&client->dev, "Client deregistration failed, " |
637 | "client not detached.\n"); | 652 | "client not detached.\n"); |
638 | return err; | 653 | return err; |
639 | } | 654 | } |
640 | 655 | ||
641 | kfree(i2c_get_clientdata(client)); | 656 | kfree(data); |
642 | return 0; | 657 | return 0; |
643 | } | 658 | } |
644 | 659 | ||
diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c index 70d996d6fe0a..3ab7a2ddafba 100644 --- a/drivers/hwmon/asb100.c +++ b/drivers/hwmon/asb100.c | |||
@@ -41,6 +41,8 @@ | |||
41 | #include <linux/i2c.h> | 41 | #include <linux/i2c.h> |
42 | #include <linux/i2c-sensor.h> | 42 | #include <linux/i2c-sensor.h> |
43 | #include <linux/i2c-vid.h> | 43 | #include <linux/i2c-vid.h> |
44 | #include <linux/hwmon.h> | ||
45 | #include <linux/err.h> | ||
44 | #include <linux/init.h> | 46 | #include <linux/init.h> |
45 | #include <linux/jiffies.h> | 47 | #include <linux/jiffies.h> |
46 | #include "lm75.h" | 48 | #include "lm75.h" |
@@ -183,6 +185,7 @@ static u8 DIV_TO_REG(long val) | |||
183 | dynamically allocated, at the same time the client itself is allocated. */ | 185 | dynamically allocated, at the same time the client itself is allocated. */ |
184 | struct asb100_data { | 186 | struct asb100_data { |
185 | struct i2c_client client; | 187 | struct i2c_client client; |
188 | struct class_device *class_dev; | ||
186 | struct semaphore lock; | 189 | struct semaphore lock; |
187 | enum chips type; | 190 | enum chips type; |
188 | 191 | ||
@@ -821,6 +824,12 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind) | |||
821 | data->fan_min[2] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(2)); | 824 | data->fan_min[2] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(2)); |
822 | 825 | ||
823 | /* Register sysfs hooks */ | 826 | /* Register sysfs hooks */ |
827 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
828 | if (IS_ERR(data->class_dev)) { | ||
829 | err = PTR_ERR(data->class_dev); | ||
830 | goto ERROR3; | ||
831 | } | ||
832 | |||
824 | device_create_file_in(new_client, 0); | 833 | device_create_file_in(new_client, 0); |
825 | device_create_file_in(new_client, 1); | 834 | device_create_file_in(new_client, 1); |
826 | device_create_file_in(new_client, 2); | 835 | device_create_file_in(new_client, 2); |
@@ -847,6 +856,11 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind) | |||
847 | 856 | ||
848 | return 0; | 857 | return 0; |
849 | 858 | ||
859 | ERROR3: | ||
860 | i2c_detach_client(data->lm75[1]); | ||
861 | i2c_detach_client(data->lm75[0]); | ||
862 | kfree(data->lm75[1]); | ||
863 | kfree(data->lm75[0]); | ||
850 | ERROR2: | 864 | ERROR2: |
851 | i2c_detach_client(new_client); | 865 | i2c_detach_client(new_client); |
852 | ERROR1: | 866 | ERROR1: |
@@ -857,21 +871,26 @@ ERROR0: | |||
857 | 871 | ||
858 | static int asb100_detach_client(struct i2c_client *client) | 872 | static int asb100_detach_client(struct i2c_client *client) |
859 | { | 873 | { |
874 | struct asb100_data *data = i2c_get_clientdata(client); | ||
860 | int err; | 875 | int err; |
861 | 876 | ||
877 | /* main client */ | ||
878 | if (data) | ||
879 | hwmon_device_unregister(data->class_dev); | ||
880 | |||
862 | if ((err = i2c_detach_client(client))) { | 881 | if ((err = i2c_detach_client(client))) { |
863 | dev_err(&client->dev, "client deregistration failed; " | 882 | dev_err(&client->dev, "client deregistration failed; " |
864 | "client not detached.\n"); | 883 | "client not detached.\n"); |
865 | return err; | 884 | return err; |
866 | } | 885 | } |
867 | 886 | ||
868 | if (i2c_get_clientdata(client)==NULL) { | 887 | /* main client */ |
869 | /* subclients */ | 888 | if (data) |
889 | kfree(data); | ||
890 | |||
891 | /* subclient */ | ||
892 | else | ||
870 | kfree(client); | 893 | kfree(client); |
871 | } else { | ||
872 | /* main client */ | ||
873 | kfree(i2c_get_clientdata(client)); | ||
874 | } | ||
875 | 894 | ||
876 | return 0; | 895 | return 0; |
877 | } | 896 | } |
diff --git a/drivers/hwmon/atxp1.c b/drivers/hwmon/atxp1.c index fca3fc1cef72..5f79f07a4ab8 100644 --- a/drivers/hwmon/atxp1.c +++ b/drivers/hwmon/atxp1.c | |||
@@ -25,6 +25,8 @@ | |||
25 | #include <linux/i2c.h> | 25 | #include <linux/i2c.h> |
26 | #include <linux/i2c-sensor.h> | 26 | #include <linux/i2c-sensor.h> |
27 | #include <linux/i2c-vid.h> | 27 | #include <linux/i2c-vid.h> |
28 | #include <linux/hwmon.h> | ||
29 | #include <linux/err.h> | ||
28 | 30 | ||
29 | MODULE_LICENSE("GPL"); | 31 | MODULE_LICENSE("GPL"); |
30 | MODULE_DESCRIPTION("System voltages control via Attansic ATXP1"); | 32 | MODULE_DESCRIPTION("System voltages control via Attansic ATXP1"); |
@@ -59,6 +61,7 @@ static struct i2c_driver atxp1_driver = { | |||
59 | 61 | ||
60 | struct atxp1_data { | 62 | struct atxp1_data { |
61 | struct i2c_client client; | 63 | struct i2c_client client; |
64 | struct class_device *class_dev; | ||
62 | struct semaphore update_lock; | 65 | struct semaphore update_lock; |
63 | unsigned long last_updated; | 66 | unsigned long last_updated; |
64 | u8 valid; | 67 | u8 valid; |
@@ -317,6 +320,12 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind) | |||
317 | goto exit_free; | 320 | goto exit_free; |
318 | } | 321 | } |
319 | 322 | ||
323 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
324 | if (IS_ERR(data->class_dev)) { | ||
325 | err = PTR_ERR(data->class_dev); | ||
326 | goto exit_detach; | ||
327 | } | ||
328 | |||
320 | device_create_file(&new_client->dev, &dev_attr_gpio1); | 329 | device_create_file(&new_client->dev, &dev_attr_gpio1); |
321 | device_create_file(&new_client->dev, &dev_attr_gpio2); | 330 | device_create_file(&new_client->dev, &dev_attr_gpio2); |
322 | device_create_file(&new_client->dev, &dev_attr_cpu0_vid); | 331 | device_create_file(&new_client->dev, &dev_attr_cpu0_vid); |
@@ -326,6 +335,8 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind) | |||
326 | 335 | ||
327 | return 0; | 336 | return 0; |
328 | 337 | ||
338 | exit_detach: | ||
339 | i2c_detach_client(new_client); | ||
329 | exit_free: | 340 | exit_free: |
330 | kfree(data); | 341 | kfree(data); |
331 | exit: | 342 | exit: |
@@ -334,14 +345,17 @@ exit: | |||
334 | 345 | ||
335 | static int atxp1_detach_client(struct i2c_client * client) | 346 | static int atxp1_detach_client(struct i2c_client * client) |
336 | { | 347 | { |
348 | struct atxp1_data * data = i2c_get_clientdata(client); | ||
337 | int err; | 349 | int err; |
338 | 350 | ||
351 | hwmon_device_unregister(data->class_dev); | ||
352 | |||
339 | err = i2c_detach_client(client); | 353 | err = i2c_detach_client(client); |
340 | 354 | ||
341 | if (err) | 355 | if (err) |
342 | dev_err(&client->dev, "Failed to detach client.\n"); | 356 | dev_err(&client->dev, "Failed to detach client.\n"); |
343 | else | 357 | else |
344 | kfree(i2c_get_clientdata(client)); | 358 | kfree(data); |
345 | 359 | ||
346 | return err; | 360 | return err; |
347 | }; | 361 | }; |
diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c index 5360d58804f6..9ed21ac46e97 100644 --- a/drivers/hwmon/ds1621.c +++ b/drivers/hwmon/ds1621.c | |||
@@ -27,6 +27,8 @@ | |||
27 | #include <linux/jiffies.h> | 27 | #include <linux/jiffies.h> |
28 | #include <linux/i2c.h> | 28 | #include <linux/i2c.h> |
29 | #include <linux/i2c-sensor.h> | 29 | #include <linux/i2c-sensor.h> |
30 | #include <linux/hwmon.h> | ||
31 | #include <linux/err.h> | ||
30 | #include "lm75.h" | 32 | #include "lm75.h" |
31 | 33 | ||
32 | /* Addresses to scan */ | 34 | /* Addresses to scan */ |
@@ -71,6 +73,7 @@ MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low") | |||
71 | /* Each client has this additional data */ | 73 | /* Each client has this additional data */ |
72 | struct ds1621_data { | 74 | struct ds1621_data { |
73 | struct i2c_client client; | 75 | struct i2c_client client; |
76 | struct class_device *class_dev; | ||
74 | struct semaphore update_lock; | 77 | struct semaphore update_lock; |
75 | char valid; /* !=0 if following fields are valid */ | 78 | char valid; /* !=0 if following fields are valid */ |
76 | unsigned long last_updated; /* In jiffies */ | 79 | unsigned long last_updated; /* In jiffies */ |
@@ -250,6 +253,12 @@ int ds1621_detect(struct i2c_adapter *adapter, int address, | |||
250 | ds1621_init_client(new_client); | 253 | ds1621_init_client(new_client); |
251 | 254 | ||
252 | /* Register sysfs hooks */ | 255 | /* Register sysfs hooks */ |
256 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
257 | if (IS_ERR(data->class_dev)) { | ||
258 | err = PTR_ERR(data->class_dev); | ||
259 | goto exit_detach; | ||
260 | } | ||
261 | |||
253 | device_create_file(&new_client->dev, &dev_attr_alarms); | 262 | device_create_file(&new_client->dev, &dev_attr_alarms); |
254 | device_create_file(&new_client->dev, &dev_attr_temp1_input); | 263 | device_create_file(&new_client->dev, &dev_attr_temp1_input); |
255 | device_create_file(&new_client->dev, &dev_attr_temp1_min); | 264 | device_create_file(&new_client->dev, &dev_attr_temp1_min); |
@@ -259,6 +268,8 @@ int ds1621_detect(struct i2c_adapter *adapter, int address, | |||
259 | 268 | ||
260 | /* OK, this is not exactly good programming practice, usually. But it is | 269 | /* OK, this is not exactly good programming practice, usually. But it is |
261 | very code-efficient in this case. */ | 270 | very code-efficient in this case. */ |
271 | exit_detach: | ||
272 | i2c_detach_client(new_client); | ||
262 | exit_free: | 273 | exit_free: |
263 | kfree(data); | 274 | kfree(data); |
264 | exit: | 275 | exit: |
@@ -267,15 +278,18 @@ int ds1621_detect(struct i2c_adapter *adapter, int address, | |||
267 | 278 | ||
268 | static int ds1621_detach_client(struct i2c_client *client) | 279 | static int ds1621_detach_client(struct i2c_client *client) |
269 | { | 280 | { |
281 | struct ds1621_data *data = i2c_get_clientdata(client); | ||
270 | int err; | 282 | int err; |
271 | 283 | ||
284 | hwmon_device_unregister(data->class_dev); | ||
285 | |||
272 | if ((err = i2c_detach_client(client))) { | 286 | if ((err = i2c_detach_client(client))) { |
273 | dev_err(&client->dev, "Client deregistration failed, " | 287 | dev_err(&client->dev, "Client deregistration failed, " |
274 | "client not detached.\n"); | 288 | "client not detached.\n"); |
275 | return err; | 289 | return err; |
276 | } | 290 | } |
277 | 291 | ||
278 | kfree(i2c_get_clientdata(client)); | 292 | kfree(data); |
279 | 293 | ||
280 | return 0; | 294 | return 0; |
281 | } | 295 | } |
diff --git a/drivers/hwmon/fscher.c b/drivers/hwmon/fscher.c index da411741c2c5..b794580a0726 100644 --- a/drivers/hwmon/fscher.c +++ b/drivers/hwmon/fscher.c | |||
@@ -32,6 +32,8 @@ | |||
32 | #include <linux/jiffies.h> | 32 | #include <linux/jiffies.h> |
33 | #include <linux/i2c.h> | 33 | #include <linux/i2c.h> |
34 | #include <linux/i2c-sensor.h> | 34 | #include <linux/i2c-sensor.h> |
35 | #include <linux/hwmon.h> | ||
36 | #include <linux/err.h> | ||
35 | 37 | ||
36 | /* | 38 | /* |
37 | * Addresses to scan | 39 | * Addresses to scan |
@@ -132,6 +134,7 @@ static struct i2c_driver fscher_driver = { | |||
132 | 134 | ||
133 | struct fscher_data { | 135 | struct fscher_data { |
134 | struct i2c_client client; | 136 | struct i2c_client client; |
137 | struct class_device *class_dev; | ||
135 | struct semaphore update_lock; | 138 | struct semaphore update_lock; |
136 | char valid; /* zero until following fields are valid */ | 139 | char valid; /* zero until following fields are valid */ |
137 | unsigned long last_updated; /* in jiffies */ | 140 | unsigned long last_updated; /* in jiffies */ |
@@ -341,6 +344,12 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind) | |||
341 | fscher_init_client(new_client); | 344 | fscher_init_client(new_client); |
342 | 345 | ||
343 | /* Register sysfs hooks */ | 346 | /* Register sysfs hooks */ |
347 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
348 | if (IS_ERR(data->class_dev)) { | ||
349 | err = PTR_ERR(data->class_dev); | ||
350 | goto exit_detach; | ||
351 | } | ||
352 | |||
344 | device_create_file_revision(new_client); | 353 | device_create_file_revision(new_client); |
345 | device_create_file_alarms(new_client); | 354 | device_create_file_alarms(new_client); |
346 | device_create_file_control(new_client); | 355 | device_create_file_control(new_client); |
@@ -360,6 +369,8 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind) | |||
360 | 369 | ||
361 | return 0; | 370 | return 0; |
362 | 371 | ||
372 | exit_detach: | ||
373 | i2c_detach_client(new_client); | ||
363 | exit_free: | 374 | exit_free: |
364 | kfree(data); | 375 | kfree(data); |
365 | exit: | 376 | exit: |
@@ -368,15 +379,18 @@ exit: | |||
368 | 379 | ||
369 | static int fscher_detach_client(struct i2c_client *client) | 380 | static int fscher_detach_client(struct i2c_client *client) |
370 | { | 381 | { |
382 | struct fscher_data *data = i2c_get_clientdata(client); | ||
371 | int err; | 383 | int err; |
372 | 384 | ||
385 | hwmon_device_unregister(data->class_dev); | ||
386 | |||
373 | if ((err = i2c_detach_client(client))) { | 387 | if ((err = i2c_detach_client(client))) { |
374 | dev_err(&client->dev, "Client deregistration failed, " | 388 | dev_err(&client->dev, "Client deregistration failed, " |
375 | "client not detached.\n"); | 389 | "client not detached.\n"); |
376 | return err; | 390 | return err; |
377 | } | 391 | } |
378 | 392 | ||
379 | kfree(i2c_get_clientdata(client)); | 393 | kfree(data); |
380 | return 0; | 394 | return 0; |
381 | } | 395 | } |
382 | 396 | ||
diff --git a/drivers/hwmon/fscpos.c b/drivers/hwmon/fscpos.c index 301ae98bd0ad..4cb33b231124 100644 --- a/drivers/hwmon/fscpos.c +++ b/drivers/hwmon/fscpos.c | |||
@@ -36,6 +36,8 @@ | |||
36 | #include <linux/i2c.h> | 36 | #include <linux/i2c.h> |
37 | #include <linux/i2c-sensor.h> | 37 | #include <linux/i2c-sensor.h> |
38 | #include <linux/init.h> | 38 | #include <linux/init.h> |
39 | #include <linux/hwmon.h> | ||
40 | #include <linux/err.h> | ||
39 | 41 | ||
40 | /* | 42 | /* |
41 | * Addresses to scan | 43 | * Addresses to scan |
@@ -113,6 +115,7 @@ static struct i2c_driver fscpos_driver = { | |||
113 | */ | 115 | */ |
114 | struct fscpos_data { | 116 | struct fscpos_data { |
115 | struct i2c_client client; | 117 | struct i2c_client client; |
118 | struct class_device *class_dev; | ||
116 | struct semaphore update_lock; | 119 | struct semaphore update_lock; |
117 | char valid; /* 0 until following fields are valid */ | 120 | char valid; /* 0 until following fields are valid */ |
118 | unsigned long last_updated; /* In jiffies */ | 121 | unsigned long last_updated; /* In jiffies */ |
@@ -496,6 +499,12 @@ int fscpos_detect(struct i2c_adapter *adapter, int address, int kind) | |||
496 | dev_info(&new_client->dev, "Found fscpos chip, rev %u\n", data->revision); | 499 | dev_info(&new_client->dev, "Found fscpos chip, rev %u\n", data->revision); |
497 | 500 | ||
498 | /* Register sysfs hooks */ | 501 | /* Register sysfs hooks */ |
502 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
503 | if (IS_ERR(data->class_dev)) { | ||
504 | err = PTR_ERR(data->class_dev); | ||
505 | goto exit_detach; | ||
506 | } | ||
507 | |||
499 | device_create_file(&new_client->dev, &dev_attr_event); | 508 | device_create_file(&new_client->dev, &dev_attr_event); |
500 | device_create_file(&new_client->dev, &dev_attr_in0_input); | 509 | device_create_file(&new_client->dev, &dev_attr_in0_input); |
501 | device_create_file(&new_client->dev, &dev_attr_in1_input); | 510 | device_create_file(&new_client->dev, &dev_attr_in1_input); |
@@ -526,6 +535,8 @@ int fscpos_detect(struct i2c_adapter *adapter, int address, int kind) | |||
526 | 535 | ||
527 | return 0; | 536 | return 0; |
528 | 537 | ||
538 | exit_detach: | ||
539 | i2c_detach_client(new_client); | ||
529 | exit_free: | 540 | exit_free: |
530 | kfree(data); | 541 | kfree(data); |
531 | exit: | 542 | exit: |
@@ -534,14 +545,17 @@ exit: | |||
534 | 545 | ||
535 | static int fscpos_detach_client(struct i2c_client *client) | 546 | static int fscpos_detach_client(struct i2c_client *client) |
536 | { | 547 | { |
548 | struct fscpos_data *data = i2c_get_clientdata(client); | ||
537 | int err; | 549 | int err; |
538 | 550 | ||
551 | hwmon_device_unregister(data->class_dev); | ||
552 | |||
539 | if ((err = i2c_detach_client(client))) { | 553 | if ((err = i2c_detach_client(client))) { |
540 | dev_err(&client->dev, "Client deregistration failed, client" | 554 | dev_err(&client->dev, "Client deregistration failed, client" |
541 | " not detached.\n"); | 555 | " not detached.\n"); |
542 | return err; | 556 | return err; |
543 | } | 557 | } |
544 | kfree(i2c_get_clientdata(client)); | 558 | kfree(data); |
545 | return 0; | 559 | return 0; |
546 | } | 560 | } |
547 | 561 | ||
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c index 6bedf729dcf5..49972929a69b 100644 --- a/drivers/hwmon/gl518sm.c +++ b/drivers/hwmon/gl518sm.c | |||
@@ -42,6 +42,8 @@ | |||
42 | #include <linux/jiffies.h> | 42 | #include <linux/jiffies.h> |
43 | #include <linux/i2c.h> | 43 | #include <linux/i2c.h> |
44 | #include <linux/i2c-sensor.h> | 44 | #include <linux/i2c-sensor.h> |
45 | #include <linux/hwmon.h> | ||
46 | #include <linux/err.h> | ||
45 | 47 | ||
46 | /* Addresses to scan */ | 48 | /* Addresses to scan */ |
47 | static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; | 49 | static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; |
@@ -117,6 +119,7 @@ static inline u8 FAN_TO_REG(long rpm, int div) | |||
117 | /* Each client has this additional data */ | 119 | /* Each client has this additional data */ |
118 | struct gl518_data { | 120 | struct gl518_data { |
119 | struct i2c_client client; | 121 | struct i2c_client client; |
122 | struct class_device *class_dev; | ||
120 | enum chips type; | 123 | enum chips type; |
121 | 124 | ||
122 | struct semaphore update_lock; | 125 | struct semaphore update_lock; |
@@ -419,6 +422,12 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) | |||
419 | gl518_init_client((struct i2c_client *) new_client); | 422 | gl518_init_client((struct i2c_client *) new_client); |
420 | 423 | ||
421 | /* Register sysfs hooks */ | 424 | /* Register sysfs hooks */ |
425 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
426 | if (IS_ERR(data->class_dev)) { | ||
427 | err = PTR_ERR(data->class_dev); | ||
428 | goto exit_detach; | ||
429 | } | ||
430 | |||
422 | device_create_file(&new_client->dev, &dev_attr_in0_input); | 431 | device_create_file(&new_client->dev, &dev_attr_in0_input); |
423 | device_create_file(&new_client->dev, &dev_attr_in1_input); | 432 | device_create_file(&new_client->dev, &dev_attr_in1_input); |
424 | device_create_file(&new_client->dev, &dev_attr_in2_input); | 433 | device_create_file(&new_client->dev, &dev_attr_in2_input); |
@@ -450,6 +459,8 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) | |||
450 | /* OK, this is not exactly good programming practice, usually. But it is | 459 | /* OK, this is not exactly good programming practice, usually. But it is |
451 | very code-efficient in this case. */ | 460 | very code-efficient in this case. */ |
452 | 461 | ||
462 | exit_detach: | ||
463 | i2c_detach_client(new_client); | ||
453 | exit_free: | 464 | exit_free: |
454 | kfree(data); | 465 | kfree(data); |
455 | exit: | 466 | exit: |
@@ -477,16 +488,18 @@ static void gl518_init_client(struct i2c_client *client) | |||
477 | 488 | ||
478 | static int gl518_detach_client(struct i2c_client *client) | 489 | static int gl518_detach_client(struct i2c_client *client) |
479 | { | 490 | { |
491 | struct gl518_data *data = i2c_get_clientdata(client); | ||
480 | int err; | 492 | int err; |
481 | 493 | ||
494 | hwmon_device_unregister(data->class_dev); | ||
495 | |||
482 | if ((err = i2c_detach_client(client))) { | 496 | if ((err = i2c_detach_client(client))) { |
483 | dev_err(&client->dev, "Client deregistration failed, " | 497 | dev_err(&client->dev, "Client deregistration failed, " |
484 | "client not detached.\n"); | 498 | "client not detached.\n"); |
485 | return err; | 499 | return err; |
486 | } | 500 | } |
487 | 501 | ||
488 | kfree(i2c_get_clientdata(client)); | 502 | kfree(data); |
489 | |||
490 | return 0; | 503 | return 0; |
491 | } | 504 | } |
492 | 505 | ||
diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c index 80ae8d30c2af..ce482e17e03c 100644 --- a/drivers/hwmon/gl520sm.c +++ b/drivers/hwmon/gl520sm.c | |||
@@ -28,6 +28,8 @@ | |||
28 | #include <linux/i2c.h> | 28 | #include <linux/i2c.h> |
29 | #include <linux/i2c-sensor.h> | 29 | #include <linux/i2c-sensor.h> |
30 | #include <linux/i2c-vid.h> | 30 | #include <linux/i2c-vid.h> |
31 | #include <linux/hwmon.h> | ||
32 | #include <linux/err.h> | ||
31 | 33 | ||
32 | /* Type of the extra sensor */ | 34 | /* Type of the extra sensor */ |
33 | static unsigned short extra_sensor_type; | 35 | static unsigned short extra_sensor_type; |
@@ -120,6 +122,7 @@ static struct i2c_driver gl520_driver = { | |||
120 | /* Client data */ | 122 | /* Client data */ |
121 | struct gl520_data { | 123 | struct gl520_data { |
122 | struct i2c_client client; | 124 | struct i2c_client client; |
125 | struct class_device *class_dev; | ||
123 | struct semaphore update_lock; | 126 | struct semaphore update_lock; |
124 | char valid; /* zero until the following fields are valid */ | 127 | char valid; /* zero until the following fields are valid */ |
125 | unsigned long last_updated; /* in jiffies */ | 128 | unsigned long last_updated; /* in jiffies */ |
@@ -571,6 +574,12 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind) | |||
571 | gl520_init_client(new_client); | 574 | gl520_init_client(new_client); |
572 | 575 | ||
573 | /* Register sysfs hooks */ | 576 | /* Register sysfs hooks */ |
577 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
578 | if (IS_ERR(data->class_dev)) { | ||
579 | err = PTR_ERR(data->class_dev); | ||
580 | goto exit_detach; | ||
581 | } | ||
582 | |||
574 | device_create_file_vid(new_client, 0); | 583 | device_create_file_vid(new_client, 0); |
575 | 584 | ||
576 | device_create_file_in(new_client, 0); | 585 | device_create_file_in(new_client, 0); |
@@ -592,6 +601,8 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind) | |||
592 | 601 | ||
593 | return 0; | 602 | return 0; |
594 | 603 | ||
604 | exit_detach: | ||
605 | i2c_detach_client(new_client); | ||
595 | exit_free: | 606 | exit_free: |
596 | kfree(data); | 607 | kfree(data); |
597 | exit: | 608 | exit: |
@@ -639,15 +650,18 @@ static void gl520_init_client(struct i2c_client *client) | |||
639 | 650 | ||
640 | static int gl520_detach_client(struct i2c_client *client) | 651 | static int gl520_detach_client(struct i2c_client *client) |
641 | { | 652 | { |
653 | struct gl520_data *data = i2c_get_clientdata(client); | ||
642 | int err; | 654 | int err; |
643 | 655 | ||
656 | hwmon_device_unregister(data->class_dev); | ||
657 | |||
644 | if ((err = i2c_detach_client(client))) { | 658 | if ((err = i2c_detach_client(client))) { |
645 | dev_err(&client->dev, "Client deregistration failed, " | 659 | dev_err(&client->dev, "Client deregistration failed, " |
646 | "client not detached.\n"); | 660 | "client not detached.\n"); |
647 | return err; | 661 | return err; |
648 | } | 662 | } |
649 | 663 | ||
650 | kfree(i2c_get_clientdata(client)); | 664 | kfree(data); |
651 | return 0; | 665 | return 0; |
652 | } | 666 | } |
653 | 667 | ||
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c index db20c9e47393..92c5b2420f9b 100644 --- a/drivers/hwmon/it87.c +++ b/drivers/hwmon/it87.c | |||
@@ -39,6 +39,8 @@ | |||
39 | #include <linux/i2c-sensor.h> | 39 | #include <linux/i2c-sensor.h> |
40 | #include <linux/i2c-vid.h> | 40 | #include <linux/i2c-vid.h> |
41 | #include <linux/hwmon-sysfs.h> | 41 | #include <linux/hwmon-sysfs.h> |
42 | #include <linux/hwmon.h> | ||
43 | #include <linux/err.h> | ||
42 | #include <asm/io.h> | 44 | #include <asm/io.h> |
43 | 45 | ||
44 | 46 | ||
@@ -192,6 +194,7 @@ static int DIV_TO_REG(int val) | |||
192 | allocated. */ | 194 | allocated. */ |
193 | struct it87_data { | 195 | struct it87_data { |
194 | struct i2c_client client; | 196 | struct i2c_client client; |
197 | struct class_device *class_dev; | ||
195 | struct semaphore lock; | 198 | struct semaphore lock; |
196 | enum chips type; | 199 | enum chips type; |
197 | 200 | ||
@@ -840,6 +843,12 @@ int it87_detect(struct i2c_adapter *adapter, int address, int kind) | |||
840 | it87_init_client(new_client, data); | 843 | it87_init_client(new_client, data); |
841 | 844 | ||
842 | /* Register sysfs hooks */ | 845 | /* Register sysfs hooks */ |
846 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
847 | if (IS_ERR(data->class_dev)) { | ||
848 | err = PTR_ERR(data->class_dev); | ||
849 | goto ERROR3; | ||
850 | } | ||
851 | |||
843 | device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr); | 852 | device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr); |
844 | device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr); | 853 | device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr); |
845 | device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr); | 854 | device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr); |
@@ -904,6 +913,8 @@ int it87_detect(struct i2c_adapter *adapter, int address, int kind) | |||
904 | 913 | ||
905 | return 0; | 914 | return 0; |
906 | 915 | ||
916 | ERROR3: | ||
917 | i2c_detach_client(new_client); | ||
907 | ERROR2: | 918 | ERROR2: |
908 | kfree(data); | 919 | kfree(data); |
909 | ERROR1: | 920 | ERROR1: |
@@ -915,8 +926,11 @@ ERROR0: | |||
915 | 926 | ||
916 | static int it87_detach_client(struct i2c_client *client) | 927 | static int it87_detach_client(struct i2c_client *client) |
917 | { | 928 | { |
929 | struct it87_data *data = i2c_get_clientdata(client); | ||
918 | int err; | 930 | int err; |
919 | 931 | ||
932 | hwmon_device_unregister(data->class_dev); | ||
933 | |||
920 | if ((err = i2c_detach_client(client))) { | 934 | if ((err = i2c_detach_client(client))) { |
921 | dev_err(&client->dev, | 935 | dev_err(&client->dev, |
922 | "Client deregistration failed, client not detached.\n"); | 936 | "Client deregistration failed, client not detached.\n"); |
@@ -925,7 +939,7 @@ static int it87_detach_client(struct i2c_client *client) | |||
925 | 939 | ||
926 | if(i2c_is_isa_client(client)) | 940 | if(i2c_is_isa_client(client)) |
927 | release_region(client->addr, IT87_EXTENT); | 941 | release_region(client->addr, IT87_EXTENT); |
928 | kfree(i2c_get_clientdata(client)); | 942 | kfree(data); |
929 | 943 | ||
930 | return 0; | 944 | return 0; |
931 | } | 945 | } |
diff --git a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c index 7c6f9ea5a254..cba0a40ad667 100644 --- a/drivers/hwmon/lm63.c +++ b/drivers/hwmon/lm63.c | |||
@@ -44,6 +44,8 @@ | |||
44 | #include <linux/i2c.h> | 44 | #include <linux/i2c.h> |
45 | #include <linux/i2c-sensor.h> | 45 | #include <linux/i2c-sensor.h> |
46 | #include <linux/hwmon-sysfs.h> | 46 | #include <linux/hwmon-sysfs.h> |
47 | #include <linux/hwmon.h> | ||
48 | #include <linux/err.h> | ||
47 | 49 | ||
48 | /* | 50 | /* |
49 | * Addresses to scan | 51 | * Addresses to scan |
@@ -152,6 +154,7 @@ static struct i2c_driver lm63_driver = { | |||
152 | 154 | ||
153 | struct lm63_data { | 155 | struct lm63_data { |
154 | struct i2c_client client; | 156 | struct i2c_client client; |
157 | struct class_device *class_dev; | ||
155 | struct semaphore update_lock; | 158 | struct semaphore update_lock; |
156 | char valid; /* zero until following fields are valid */ | 159 | char valid; /* zero until following fields are valid */ |
157 | unsigned long last_updated; /* in jiffies */ | 160 | unsigned long last_updated; /* in jiffies */ |
@@ -437,6 +440,12 @@ static int lm63_detect(struct i2c_adapter *adapter, int address, int kind) | |||
437 | lm63_init_client(new_client); | 440 | lm63_init_client(new_client); |
438 | 441 | ||
439 | /* Register sysfs hooks */ | 442 | /* Register sysfs hooks */ |
443 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
444 | if (IS_ERR(data->class_dev)) { | ||
445 | err = PTR_ERR(data->class_dev); | ||
446 | goto exit_detach; | ||
447 | } | ||
448 | |||
440 | if (data->config & 0x04) { /* tachometer enabled */ | 449 | if (data->config & 0x04) { /* tachometer enabled */ |
441 | device_create_file(&new_client->dev, | 450 | device_create_file(&new_client->dev, |
442 | &sensor_dev_attr_fan1_input.dev_attr); | 451 | &sensor_dev_attr_fan1_input.dev_attr); |
@@ -462,6 +471,8 @@ static int lm63_detect(struct i2c_adapter *adapter, int address, int kind) | |||
462 | 471 | ||
463 | return 0; | 472 | return 0; |
464 | 473 | ||
474 | exit_detach: | ||
475 | i2c_detach_client(new_client); | ||
465 | exit_free: | 476 | exit_free: |
466 | kfree(data); | 477 | kfree(data); |
467 | exit: | 478 | exit: |
@@ -505,15 +516,18 @@ static void lm63_init_client(struct i2c_client *client) | |||
505 | 516 | ||
506 | static int lm63_detach_client(struct i2c_client *client) | 517 | static int lm63_detach_client(struct i2c_client *client) |
507 | { | 518 | { |
519 | struct lm63_data *data = i2c_get_clientdata(client); | ||
508 | int err; | 520 | int err; |
509 | 521 | ||
522 | hwmon_device_unregister(data->class_dev); | ||
523 | |||
510 | if ((err = i2c_detach_client(client))) { | 524 | if ((err = i2c_detach_client(client))) { |
511 | dev_err(&client->dev, "Client deregistration failed, " | 525 | dev_err(&client->dev, "Client deregistration failed, " |
512 | "client not detached\n"); | 526 | "client not detached\n"); |
513 | return err; | 527 | return err; |
514 | } | 528 | } |
515 | 529 | ||
516 | kfree(i2c_get_clientdata(client)); | 530 | kfree(data); |
517 | return 0; | 531 | return 0; |
518 | } | 532 | } |
519 | 533 | ||
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index 79d7ebc9b14a..129c8f213331 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c | |||
@@ -24,6 +24,8 @@ | |||
24 | #include <linux/jiffies.h> | 24 | #include <linux/jiffies.h> |
25 | #include <linux/i2c.h> | 25 | #include <linux/i2c.h> |
26 | #include <linux/i2c-sensor.h> | 26 | #include <linux/i2c-sensor.h> |
27 | #include <linux/hwmon.h> | ||
28 | #include <linux/err.h> | ||
27 | #include "lm75.h" | 29 | #include "lm75.h" |
28 | 30 | ||
29 | 31 | ||
@@ -46,6 +48,7 @@ SENSORS_INSMOD_1(lm75); | |||
46 | /* Each client has this additional data */ | 48 | /* Each client has this additional data */ |
47 | struct lm75_data { | 49 | struct lm75_data { |
48 | struct i2c_client client; | 50 | struct i2c_client client; |
51 | struct class_device *class_dev; | ||
49 | struct semaphore update_lock; | 52 | struct semaphore update_lock; |
50 | char valid; /* !=0 if following fields are valid */ | 53 | char valid; /* !=0 if following fields are valid */ |
51 | unsigned long last_updated; /* In jiffies */ | 54 | unsigned long last_updated; /* In jiffies */ |
@@ -208,12 +211,20 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) | |||
208 | lm75_init_client(new_client); | 211 | lm75_init_client(new_client); |
209 | 212 | ||
210 | /* Register sysfs hooks */ | 213 | /* Register sysfs hooks */ |
214 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
215 | if (IS_ERR(data->class_dev)) { | ||
216 | err = PTR_ERR(data->class_dev); | ||
217 | goto exit_detach; | ||
218 | } | ||
219 | |||
211 | device_create_file(&new_client->dev, &dev_attr_temp1_max); | 220 | device_create_file(&new_client->dev, &dev_attr_temp1_max); |
212 | device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst); | 221 | device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst); |
213 | device_create_file(&new_client->dev, &dev_attr_temp1_input); | 222 | device_create_file(&new_client->dev, &dev_attr_temp1_input); |
214 | 223 | ||
215 | return 0; | 224 | return 0; |
216 | 225 | ||
226 | exit_detach: | ||
227 | i2c_detach_client(new_client); | ||
217 | exit_free: | 228 | exit_free: |
218 | kfree(data); | 229 | kfree(data); |
219 | exit: | 230 | exit: |
@@ -222,8 +233,10 @@ exit: | |||
222 | 233 | ||
223 | static int lm75_detach_client(struct i2c_client *client) | 234 | static int lm75_detach_client(struct i2c_client *client) |
224 | { | 235 | { |
236 | struct lm75_data *data = i2c_get_clientdata(client); | ||
237 | hwmon_device_unregister(data->class_dev); | ||
225 | i2c_detach_client(client); | 238 | i2c_detach_client(client); |
226 | kfree(i2c_get_clientdata(client)); | 239 | kfree(data); |
227 | return 0; | 240 | return 0; |
228 | } | 241 | } |
229 | 242 | ||
diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c index b98f44952997..15f30fdc75c6 100644 --- a/drivers/hwmon/lm77.c +++ b/drivers/hwmon/lm77.c | |||
@@ -31,7 +31,8 @@ | |||
31 | #include <linux/jiffies.h> | 31 | #include <linux/jiffies.h> |
32 | #include <linux/i2c.h> | 32 | #include <linux/i2c.h> |
33 | #include <linux/i2c-sensor.h> | 33 | #include <linux/i2c-sensor.h> |
34 | 34 | #include <linux/hwmon.h> | |
35 | #include <linux/err.h> | ||
35 | 36 | ||
36 | /* Addresses to scan */ | 37 | /* Addresses to scan */ |
37 | static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, I2C_CLIENT_END }; | 38 | static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, I2C_CLIENT_END }; |
@@ -51,6 +52,7 @@ SENSORS_INSMOD_1(lm77); | |||
51 | /* Each client has this additional data */ | 52 | /* Each client has this additional data */ |
52 | struct lm77_data { | 53 | struct lm77_data { |
53 | struct i2c_client client; | 54 | struct i2c_client client; |
55 | struct class_device *class_dev; | ||
54 | struct semaphore update_lock; | 56 | struct semaphore update_lock; |
55 | char valid; | 57 | char valid; |
56 | unsigned long last_updated; /* In jiffies */ | 58 | unsigned long last_updated; /* In jiffies */ |
@@ -317,6 +319,12 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) | |||
317 | lm77_init_client(new_client); | 319 | lm77_init_client(new_client); |
318 | 320 | ||
319 | /* Register sysfs hooks */ | 321 | /* Register sysfs hooks */ |
322 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
323 | if (IS_ERR(data->class_dev)) { | ||
324 | err = PTR_ERR(data->class_dev); | ||
325 | goto exit_detach; | ||
326 | } | ||
327 | |||
320 | device_create_file(&new_client->dev, &dev_attr_temp1_input); | 328 | device_create_file(&new_client->dev, &dev_attr_temp1_input); |
321 | device_create_file(&new_client->dev, &dev_attr_temp1_crit); | 329 | device_create_file(&new_client->dev, &dev_attr_temp1_crit); |
322 | device_create_file(&new_client->dev, &dev_attr_temp1_min); | 330 | device_create_file(&new_client->dev, &dev_attr_temp1_min); |
@@ -327,6 +335,8 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) | |||
327 | device_create_file(&new_client->dev, &dev_attr_alarms); | 335 | device_create_file(&new_client->dev, &dev_attr_alarms); |
328 | return 0; | 336 | return 0; |
329 | 337 | ||
338 | exit_detach: | ||
339 | i2c_detach_client(new_client); | ||
330 | exit_free: | 340 | exit_free: |
331 | kfree(data); | 341 | kfree(data); |
332 | exit: | 342 | exit: |
@@ -335,8 +345,10 @@ exit: | |||
335 | 345 | ||
336 | static int lm77_detach_client(struct i2c_client *client) | 346 | static int lm77_detach_client(struct i2c_client *client) |
337 | { | 347 | { |
348 | struct lm77_data *data = i2c_get_clientdata(client); | ||
349 | hwmon_device_unregister(data->class_dev); | ||
338 | i2c_detach_client(client); | 350 | i2c_detach_client(client); |
339 | kfree(i2c_get_clientdata(client)); | 351 | kfree(data); |
340 | return 0; | 352 | return 0; |
341 | } | 353 | } |
342 | 354 | ||
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c index cf7a2a7f54b5..570098e15366 100644 --- a/drivers/hwmon/lm78.c +++ b/drivers/hwmon/lm78.c | |||
@@ -24,6 +24,8 @@ | |||
24 | #include <linux/jiffies.h> | 24 | #include <linux/jiffies.h> |
25 | #include <linux/i2c.h> | 25 | #include <linux/i2c.h> |
26 | #include <linux/i2c-sensor.h> | 26 | #include <linux/i2c-sensor.h> |
27 | #include <linux/hwmon.h> | ||
28 | #include <linux/err.h> | ||
27 | #include <asm/io.h> | 29 | #include <asm/io.h> |
28 | 30 | ||
29 | /* Addresses to scan */ | 31 | /* Addresses to scan */ |
@@ -134,6 +136,7 @@ static inline int VID_FROM_REG(u8 val) | |||
134 | allocated. */ | 136 | allocated. */ |
135 | struct lm78_data { | 137 | struct lm78_data { |
136 | struct i2c_client client; | 138 | struct i2c_client client; |
139 | struct class_device *class_dev; | ||
137 | struct semaphore lock; | 140 | struct semaphore lock; |
138 | enum chips type; | 141 | enum chips type; |
139 | 142 | ||
@@ -602,6 +605,12 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind) | |||
602 | } | 605 | } |
603 | 606 | ||
604 | /* Register sysfs hooks */ | 607 | /* Register sysfs hooks */ |
608 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
609 | if (IS_ERR(data->class_dev)) { | ||
610 | err = PTR_ERR(data->class_dev); | ||
611 | goto ERROR3; | ||
612 | } | ||
613 | |||
605 | device_create_file(&new_client->dev, &dev_attr_in0_input); | 614 | device_create_file(&new_client->dev, &dev_attr_in0_input); |
606 | device_create_file(&new_client->dev, &dev_attr_in0_min); | 615 | device_create_file(&new_client->dev, &dev_attr_in0_min); |
607 | device_create_file(&new_client->dev, &dev_attr_in0_max); | 616 | device_create_file(&new_client->dev, &dev_attr_in0_max); |
@@ -640,6 +649,8 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind) | |||
640 | 649 | ||
641 | return 0; | 650 | return 0; |
642 | 651 | ||
652 | ERROR3: | ||
653 | i2c_detach_client(new_client); | ||
643 | ERROR2: | 654 | ERROR2: |
644 | kfree(data); | 655 | kfree(data); |
645 | ERROR1: | 656 | ERROR1: |
@@ -651,8 +662,11 @@ ERROR0: | |||
651 | 662 | ||
652 | static int lm78_detach_client(struct i2c_client *client) | 663 | static int lm78_detach_client(struct i2c_client *client) |
653 | { | 664 | { |
665 | struct lm78_data *data = i2c_get_clientdata(client); | ||
654 | int err; | 666 | int err; |
655 | 667 | ||
668 | hwmon_device_unregister(data->class_dev); | ||
669 | |||
656 | if ((err = i2c_detach_client(client))) { | 670 | if ((err = i2c_detach_client(client))) { |
657 | dev_err(&client->dev, | 671 | dev_err(&client->dev, |
658 | "Client deregistration failed, client not detached.\n"); | 672 | "Client deregistration failed, client not detached.\n"); |
@@ -662,7 +676,7 @@ static int lm78_detach_client(struct i2c_client *client) | |||
662 | if(i2c_is_isa_client(client)) | 676 | if(i2c_is_isa_client(client)) |
663 | release_region(client->addr, LM78_EXTENT); | 677 | release_region(client->addr, LM78_EXTENT); |
664 | 678 | ||
665 | kfree(i2c_get_clientdata(client)); | 679 | kfree(data); |
666 | 680 | ||
667 | return 0; | 681 | return 0; |
668 | } | 682 | } |
diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c index 8100595feb44..dbf8df386250 100644 --- a/drivers/hwmon/lm80.c +++ b/drivers/hwmon/lm80.c | |||
@@ -27,6 +27,8 @@ | |||
27 | #include <linux/jiffies.h> | 27 | #include <linux/jiffies.h> |
28 | #include <linux/i2c.h> | 28 | #include <linux/i2c.h> |
29 | #include <linux/i2c-sensor.h> | 29 | #include <linux/i2c-sensor.h> |
30 | #include <linux/hwmon.h> | ||
31 | #include <linux/err.h> | ||
30 | 32 | ||
31 | /* Addresses to scan */ | 33 | /* Addresses to scan */ |
32 | static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, | 34 | static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, |
@@ -107,6 +109,7 @@ static inline long TEMP_FROM_REG(u16 temp) | |||
107 | 109 | ||
108 | struct lm80_data { | 110 | struct lm80_data { |
109 | struct i2c_client client; | 111 | struct i2c_client client; |
112 | struct class_device *class_dev; | ||
110 | struct semaphore update_lock; | 113 | struct semaphore update_lock; |
111 | char valid; /* !=0 if following fields are valid */ | 114 | char valid; /* !=0 if following fields are valid */ |
112 | unsigned long last_updated; /* In jiffies */ | 115 | unsigned long last_updated; /* In jiffies */ |
@@ -451,6 +454,12 @@ int lm80_detect(struct i2c_adapter *adapter, int address, int kind) | |||
451 | data->fan_min[1] = lm80_read_value(new_client, LM80_REG_FAN_MIN(2)); | 454 | data->fan_min[1] = lm80_read_value(new_client, LM80_REG_FAN_MIN(2)); |
452 | 455 | ||
453 | /* Register sysfs hooks */ | 456 | /* Register sysfs hooks */ |
457 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
458 | if (IS_ERR(data->class_dev)) { | ||
459 | err = PTR_ERR(data->class_dev); | ||
460 | goto error_detach; | ||
461 | } | ||
462 | |||
454 | device_create_file(&new_client->dev, &dev_attr_in0_min); | 463 | device_create_file(&new_client->dev, &dev_attr_in0_min); |
455 | device_create_file(&new_client->dev, &dev_attr_in1_min); | 464 | device_create_file(&new_client->dev, &dev_attr_in1_min); |
456 | device_create_file(&new_client->dev, &dev_attr_in2_min); | 465 | device_create_file(&new_client->dev, &dev_attr_in2_min); |
@@ -487,6 +496,8 @@ int lm80_detect(struct i2c_adapter *adapter, int address, int kind) | |||
487 | 496 | ||
488 | return 0; | 497 | return 0; |
489 | 498 | ||
499 | error_detach: | ||
500 | i2c_detach_client(new_client); | ||
490 | error_free: | 501 | error_free: |
491 | kfree(data); | 502 | kfree(data); |
492 | exit: | 503 | exit: |
@@ -495,15 +506,18 @@ exit: | |||
495 | 506 | ||
496 | static int lm80_detach_client(struct i2c_client *client) | 507 | static int lm80_detach_client(struct i2c_client *client) |
497 | { | 508 | { |
509 | struct lm80_data *data = i2c_get_clientdata(client); | ||
498 | int err; | 510 | int err; |
499 | 511 | ||
512 | hwmon_device_unregister(data->class_dev); | ||
513 | |||
500 | if ((err = i2c_detach_client(client))) { | 514 | if ((err = i2c_detach_client(client))) { |
501 | dev_err(&client->dev, "Client deregistration failed, " | 515 | dev_err(&client->dev, "Client deregistration failed, " |
502 | "client not detached.\n"); | 516 | "client not detached.\n"); |
503 | return err; | 517 | return err; |
504 | } | 518 | } |
505 | 519 | ||
506 | kfree(i2c_get_clientdata(client)); | 520 | kfree(data); |
507 | return 0; | 521 | return 0; |
508 | } | 522 | } |
509 | 523 | ||
diff --git a/drivers/hwmon/lm83.c b/drivers/hwmon/lm83.c index a49008b444c8..f3f3901c7294 100644 --- a/drivers/hwmon/lm83.c +++ b/drivers/hwmon/lm83.c | |||
@@ -34,6 +34,8 @@ | |||
34 | #include <linux/i2c.h> | 34 | #include <linux/i2c.h> |
35 | #include <linux/i2c-sensor.h> | 35 | #include <linux/i2c-sensor.h> |
36 | #include <linux/hwmon-sysfs.h> | 36 | #include <linux/hwmon-sysfs.h> |
37 | #include <linux/hwmon.h> | ||
38 | #include <linux/err.h> | ||
37 | 39 | ||
38 | /* | 40 | /* |
39 | * Addresses to scan | 41 | * Addresses to scan |
@@ -138,6 +140,7 @@ static struct i2c_driver lm83_driver = { | |||
138 | 140 | ||
139 | struct lm83_data { | 141 | struct lm83_data { |
140 | struct i2c_client client; | 142 | struct i2c_client client; |
143 | struct class_device *class_dev; | ||
141 | struct semaphore update_lock; | 144 | struct semaphore update_lock; |
142 | char valid; /* zero until following fields are valid */ | 145 | char valid; /* zero until following fields are valid */ |
143 | unsigned long last_updated; /* in jiffies */ | 146 | unsigned long last_updated; /* in jiffies */ |
@@ -312,6 +315,12 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind) | |||
312 | */ | 315 | */ |
313 | 316 | ||
314 | /* Register sysfs hooks */ | 317 | /* Register sysfs hooks */ |
318 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
319 | if (IS_ERR(data->class_dev)) { | ||
320 | err = PTR_ERR(data->class_dev); | ||
321 | goto exit_detach; | ||
322 | } | ||
323 | |||
315 | device_create_file(&new_client->dev, | 324 | device_create_file(&new_client->dev, |
316 | &sensor_dev_attr_temp1_input.dev_attr); | 325 | &sensor_dev_attr_temp1_input.dev_attr); |
317 | device_create_file(&new_client->dev, | 326 | device_create_file(&new_client->dev, |
@@ -340,6 +349,8 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind) | |||
340 | 349 | ||
341 | return 0; | 350 | return 0; |
342 | 351 | ||
352 | exit_detach: | ||
353 | i2c_detach_client(new_client); | ||
343 | exit_free: | 354 | exit_free: |
344 | kfree(data); | 355 | kfree(data); |
345 | exit: | 356 | exit: |
@@ -348,15 +359,18 @@ exit: | |||
348 | 359 | ||
349 | static int lm83_detach_client(struct i2c_client *client) | 360 | static int lm83_detach_client(struct i2c_client *client) |
350 | { | 361 | { |
362 | struct lm83_data *data = i2c_get_clientdata(client); | ||
351 | int err; | 363 | int err; |
352 | 364 | ||
365 | hwmon_device_unregister(data->class_dev); | ||
366 | |||
353 | if ((err = i2c_detach_client(client))) { | 367 | if ((err = i2c_detach_client(client))) { |
354 | dev_err(&client->dev, | 368 | dev_err(&client->dev, |
355 | "Client deregistration failed, client not detached.\n"); | 369 | "Client deregistration failed, client not detached.\n"); |
356 | return err; | 370 | return err; |
357 | } | 371 | } |
358 | 372 | ||
359 | kfree(i2c_get_clientdata(client)); | 373 | kfree(data); |
360 | return 0; | 374 | return 0; |
361 | } | 375 | } |
362 | 376 | ||
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c index b4d7fd418264..4203f904bbe2 100644 --- a/drivers/hwmon/lm85.c +++ b/drivers/hwmon/lm85.c | |||
@@ -30,6 +30,8 @@ | |||
30 | #include <linux/i2c.h> | 30 | #include <linux/i2c.h> |
31 | #include <linux/i2c-sensor.h> | 31 | #include <linux/i2c-sensor.h> |
32 | #include <linux/i2c-vid.h> | 32 | #include <linux/i2c-vid.h> |
33 | #include <linux/hwmon.h> | ||
34 | #include <linux/err.h> | ||
33 | 35 | ||
34 | /* Addresses to scan */ | 36 | /* Addresses to scan */ |
35 | static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; | 37 | static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; |
@@ -339,6 +341,7 @@ struct lm85_autofan { | |||
339 | 341 | ||
340 | struct lm85_data { | 342 | struct lm85_data { |
341 | struct i2c_client client; | 343 | struct i2c_client client; |
344 | struct class_device *class_dev; | ||
342 | struct semaphore lock; | 345 | struct semaphore lock; |
343 | enum chips type; | 346 | enum chips type; |
344 | 347 | ||
@@ -1166,6 +1169,12 @@ int lm85_detect(struct i2c_adapter *adapter, int address, | |||
1166 | lm85_init_client(new_client); | 1169 | lm85_init_client(new_client); |
1167 | 1170 | ||
1168 | /* Register sysfs hooks */ | 1171 | /* Register sysfs hooks */ |
1172 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
1173 | if (IS_ERR(data->class_dev)) { | ||
1174 | err = PTR_ERR(data->class_dev); | ||
1175 | goto ERROR2; | ||
1176 | } | ||
1177 | |||
1169 | device_create_file(&new_client->dev, &dev_attr_fan1_input); | 1178 | device_create_file(&new_client->dev, &dev_attr_fan1_input); |
1170 | device_create_file(&new_client->dev, &dev_attr_fan2_input); | 1179 | device_create_file(&new_client->dev, &dev_attr_fan2_input); |
1171 | device_create_file(&new_client->dev, &dev_attr_fan3_input); | 1180 | device_create_file(&new_client->dev, &dev_attr_fan3_input); |
@@ -1235,6 +1244,8 @@ int lm85_detect(struct i2c_adapter *adapter, int address, | |||
1235 | return 0; | 1244 | return 0; |
1236 | 1245 | ||
1237 | /* Error out and cleanup code */ | 1246 | /* Error out and cleanup code */ |
1247 | ERROR2: | ||
1248 | i2c_detach_client(new_client); | ||
1238 | ERROR1: | 1249 | ERROR1: |
1239 | kfree(data); | 1250 | kfree(data); |
1240 | ERROR0: | 1251 | ERROR0: |
@@ -1243,8 +1254,10 @@ int lm85_detect(struct i2c_adapter *adapter, int address, | |||
1243 | 1254 | ||
1244 | int lm85_detach_client(struct i2c_client *client) | 1255 | int lm85_detach_client(struct i2c_client *client) |
1245 | { | 1256 | { |
1257 | struct lm85_data *data = i2c_get_clientdata(client); | ||
1258 | hwmon_device_unregister(data->class_dev); | ||
1246 | i2c_detach_client(client); | 1259 | i2c_detach_client(client); |
1247 | kfree(i2c_get_clientdata(client)); | 1260 | kfree(data); |
1248 | return 0; | 1261 | return 0; |
1249 | } | 1262 | } |
1250 | 1263 | ||
diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c index 1921ed1af182..7e14858c257b 100644 --- a/drivers/hwmon/lm87.c +++ b/drivers/hwmon/lm87.c | |||
@@ -59,6 +59,8 @@ | |||
59 | #include <linux/i2c.h> | 59 | #include <linux/i2c.h> |
60 | #include <linux/i2c-sensor.h> | 60 | #include <linux/i2c-sensor.h> |
61 | #include <linux/i2c-vid.h> | 61 | #include <linux/i2c-vid.h> |
62 | #include <linux/hwmon.h> | ||
63 | #include <linux/err.h> | ||
62 | 64 | ||
63 | /* | 65 | /* |
64 | * Addresses to scan | 66 | * Addresses to scan |
@@ -175,6 +177,7 @@ static struct i2c_driver lm87_driver = { | |||
175 | 177 | ||
176 | struct lm87_data { | 178 | struct lm87_data { |
177 | struct i2c_client client; | 179 | struct i2c_client client; |
180 | struct class_device *class_dev; | ||
178 | struct semaphore update_lock; | 181 | struct semaphore update_lock; |
179 | char valid; /* zero until following fields are valid */ | 182 | char valid; /* zero until following fields are valid */ |
180 | unsigned long last_updated; /* In jiffies */ | 183 | unsigned long last_updated; /* In jiffies */ |
@@ -608,6 +611,12 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind) | |||
608 | data->in_scale[7] = 1875; | 611 | data->in_scale[7] = 1875; |
609 | 612 | ||
610 | /* Register sysfs hooks */ | 613 | /* Register sysfs hooks */ |
614 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
615 | if (IS_ERR(data->class_dev)) { | ||
616 | err = PTR_ERR(data->class_dev); | ||
617 | goto exit_detach; | ||
618 | } | ||
619 | |||
611 | device_create_file(&new_client->dev, &dev_attr_in1_input); | 620 | device_create_file(&new_client->dev, &dev_attr_in1_input); |
612 | device_create_file(&new_client->dev, &dev_attr_in1_min); | 621 | device_create_file(&new_client->dev, &dev_attr_in1_min); |
613 | device_create_file(&new_client->dev, &dev_attr_in1_max); | 622 | device_create_file(&new_client->dev, &dev_attr_in1_max); |
@@ -673,6 +682,8 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind) | |||
673 | 682 | ||
674 | return 0; | 683 | return 0; |
675 | 684 | ||
685 | exit_detach: | ||
686 | i2c_detach_client(new_client); | ||
676 | exit_free: | 687 | exit_free: |
677 | kfree(data); | 688 | kfree(data); |
678 | exit: | 689 | exit: |
@@ -719,15 +730,18 @@ static void lm87_init_client(struct i2c_client *client) | |||
719 | 730 | ||
720 | static int lm87_detach_client(struct i2c_client *client) | 731 | static int lm87_detach_client(struct i2c_client *client) |
721 | { | 732 | { |
733 | struct lm87_data *data = i2c_get_clientdata(client); | ||
722 | int err; | 734 | int err; |
723 | 735 | ||
736 | hwmon_device_unregister(data->class_dev); | ||
737 | |||
724 | if ((err = i2c_detach_client(client))) { | 738 | if ((err = i2c_detach_client(client))) { |
725 | dev_err(&client->dev, "Client deregistration failed, " | 739 | dev_err(&client->dev, "Client deregistration failed, " |
726 | "client not detached.\n"); | 740 | "client not detached.\n"); |
727 | return err; | 741 | return err; |
728 | } | 742 | } |
729 | 743 | ||
730 | kfree(i2c_get_clientdata(client)); | 744 | kfree(data); |
731 | return 0; | 745 | return 0; |
732 | } | 746 | } |
733 | 747 | ||
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index a67dcadf7cb0..c1e8d0e965f7 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c | |||
@@ -77,6 +77,8 @@ | |||
77 | #include <linux/i2c.h> | 77 | #include <linux/i2c.h> |
78 | #include <linux/i2c-sensor.h> | 78 | #include <linux/i2c-sensor.h> |
79 | #include <linux/hwmon-sysfs.h> | 79 | #include <linux/hwmon-sysfs.h> |
80 | #include <linux/hwmon.h> | ||
81 | #include <linux/err.h> | ||
80 | 82 | ||
81 | /* | 83 | /* |
82 | * Addresses to scan | 84 | * Addresses to scan |
@@ -200,6 +202,7 @@ static struct i2c_driver lm90_driver = { | |||
200 | 202 | ||
201 | struct lm90_data { | 203 | struct lm90_data { |
202 | struct i2c_client client; | 204 | struct i2c_client client; |
205 | struct class_device *class_dev; | ||
203 | struct semaphore update_lock; | 206 | struct semaphore update_lock; |
204 | char valid; /* zero until following fields are valid */ | 207 | char valid; /* zero until following fields are valid */ |
205 | unsigned long last_updated; /* in jiffies */ | 208 | unsigned long last_updated; /* in jiffies */ |
@@ -500,6 +503,12 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) | |||
500 | lm90_init_client(new_client); | 503 | lm90_init_client(new_client); |
501 | 504 | ||
502 | /* Register sysfs hooks */ | 505 | /* Register sysfs hooks */ |
506 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
507 | if (IS_ERR(data->class_dev)) { | ||
508 | err = PTR_ERR(data->class_dev); | ||
509 | goto exit_detach; | ||
510 | } | ||
511 | |||
503 | device_create_file(&new_client->dev, | 512 | device_create_file(&new_client->dev, |
504 | &sensor_dev_attr_temp1_input.dev_attr); | 513 | &sensor_dev_attr_temp1_input.dev_attr); |
505 | device_create_file(&new_client->dev, | 514 | device_create_file(&new_client->dev, |
@@ -524,6 +533,8 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) | |||
524 | 533 | ||
525 | return 0; | 534 | return 0; |
526 | 535 | ||
536 | exit_detach: | ||
537 | i2c_detach_client(new_client); | ||
527 | exit_free: | 538 | exit_free: |
528 | kfree(data); | 539 | kfree(data); |
529 | exit: | 540 | exit: |
@@ -547,15 +558,18 @@ static void lm90_init_client(struct i2c_client *client) | |||
547 | 558 | ||
548 | static int lm90_detach_client(struct i2c_client *client) | 559 | static int lm90_detach_client(struct i2c_client *client) |
549 | { | 560 | { |
561 | struct lm90_data *data = i2c_get_clientdata(client); | ||
550 | int err; | 562 | int err; |
551 | 563 | ||
564 | hwmon_device_unregister(data->class_dev); | ||
565 | |||
552 | if ((err = i2c_detach_client(client))) { | 566 | if ((err = i2c_detach_client(client))) { |
553 | dev_err(&client->dev, "Client deregistration failed, " | 567 | dev_err(&client->dev, "Client deregistration failed, " |
554 | "client not detached.\n"); | 568 | "client not detached.\n"); |
555 | return err; | 569 | return err; |
556 | } | 570 | } |
557 | 571 | ||
558 | kfree(i2c_get_clientdata(client)); | 572 | kfree(data); |
559 | return 0; | 573 | return 0; |
560 | } | 574 | } |
561 | 575 | ||
diff --git a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c index 215c8e40ffdd..0fb601c07519 100644 --- a/drivers/hwmon/lm92.c +++ b/drivers/hwmon/lm92.c | |||
@@ -45,7 +45,8 @@ | |||
45 | #include <linux/slab.h> | 45 | #include <linux/slab.h> |
46 | #include <linux/i2c.h> | 46 | #include <linux/i2c.h> |
47 | #include <linux/i2c-sensor.h> | 47 | #include <linux/i2c-sensor.h> |
48 | 48 | #include <linux/hwmon.h> | |
49 | #include <linux/err.h> | ||
49 | 50 | ||
50 | /* The LM92 and MAX6635 have 2 two-state pins for address selection, | 51 | /* The LM92 and MAX6635 have 2 two-state pins for address selection, |
51 | resulting in 4 possible addresses. */ | 52 | resulting in 4 possible addresses. */ |
@@ -96,6 +97,7 @@ static struct i2c_driver lm92_driver; | |||
96 | /* Client data (each client gets its own) */ | 97 | /* Client data (each client gets its own) */ |
97 | struct lm92_data { | 98 | struct lm92_data { |
98 | struct i2c_client client; | 99 | struct i2c_client client; |
100 | struct class_device *class_dev; | ||
99 | struct semaphore update_lock; | 101 | struct semaphore update_lock; |
100 | char valid; /* zero until following fields are valid */ | 102 | char valid; /* zero until following fields are valid */ |
101 | unsigned long last_updated; /* in jiffies */ | 103 | unsigned long last_updated; /* in jiffies */ |
@@ -359,6 +361,12 @@ static int lm92_detect(struct i2c_adapter *adapter, int address, int kind) | |||
359 | lm92_init_client(new_client); | 361 | lm92_init_client(new_client); |
360 | 362 | ||
361 | /* Register sysfs hooks */ | 363 | /* Register sysfs hooks */ |
364 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
365 | if (IS_ERR(data->class_dev)) { | ||
366 | err = PTR_ERR(data->class_dev); | ||
367 | goto exit_detach; | ||
368 | } | ||
369 | |||
362 | device_create_file(&new_client->dev, &dev_attr_temp1_input); | 370 | device_create_file(&new_client->dev, &dev_attr_temp1_input); |
363 | device_create_file(&new_client->dev, &dev_attr_temp1_crit); | 371 | device_create_file(&new_client->dev, &dev_attr_temp1_crit); |
364 | device_create_file(&new_client->dev, &dev_attr_temp1_crit_hyst); | 372 | device_create_file(&new_client->dev, &dev_attr_temp1_crit_hyst); |
@@ -370,6 +378,8 @@ static int lm92_detect(struct i2c_adapter *adapter, int address, int kind) | |||
370 | 378 | ||
371 | return 0; | 379 | return 0; |
372 | 380 | ||
381 | exit_detach: | ||
382 | i2c_detach_client(new_client); | ||
373 | exit_free: | 383 | exit_free: |
374 | kfree(data); | 384 | kfree(data); |
375 | exit: | 385 | exit: |
@@ -385,15 +395,18 @@ static int lm92_attach_adapter(struct i2c_adapter *adapter) | |||
385 | 395 | ||
386 | static int lm92_detach_client(struct i2c_client *client) | 396 | static int lm92_detach_client(struct i2c_client *client) |
387 | { | 397 | { |
398 | struct lm92_data *data = i2c_get_clientdata(client); | ||
388 | int err; | 399 | int err; |
389 | 400 | ||
401 | hwmon_device_unregister(data->class_dev); | ||
402 | |||
390 | if ((err = i2c_detach_client(client))) { | 403 | if ((err = i2c_detach_client(client))) { |
391 | dev_err(&client->dev, "Client deregistration failed, " | 404 | dev_err(&client->dev, "Client deregistration failed, " |
392 | "client not detached.\n"); | 405 | "client not detached.\n"); |
393 | return err; | 406 | return err; |
394 | } | 407 | } |
395 | 408 | ||
396 | kfree(i2c_get_clientdata(client)); | 409 | kfree(data); |
397 | return 0; | 410 | return 0; |
398 | } | 411 | } |
399 | 412 | ||
diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c index 3c159f1d49ee..56c34c2d3619 100644 --- a/drivers/hwmon/max1619.c +++ b/drivers/hwmon/max1619.c | |||
@@ -32,7 +32,8 @@ | |||
32 | #include <linux/jiffies.h> | 32 | #include <linux/jiffies.h> |
33 | #include <linux/i2c.h> | 33 | #include <linux/i2c.h> |
34 | #include <linux/i2c-sensor.h> | 34 | #include <linux/i2c-sensor.h> |
35 | 35 | #include <linux/hwmon.h> | |
36 | #include <linux/err.h> | ||
36 | 37 | ||
37 | static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a, | 38 | static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a, |
38 | 0x29, 0x2a, 0x2b, | 39 | 0x29, 0x2a, 0x2b, |
@@ -104,6 +105,7 @@ static struct i2c_driver max1619_driver = { | |||
104 | 105 | ||
105 | struct max1619_data { | 106 | struct max1619_data { |
106 | struct i2c_client client; | 107 | struct i2c_client client; |
108 | struct class_device *class_dev; | ||
107 | struct semaphore update_lock; | 109 | struct semaphore update_lock; |
108 | char valid; /* zero until following fields are valid */ | 110 | char valid; /* zero until following fields are valid */ |
109 | unsigned long last_updated; /* in jiffies */ | 111 | unsigned long last_updated; /* in jiffies */ |
@@ -275,6 +277,12 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind) | |||
275 | max1619_init_client(new_client); | 277 | max1619_init_client(new_client); |
276 | 278 | ||
277 | /* Register sysfs hooks */ | 279 | /* Register sysfs hooks */ |
280 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
281 | if (IS_ERR(data->class_dev)) { | ||
282 | err = PTR_ERR(data->class_dev); | ||
283 | goto exit_detach; | ||
284 | } | ||
285 | |||
278 | device_create_file(&new_client->dev, &dev_attr_temp1_input); | 286 | device_create_file(&new_client->dev, &dev_attr_temp1_input); |
279 | device_create_file(&new_client->dev, &dev_attr_temp2_input); | 287 | device_create_file(&new_client->dev, &dev_attr_temp2_input); |
280 | device_create_file(&new_client->dev, &dev_attr_temp2_min); | 288 | device_create_file(&new_client->dev, &dev_attr_temp2_min); |
@@ -285,6 +293,8 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind) | |||
285 | 293 | ||
286 | return 0; | 294 | return 0; |
287 | 295 | ||
296 | exit_detach: | ||
297 | i2c_detach_client(new_client); | ||
288 | exit_free: | 298 | exit_free: |
289 | kfree(data); | 299 | kfree(data); |
290 | exit: | 300 | exit: |
@@ -308,15 +318,18 @@ static void max1619_init_client(struct i2c_client *client) | |||
308 | 318 | ||
309 | static int max1619_detach_client(struct i2c_client *client) | 319 | static int max1619_detach_client(struct i2c_client *client) |
310 | { | 320 | { |
321 | struct max1619_data *data = i2c_get_clientdata(client); | ||
311 | int err; | 322 | int err; |
312 | 323 | ||
324 | hwmon_device_unregister(data->class_dev); | ||
325 | |||
313 | if ((err = i2c_detach_client(client))) { | 326 | if ((err = i2c_detach_client(client))) { |
314 | dev_err(&client->dev, "Client deregistration failed, " | 327 | dev_err(&client->dev, "Client deregistration failed, " |
315 | "client not detached.\n"); | 328 | "client not detached.\n"); |
316 | return err; | 329 | return err; |
317 | } | 330 | } |
318 | 331 | ||
319 | kfree(i2c_get_clientdata(client)); | 332 | kfree(data); |
320 | return 0; | 333 | return 0; |
321 | } | 334 | } |
322 | 335 | ||
diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c index fa4032d53b79..496549bf96b9 100644 --- a/drivers/hwmon/pc87360.c +++ b/drivers/hwmon/pc87360.c | |||
@@ -40,6 +40,8 @@ | |||
40 | #include <linux/i2c.h> | 40 | #include <linux/i2c.h> |
41 | #include <linux/i2c-sensor.h> | 41 | #include <linux/i2c-sensor.h> |
42 | #include <linux/i2c-vid.h> | 42 | #include <linux/i2c-vid.h> |
43 | #include <linux/hwmon.h> | ||
44 | #include <linux/err.h> | ||
43 | #include <asm/io.h> | 45 | #include <asm/io.h> |
44 | 46 | ||
45 | static unsigned short normal_i2c[] = { I2C_CLIENT_END }; | 47 | static unsigned short normal_i2c[] = { I2C_CLIENT_END }; |
@@ -186,6 +188,7 @@ static inline u8 PWM_TO_REG(int val, int inv) | |||
186 | 188 | ||
187 | struct pc87360_data { | 189 | struct pc87360_data { |
188 | struct i2c_client client; | 190 | struct i2c_client client; |
191 | struct class_device *class_dev; | ||
189 | struct semaphore lock; | 192 | struct semaphore lock; |
190 | struct semaphore update_lock; | 193 | struct semaphore update_lock; |
191 | char valid; /* !=0 if following fields are valid */ | 194 | char valid; /* !=0 if following fields are valid */ |
@@ -838,6 +841,12 @@ int pc87360_detect(struct i2c_adapter *adapter, int address, int kind) | |||
838 | } | 841 | } |
839 | 842 | ||
840 | /* Register sysfs hooks */ | 843 | /* Register sysfs hooks */ |
844 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
845 | if (IS_ERR(data->class_dev)) { | ||
846 | err = PTR_ERR(data->class_dev); | ||
847 | goto ERROR3; | ||
848 | } | ||
849 | |||
841 | if (data->innr) { | 850 | if (data->innr) { |
842 | device_create_file(&new_client->dev, &dev_attr_in0_input); | 851 | device_create_file(&new_client->dev, &dev_attr_in0_input); |
843 | device_create_file(&new_client->dev, &dev_attr_in1_input); | 852 | device_create_file(&new_client->dev, &dev_attr_in1_input); |
@@ -974,6 +983,8 @@ int pc87360_detect(struct i2c_adapter *adapter, int address, int kind) | |||
974 | 983 | ||
975 | return 0; | 984 | return 0; |
976 | 985 | ||
986 | ERROR3: | ||
987 | i2c_detach_client(new_client); | ||
977 | ERROR2: | 988 | ERROR2: |
978 | for (i = 0; i < 3; i++) { | 989 | for (i = 0; i < 3; i++) { |
979 | if (data->address[i]) { | 990 | if (data->address[i]) { |
@@ -990,6 +1001,8 @@ static int pc87360_detach_client(struct i2c_client *client) | |||
990 | struct pc87360_data *data = i2c_get_clientdata(client); | 1001 | struct pc87360_data *data = i2c_get_clientdata(client); |
991 | int i; | 1002 | int i; |
992 | 1003 | ||
1004 | hwmon_device_unregister(data->class_dev); | ||
1005 | |||
993 | if ((i = i2c_detach_client(client))) { | 1006 | if ((i = i2c_detach_client(client))) { |
994 | dev_err(&client->dev, "Client deregistration failed, " | 1007 | dev_err(&client->dev, "Client deregistration failed, " |
995 | "client not detached.\n"); | 1008 | "client not detached.\n"); |
diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c index 6bbfc8fb4f13..ea5934f89f05 100644 --- a/drivers/hwmon/sis5595.c +++ b/drivers/hwmon/sis5595.c | |||
@@ -56,6 +56,8 @@ | |||
56 | #include <linux/pci.h> | 56 | #include <linux/pci.h> |
57 | #include <linux/i2c.h> | 57 | #include <linux/i2c.h> |
58 | #include <linux/i2c-sensor.h> | 58 | #include <linux/i2c-sensor.h> |
59 | #include <linux/hwmon.h> | ||
60 | #include <linux/err.h> | ||
59 | #include <linux/init.h> | 61 | #include <linux/init.h> |
60 | #include <linux/jiffies.h> | 62 | #include <linux/jiffies.h> |
61 | #include <asm/io.h> | 63 | #include <asm/io.h> |
@@ -168,6 +170,7 @@ static inline u8 DIV_TO_REG(int val) | |||
168 | allocated. */ | 170 | allocated. */ |
169 | struct sis5595_data { | 171 | struct sis5595_data { |
170 | struct i2c_client client; | 172 | struct i2c_client client; |
173 | struct class_device *class_dev; | ||
171 | struct semaphore lock; | 174 | struct semaphore lock; |
172 | 175 | ||
173 | struct semaphore update_lock; | 176 | struct semaphore update_lock; |
@@ -578,6 +581,12 @@ int sis5595_detect(struct i2c_adapter *adapter, int address, int kind) | |||
578 | } | 581 | } |
579 | 582 | ||
580 | /* Register sysfs hooks */ | 583 | /* Register sysfs hooks */ |
584 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
585 | if (IS_ERR(data->class_dev)) { | ||
586 | err = PTR_ERR(data->class_dev); | ||
587 | goto exit_detach; | ||
588 | } | ||
589 | |||
581 | device_create_file(&new_client->dev, &dev_attr_in0_input); | 590 | device_create_file(&new_client->dev, &dev_attr_in0_input); |
582 | device_create_file(&new_client->dev, &dev_attr_in0_min); | 591 | device_create_file(&new_client->dev, &dev_attr_in0_min); |
583 | device_create_file(&new_client->dev, &dev_attr_in0_max); | 592 | device_create_file(&new_client->dev, &dev_attr_in0_max); |
@@ -608,7 +617,9 @@ int sis5595_detect(struct i2c_adapter *adapter, int address, int kind) | |||
608 | device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst); | 617 | device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst); |
609 | } | 618 | } |
610 | return 0; | 619 | return 0; |
611 | 620 | ||
621 | exit_detach: | ||
622 | i2c_detach_client(new_client); | ||
612 | exit_free: | 623 | exit_free: |
613 | kfree(data); | 624 | kfree(data); |
614 | exit_release: | 625 | exit_release: |
@@ -619,8 +630,11 @@ exit: | |||
619 | 630 | ||
620 | static int sis5595_detach_client(struct i2c_client *client) | 631 | static int sis5595_detach_client(struct i2c_client *client) |
621 | { | 632 | { |
633 | struct sis5595_data *data = i2c_get_clientdata(client); | ||
622 | int err; | 634 | int err; |
623 | 635 | ||
636 | hwmon_device_unregister(data->class_dev); | ||
637 | |||
624 | if ((err = i2c_detach_client(client))) { | 638 | if ((err = i2c_detach_client(client))) { |
625 | dev_err(&client->dev, | 639 | dev_err(&client->dev, |
626 | "Client deregistration failed, client not detached.\n"); | 640 | "Client deregistration failed, client not detached.\n"); |
@@ -630,7 +644,7 @@ static int sis5595_detach_client(struct i2c_client *client) | |||
630 | if (i2c_is_isa_client(client)) | 644 | if (i2c_is_isa_client(client)) |
631 | release_region(client->addr, SIS5595_EXTENT); | 645 | release_region(client->addr, SIS5595_EXTENT); |
632 | 646 | ||
633 | kfree(i2c_get_clientdata(client)); | 647 | kfree(data); |
634 | 648 | ||
635 | return 0; | 649 | return 0; |
636 | } | 650 | } |
diff --git a/drivers/hwmon/smsc47b397.c b/drivers/hwmon/smsc47b397.c index fdeeb3ab6f2f..96b9eb40f425 100644 --- a/drivers/hwmon/smsc47b397.c +++ b/drivers/hwmon/smsc47b397.c | |||
@@ -32,6 +32,8 @@ | |||
32 | #include <linux/jiffies.h> | 32 | #include <linux/jiffies.h> |
33 | #include <linux/i2c.h> | 33 | #include <linux/i2c.h> |
34 | #include <linux/i2c-sensor.h> | 34 | #include <linux/i2c-sensor.h> |
35 | #include <linux/hwmon.h> | ||
36 | #include <linux/err.h> | ||
35 | #include <linux/init.h> | 37 | #include <linux/init.h> |
36 | #include <asm/io.h> | 38 | #include <asm/io.h> |
37 | 39 | ||
@@ -100,6 +102,7 @@ static u8 smsc47b397_reg_temp[] = {0x25, 0x26, 0x27, 0x80}; | |||
100 | 102 | ||
101 | struct smsc47b397_data { | 103 | struct smsc47b397_data { |
102 | struct i2c_client client; | 104 | struct i2c_client client; |
105 | struct class_device *class_dev; | ||
103 | struct semaphore lock; | 106 | struct semaphore lock; |
104 | 107 | ||
105 | struct semaphore update_lock; | 108 | struct semaphore update_lock; |
@@ -226,8 +229,11 @@ static int smsc47b397_attach_adapter(struct i2c_adapter *adapter) | |||
226 | 229 | ||
227 | static int smsc47b397_detach_client(struct i2c_client *client) | 230 | static int smsc47b397_detach_client(struct i2c_client *client) |
228 | { | 231 | { |
232 | struct smsc47b397_data *data = i2c_get_clientdata(client); | ||
229 | int err; | 233 | int err; |
230 | 234 | ||
235 | hwmon_device_unregister(data->class_dev); | ||
236 | |||
231 | if ((err = i2c_detach_client(client))) { | 237 | if ((err = i2c_detach_client(client))) { |
232 | dev_err(&client->dev, "Client deregistration failed, " | 238 | dev_err(&client->dev, "Client deregistration failed, " |
233 | "client not detached.\n"); | 239 | "client not detached.\n"); |
@@ -235,7 +241,7 @@ static int smsc47b397_detach_client(struct i2c_client *client) | |||
235 | } | 241 | } |
236 | 242 | ||
237 | release_region(client->addr, SMSC_EXTENT); | 243 | release_region(client->addr, SMSC_EXTENT); |
238 | kfree(i2c_get_clientdata(client)); | 244 | kfree(data); |
239 | 245 | ||
240 | return 0; | 246 | return 0; |
241 | } | 247 | } |
@@ -285,6 +291,12 @@ static int smsc47b397_detect(struct i2c_adapter *adapter, int addr, int kind) | |||
285 | if ((err = i2c_attach_client(new_client))) | 291 | if ((err = i2c_attach_client(new_client))) |
286 | goto error_free; | 292 | goto error_free; |
287 | 293 | ||
294 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
295 | if (IS_ERR(data->class_dev)) { | ||
296 | err = PTR_ERR(data->class_dev); | ||
297 | goto error_detach; | ||
298 | } | ||
299 | |||
288 | device_create_file_temp(new_client, 1); | 300 | device_create_file_temp(new_client, 1); |
289 | device_create_file_temp(new_client, 2); | 301 | device_create_file_temp(new_client, 2); |
290 | device_create_file_temp(new_client, 3); | 302 | device_create_file_temp(new_client, 3); |
@@ -297,6 +309,8 @@ static int smsc47b397_detect(struct i2c_adapter *adapter, int addr, int kind) | |||
297 | 309 | ||
298 | return 0; | 310 | return 0; |
299 | 311 | ||
312 | error_detach: | ||
313 | i2c_detach_client(new_client); | ||
300 | error_free: | 314 | error_free: |
301 | kfree(data); | 315 | kfree(data); |
302 | error_release: | 316 | error_release: |
diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c index 7166ad0b2fda..de7c7f804d66 100644 --- a/drivers/hwmon/smsc47m1.c +++ b/drivers/hwmon/smsc47m1.c | |||
@@ -31,6 +31,8 @@ | |||
31 | #include <linux/jiffies.h> | 31 | #include <linux/jiffies.h> |
32 | #include <linux/i2c.h> | 32 | #include <linux/i2c.h> |
33 | #include <linux/i2c-sensor.h> | 33 | #include <linux/i2c-sensor.h> |
34 | #include <linux/hwmon.h> | ||
35 | #include <linux/err.h> | ||
34 | #include <linux/init.h> | 36 | #include <linux/init.h> |
35 | #include <asm/io.h> | 37 | #include <asm/io.h> |
36 | 38 | ||
@@ -108,6 +110,7 @@ superio_exit(void) | |||
108 | 110 | ||
109 | struct smsc47m1_data { | 111 | struct smsc47m1_data { |
110 | struct i2c_client client; | 112 | struct i2c_client client; |
113 | struct class_device *class_dev; | ||
111 | struct semaphore lock; | 114 | struct semaphore lock; |
112 | 115 | ||
113 | struct semaphore update_lock; | 116 | struct semaphore update_lock; |
@@ -461,6 +464,13 @@ static int smsc47m1_detect(struct i2c_adapter *adapter, int address, int kind) | |||
461 | function. */ | 464 | function. */ |
462 | smsc47m1_update_device(&new_client->dev, 1); | 465 | smsc47m1_update_device(&new_client->dev, 1); |
463 | 466 | ||
467 | /* Register sysfs hooks */ | ||
468 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
469 | if (IS_ERR(data->class_dev)) { | ||
470 | err = PTR_ERR(data->class_dev); | ||
471 | goto error_detach; | ||
472 | } | ||
473 | |||
464 | if (fan1) { | 474 | if (fan1) { |
465 | device_create_file(&new_client->dev, &dev_attr_fan1_input); | 475 | device_create_file(&new_client->dev, &dev_attr_fan1_input); |
466 | device_create_file(&new_client->dev, &dev_attr_fan1_min); | 476 | device_create_file(&new_client->dev, &dev_attr_fan1_min); |
@@ -494,6 +504,8 @@ static int smsc47m1_detect(struct i2c_adapter *adapter, int address, int kind) | |||
494 | 504 | ||
495 | return 0; | 505 | return 0; |
496 | 506 | ||
507 | error_detach: | ||
508 | i2c_detach_client(new_client); | ||
497 | error_free: | 509 | error_free: |
498 | kfree(data); | 510 | kfree(data); |
499 | error_release: | 511 | error_release: |
@@ -503,8 +515,11 @@ error_release: | |||
503 | 515 | ||
504 | static int smsc47m1_detach_client(struct i2c_client *client) | 516 | static int smsc47m1_detach_client(struct i2c_client *client) |
505 | { | 517 | { |
518 | struct smsc47m1_data *data = i2c_get_clientdata(client); | ||
506 | int err; | 519 | int err; |
507 | 520 | ||
521 | hwmon_device_unregister(data->class_dev); | ||
522 | |||
508 | if ((err = i2c_detach_client(client))) { | 523 | if ((err = i2c_detach_client(client))) { |
509 | dev_err(&client->dev, "Client deregistration failed, " | 524 | dev_err(&client->dev, "Client deregistration failed, " |
510 | "client not detached.\n"); | 525 | "client not detached.\n"); |
@@ -512,7 +527,7 @@ static int smsc47m1_detach_client(struct i2c_client *client) | |||
512 | } | 527 | } |
513 | 528 | ||
514 | release_region(client->addr, SMSC_EXTENT); | 529 | release_region(client->addr, SMSC_EXTENT); |
515 | kfree(i2c_get_clientdata(client)); | 530 | kfree(data); |
516 | 531 | ||
517 | return 0; | 532 | return 0; |
518 | } | 533 | } |
diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c index 164d47948390..8eb9d084149d 100644 --- a/drivers/hwmon/via686a.c +++ b/drivers/hwmon/via686a.c | |||
@@ -36,6 +36,8 @@ | |||
36 | #include <linux/jiffies.h> | 36 | #include <linux/jiffies.h> |
37 | #include <linux/i2c.h> | 37 | #include <linux/i2c.h> |
38 | #include <linux/i2c-sensor.h> | 38 | #include <linux/i2c-sensor.h> |
39 | #include <linux/hwmon.h> | ||
40 | #include <linux/err.h> | ||
39 | #include <linux/init.h> | 41 | #include <linux/init.h> |
40 | #include <asm/io.h> | 42 | #include <asm/io.h> |
41 | 43 | ||
@@ -297,6 +299,7 @@ static inline long TEMP_FROM_REG10(u16 val) | |||
297 | via686a client is allocated. */ | 299 | via686a client is allocated. */ |
298 | struct via686a_data { | 300 | struct via686a_data { |
299 | struct i2c_client client; | 301 | struct i2c_client client; |
302 | struct class_device *class_dev; | ||
300 | struct semaphore update_lock; | 303 | struct semaphore update_lock; |
301 | char valid; /* !=0 if following fields are valid */ | 304 | char valid; /* !=0 if following fields are valid */ |
302 | unsigned long last_updated; /* In jiffies */ | 305 | unsigned long last_updated; /* In jiffies */ |
@@ -637,7 +640,7 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) | |||
637 | 640 | ||
638 | if (!(data = kmalloc(sizeof(struct via686a_data), GFP_KERNEL))) { | 641 | if (!(data = kmalloc(sizeof(struct via686a_data), GFP_KERNEL))) { |
639 | err = -ENOMEM; | 642 | err = -ENOMEM; |
640 | goto ERROR0; | 643 | goto exit_release; |
641 | } | 644 | } |
642 | memset(data, 0, sizeof(struct via686a_data)); | 645 | memset(data, 0, sizeof(struct via686a_data)); |
643 | 646 | ||
@@ -655,12 +658,18 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) | |||
655 | init_MUTEX(&data->update_lock); | 658 | init_MUTEX(&data->update_lock); |
656 | /* Tell the I2C layer a new client has arrived */ | 659 | /* Tell the I2C layer a new client has arrived */ |
657 | if ((err = i2c_attach_client(new_client))) | 660 | if ((err = i2c_attach_client(new_client))) |
658 | goto ERROR3; | 661 | goto exit_free; |
659 | 662 | ||
660 | /* Initialize the VIA686A chip */ | 663 | /* Initialize the VIA686A chip */ |
661 | via686a_init_client(new_client); | 664 | via686a_init_client(new_client); |
662 | 665 | ||
663 | /* Register sysfs hooks */ | 666 | /* Register sysfs hooks */ |
667 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
668 | if (IS_ERR(data->class_dev)) { | ||
669 | err = PTR_ERR(data->class_dev); | ||
670 | goto exit_detach; | ||
671 | } | ||
672 | |||
664 | device_create_file(&new_client->dev, &dev_attr_in0_input); | 673 | device_create_file(&new_client->dev, &dev_attr_in0_input); |
665 | device_create_file(&new_client->dev, &dev_attr_in1_input); | 674 | device_create_file(&new_client->dev, &dev_attr_in1_input); |
666 | device_create_file(&new_client->dev, &dev_attr_in2_input); | 675 | device_create_file(&new_client->dev, &dev_attr_in2_input); |
@@ -695,17 +704,22 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) | |||
695 | 704 | ||
696 | return 0; | 705 | return 0; |
697 | 706 | ||
698 | ERROR3: | 707 | exit_detach: |
708 | i2c_detach_client(new_client); | ||
709 | exit_free: | ||
699 | kfree(data); | 710 | kfree(data); |
700 | ERROR0: | 711 | exit_release: |
701 | release_region(address, VIA686A_EXTENT); | 712 | release_region(address, VIA686A_EXTENT); |
702 | return err; | 713 | return err; |
703 | } | 714 | } |
704 | 715 | ||
705 | static int via686a_detach_client(struct i2c_client *client) | 716 | static int via686a_detach_client(struct i2c_client *client) |
706 | { | 717 | { |
718 | struct via686a_data *data = i2c_get_clientdata(client); | ||
707 | int err; | 719 | int err; |
708 | 720 | ||
721 | hwmon_device_unregister(data->class_dev); | ||
722 | |||
709 | if ((err = i2c_detach_client(client))) { | 723 | if ((err = i2c_detach_client(client))) { |
710 | dev_err(&client->dev, | 724 | dev_err(&client->dev, |
711 | "Client deregistration failed, client not detached.\n"); | 725 | "Client deregistration failed, client not detached.\n"); |
@@ -713,7 +727,7 @@ static int via686a_detach_client(struct i2c_client *client) | |||
713 | } | 727 | } |
714 | 728 | ||
715 | release_region(client->addr, VIA686A_EXTENT); | 729 | release_region(client->addr, VIA686A_EXTENT); |
716 | kfree(i2c_get_clientdata(client)); | 730 | kfree(data); |
717 | 731 | ||
718 | return 0; | 732 | return 0; |
719 | } | 733 | } |
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c index 250f6b059a54..956e7f830aa6 100644 --- a/drivers/hwmon/w83627ehf.c +++ b/drivers/hwmon/w83627ehf.c | |||
@@ -41,6 +41,8 @@ | |||
41 | #include <linux/slab.h> | 41 | #include <linux/slab.h> |
42 | #include <linux/i2c.h> | 42 | #include <linux/i2c.h> |
43 | #include <linux/i2c-sensor.h> | 43 | #include <linux/i2c-sensor.h> |
44 | #include <linux/hwmon.h> | ||
45 | #include <linux/err.h> | ||
44 | #include <asm/io.h> | 46 | #include <asm/io.h> |
45 | #include "lm75.h" | 47 | #include "lm75.h" |
46 | 48 | ||
@@ -177,6 +179,7 @@ temp1_to_reg(int temp) | |||
177 | 179 | ||
178 | struct w83627ehf_data { | 180 | struct w83627ehf_data { |
179 | struct i2c_client client; | 181 | struct i2c_client client; |
182 | struct class_device *class_dev; | ||
180 | struct semaphore lock; | 183 | struct semaphore lock; |
181 | 184 | ||
182 | struct semaphore update_lock; | 185 | struct semaphore update_lock; |
@@ -723,6 +726,12 @@ static int w83627ehf_detect(struct i2c_adapter *adapter, int address, int kind) | |||
723 | data->has_fan |= (1 << 4); | 726 | data->has_fan |= (1 << 4); |
724 | 727 | ||
725 | /* Register sysfs hooks */ | 728 | /* Register sysfs hooks */ |
729 | data->class_dev = hwmon_device_register(&client->dev); | ||
730 | if (IS_ERR(data->class_dev)) { | ||
731 | err = PTR_ERR(data->class_dev); | ||
732 | goto exit_detach; | ||
733 | } | ||
734 | |||
726 | device_create_file(&client->dev, &dev_attr_fan1_input); | 735 | device_create_file(&client->dev, &dev_attr_fan1_input); |
727 | device_create_file(&client->dev, &dev_attr_fan1_min); | 736 | device_create_file(&client->dev, &dev_attr_fan1_min); |
728 | device_create_file(&client->dev, &dev_attr_fan1_div); | 737 | device_create_file(&client->dev, &dev_attr_fan1_div); |
@@ -756,6 +765,8 @@ static int w83627ehf_detect(struct i2c_adapter *adapter, int address, int kind) | |||
756 | 765 | ||
757 | return 0; | 766 | return 0; |
758 | 767 | ||
768 | exit_detach: | ||
769 | i2c_detach_client(client); | ||
759 | exit_free: | 770 | exit_free: |
760 | kfree(data); | 771 | kfree(data); |
761 | exit_release: | 772 | exit_release: |
@@ -773,15 +784,18 @@ static int w83627ehf_attach_adapter(struct i2c_adapter *adapter) | |||
773 | 784 | ||
774 | static int w83627ehf_detach_client(struct i2c_client *client) | 785 | static int w83627ehf_detach_client(struct i2c_client *client) |
775 | { | 786 | { |
787 | struct w83627ehf_data *data = i2c_get_clientdata(client); | ||
776 | int err; | 788 | int err; |
777 | 789 | ||
790 | hwmon_device_unregister(data->class_dev); | ||
791 | |||
778 | if ((err = i2c_detach_client(client))) { | 792 | if ((err = i2c_detach_client(client))) { |
779 | dev_err(&client->dev, "Client deregistration failed, " | 793 | dev_err(&client->dev, "Client deregistration failed, " |
780 | "client not detached.\n"); | 794 | "client not detached.\n"); |
781 | return err; | 795 | return err; |
782 | } | 796 | } |
783 | release_region(client->addr, REGION_LENGTH); | 797 | release_region(client->addr, REGION_LENGTH); |
784 | kfree(i2c_get_clientdata(client)); | 798 | kfree(data); |
785 | 799 | ||
786 | return 0; | 800 | return 0; |
787 | } | 801 | } |
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c index bd87a42e068a..da2f4992ee21 100644 --- a/drivers/hwmon/w83627hf.c +++ b/drivers/hwmon/w83627hf.c | |||
@@ -44,6 +44,8 @@ | |||
44 | #include <linux/i2c.h> | 44 | #include <linux/i2c.h> |
45 | #include <linux/i2c-sensor.h> | 45 | #include <linux/i2c-sensor.h> |
46 | #include <linux/i2c-vid.h> | 46 | #include <linux/i2c-vid.h> |
47 | #include <linux/hwmon.h> | ||
48 | #include <linux/err.h> | ||
47 | #include <asm/io.h> | 49 | #include <asm/io.h> |
48 | #include "lm75.h" | 50 | #include "lm75.h" |
49 | 51 | ||
@@ -277,6 +279,7 @@ static inline u8 DIV_TO_REG(long val) | |||
277 | dynamically allocated, at the same time when a new client is allocated. */ | 279 | dynamically allocated, at the same time when a new client is allocated. */ |
278 | struct w83627hf_data { | 280 | struct w83627hf_data { |
279 | struct i2c_client client; | 281 | struct i2c_client client; |
282 | struct class_device *class_dev; | ||
280 | struct semaphore lock; | 283 | struct semaphore lock; |
281 | enum chips type; | 284 | enum chips type; |
282 | 285 | ||
@@ -1102,6 +1105,12 @@ int w83627hf_detect(struct i2c_adapter *adapter, int address, | |||
1102 | data->fan_min[2] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(3)); | 1105 | data->fan_min[2] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(3)); |
1103 | 1106 | ||
1104 | /* Register sysfs hooks */ | 1107 | /* Register sysfs hooks */ |
1108 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
1109 | if (IS_ERR(data->class_dev)) { | ||
1110 | err = PTR_ERR(data->class_dev); | ||
1111 | goto ERROR3; | ||
1112 | } | ||
1113 | |||
1105 | device_create_file_in(new_client, 0); | 1114 | device_create_file_in(new_client, 0); |
1106 | if (kind != w83697hf) | 1115 | if (kind != w83697hf) |
1107 | device_create_file_in(new_client, 1); | 1116 | device_create_file_in(new_client, 1); |
@@ -1152,6 +1161,8 @@ int w83627hf_detect(struct i2c_adapter *adapter, int address, | |||
1152 | 1161 | ||
1153 | return 0; | 1162 | return 0; |
1154 | 1163 | ||
1164 | ERROR3: | ||
1165 | i2c_detach_client(new_client); | ||
1155 | ERROR2: | 1166 | ERROR2: |
1156 | kfree(data); | 1167 | kfree(data); |
1157 | ERROR1: | 1168 | ERROR1: |
@@ -1162,8 +1173,11 @@ int w83627hf_detect(struct i2c_adapter *adapter, int address, | |||
1162 | 1173 | ||
1163 | static int w83627hf_detach_client(struct i2c_client *client) | 1174 | static int w83627hf_detach_client(struct i2c_client *client) |
1164 | { | 1175 | { |
1176 | struct w83627hf_data *data = i2c_get_clientdata(client); | ||
1165 | int err; | 1177 | int err; |
1166 | 1178 | ||
1179 | hwmon_device_unregister(data->class_dev); | ||
1180 | |||
1167 | if ((err = i2c_detach_client(client))) { | 1181 | if ((err = i2c_detach_client(client))) { |
1168 | dev_err(&client->dev, | 1182 | dev_err(&client->dev, |
1169 | "Client deregistration failed, client not detached.\n"); | 1183 | "Client deregistration failed, client not detached.\n"); |
@@ -1171,7 +1185,7 @@ static int w83627hf_detach_client(struct i2c_client *client) | |||
1171 | } | 1185 | } |
1172 | 1186 | ||
1173 | release_region(client->addr, WINB_EXTENT); | 1187 | release_region(client->addr, WINB_EXTENT); |
1174 | kfree(i2c_get_clientdata(client)); | 1188 | kfree(data); |
1175 | 1189 | ||
1176 | return 0; | 1190 | return 0; |
1177 | } | 1191 | } |
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c index 0bb131ce09eb..c83ae769e362 100644 --- a/drivers/hwmon/w83781d.c +++ b/drivers/hwmon/w83781d.c | |||
@@ -40,6 +40,8 @@ | |||
40 | #include <linux/i2c.h> | 40 | #include <linux/i2c.h> |
41 | #include <linux/i2c-sensor.h> | 41 | #include <linux/i2c-sensor.h> |
42 | #include <linux/i2c-vid.h> | 42 | #include <linux/i2c-vid.h> |
43 | #include <linux/hwmon.h> | ||
44 | #include <linux/err.h> | ||
43 | #include <asm/io.h> | 45 | #include <asm/io.h> |
44 | #include "lm75.h" | 46 | #include "lm75.h" |
45 | 47 | ||
@@ -218,6 +220,7 @@ DIV_TO_REG(long val, enum chips type) | |||
218 | allocated. */ | 220 | allocated. */ |
219 | struct w83781d_data { | 221 | struct w83781d_data { |
220 | struct i2c_client client; | 222 | struct i2c_client client; |
223 | struct class_device *class_dev; | ||
221 | struct semaphore lock; | 224 | struct semaphore lock; |
222 | enum chips type; | 225 | enum chips type; |
223 | 226 | ||
@@ -961,10 +964,10 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind, | |||
961 | ERROR_SC_3: | 964 | ERROR_SC_3: |
962 | i2c_detach_client(data->lm75[0]); | 965 | i2c_detach_client(data->lm75[0]); |
963 | ERROR_SC_2: | 966 | ERROR_SC_2: |
964 | if (NULL != data->lm75[1]) | 967 | if (data->lm75[1]) |
965 | kfree(data->lm75[1]); | 968 | kfree(data->lm75[1]); |
966 | ERROR_SC_1: | 969 | ERROR_SC_1: |
967 | if (NULL != data->lm75[0]) | 970 | if (data->lm75[0]) |
968 | kfree(data->lm75[0]); | 971 | kfree(data->lm75[0]); |
969 | ERROR_SC_0: | 972 | ERROR_SC_0: |
970 | return err; | 973 | return err; |
@@ -1189,6 +1192,12 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1189 | data->pwmenable[i] = 1; | 1192 | data->pwmenable[i] = 1; |
1190 | 1193 | ||
1191 | /* Register sysfs hooks */ | 1194 | /* Register sysfs hooks */ |
1195 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
1196 | if (IS_ERR(data->class_dev)) { | ||
1197 | err = PTR_ERR(data->class_dev); | ||
1198 | goto ERROR4; | ||
1199 | } | ||
1200 | |||
1192 | device_create_file_in(new_client, 0); | 1201 | device_create_file_in(new_client, 0); |
1193 | if (kind != w83783s) | 1202 | if (kind != w83783s) |
1194 | device_create_file_in(new_client, 1); | 1203 | device_create_file_in(new_client, 1); |
@@ -1241,6 +1250,15 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1241 | 1250 | ||
1242 | return 0; | 1251 | return 0; |
1243 | 1252 | ||
1253 | ERROR4: | ||
1254 | if (data->lm75[1]) { | ||
1255 | i2c_detach_client(data->lm75[1]); | ||
1256 | kfree(data->lm75[1]); | ||
1257 | } | ||
1258 | if (data->lm75[0]) { | ||
1259 | i2c_detach_client(data->lm75[0]); | ||
1260 | kfree(data->lm75[0]); | ||
1261 | } | ||
1244 | ERROR3: | 1262 | ERROR3: |
1245 | i2c_detach_client(new_client); | 1263 | i2c_detach_client(new_client); |
1246 | ERROR2: | 1264 | ERROR2: |
@@ -1255,8 +1273,13 @@ ERROR0: | |||
1255 | static int | 1273 | static int |
1256 | w83781d_detach_client(struct i2c_client *client) | 1274 | w83781d_detach_client(struct i2c_client *client) |
1257 | { | 1275 | { |
1276 | struct w83781d_data *data = i2c_get_clientdata(client); | ||
1258 | int err; | 1277 | int err; |
1259 | 1278 | ||
1279 | /* main client */ | ||
1280 | if (data) | ||
1281 | hwmon_device_unregister(data->class_dev); | ||
1282 | |||
1260 | if (i2c_is_isa_client(client)) | 1283 | if (i2c_is_isa_client(client)) |
1261 | release_region(client->addr, W83781D_EXTENT); | 1284 | release_region(client->addr, W83781D_EXTENT); |
1262 | 1285 | ||
@@ -1266,13 +1289,13 @@ w83781d_detach_client(struct i2c_client *client) | |||
1266 | return err; | 1289 | return err; |
1267 | } | 1290 | } |
1268 | 1291 | ||
1269 | if (i2c_get_clientdata(client)==NULL) { | 1292 | /* main client */ |
1270 | /* subclients */ | 1293 | if (data) |
1294 | kfree(data); | ||
1295 | |||
1296 | /* subclient */ | ||
1297 | else | ||
1271 | kfree(client); | 1298 | kfree(client); |
1272 | } else { | ||
1273 | /* main client */ | ||
1274 | kfree(i2c_get_clientdata(client)); | ||
1275 | } | ||
1276 | 1299 | ||
1277 | return 0; | 1300 | return 0; |
1278 | } | 1301 | } |
diff --git a/drivers/hwmon/w83l785ts.c b/drivers/hwmon/w83l785ts.c index 4469d52aba4c..1f763499dac4 100644 --- a/drivers/hwmon/w83l785ts.c +++ b/drivers/hwmon/w83l785ts.c | |||
@@ -37,6 +37,8 @@ | |||
37 | #include <linux/jiffies.h> | 37 | #include <linux/jiffies.h> |
38 | #include <linux/i2c.h> | 38 | #include <linux/i2c.h> |
39 | #include <linux/i2c-sensor.h> | 39 | #include <linux/i2c-sensor.h> |
40 | #include <linux/hwmon.h> | ||
41 | #include <linux/err.h> | ||
40 | 42 | ||
41 | /* How many retries on register read error */ | 43 | /* How many retries on register read error */ |
42 | #define MAX_RETRIES 5 | 44 | #define MAX_RETRIES 5 |
@@ -105,6 +107,7 @@ static struct i2c_driver w83l785ts_driver = { | |||
105 | 107 | ||
106 | struct w83l785ts_data { | 108 | struct w83l785ts_data { |
107 | struct i2c_client client; | 109 | struct i2c_client client; |
110 | struct class_device *class_dev; | ||
108 | struct semaphore update_lock; | 111 | struct semaphore update_lock; |
109 | char valid; /* zero until following fields are valid */ | 112 | char valid; /* zero until following fields are valid */ |
110 | unsigned long last_updated; /* in jiffies */ | 113 | unsigned long last_updated; /* in jiffies */ |
@@ -239,11 +242,19 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind) | |||
239 | */ | 242 | */ |
240 | 243 | ||
241 | /* Register sysfs hooks */ | 244 | /* Register sysfs hooks */ |
245 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
246 | if (IS_ERR(data->class_dev)) { | ||
247 | err = PTR_ERR(data->class_dev); | ||
248 | goto exit_detach; | ||
249 | } | ||
250 | |||
242 | device_create_file(&new_client->dev, &dev_attr_temp1_input); | 251 | device_create_file(&new_client->dev, &dev_attr_temp1_input); |
243 | device_create_file(&new_client->dev, &dev_attr_temp1_max); | 252 | device_create_file(&new_client->dev, &dev_attr_temp1_max); |
244 | 253 | ||
245 | return 0; | 254 | return 0; |
246 | 255 | ||
256 | exit_detach: | ||
257 | i2c_detach_client(new_client); | ||
247 | exit_free: | 258 | exit_free: |
248 | kfree(data); | 259 | kfree(data); |
249 | exit: | 260 | exit: |
@@ -252,15 +263,18 @@ exit: | |||
252 | 263 | ||
253 | static int w83l785ts_detach_client(struct i2c_client *client) | 264 | static int w83l785ts_detach_client(struct i2c_client *client) |
254 | { | 265 | { |
266 | struct w83l785ts_data *data = i2c_get_clientdata(client); | ||
255 | int err; | 267 | int err; |
256 | 268 | ||
269 | hwmon_device_unregister(data->class_dev); | ||
270 | |||
257 | if ((err = i2c_detach_client(client))) { | 271 | if ((err = i2c_detach_client(client))) { |
258 | dev_err(&client->dev, "Client deregistration failed, " | 272 | dev_err(&client->dev, "Client deregistration failed, " |
259 | "client not detached.\n"); | 273 | "client not detached.\n"); |
260 | return err; | 274 | return err; |
261 | } | 275 | } |
262 | 276 | ||
263 | kfree(i2c_get_clientdata(client)); | 277 | kfree(data); |
264 | return 0; | 278 | return 0; |
265 | } | 279 | } |
266 | 280 | ||