aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/lm87.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/lm87.c')
-rw-r--r--drivers/hwmon/lm87.c16
1 files changed, 15 insertions, 1 deletions
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
176struct lm87_data { 178struct 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
685exit_detach:
686 i2c_detach_client(new_client);
676exit_free: 687exit_free:
677 kfree(data); 688 kfree(data);
678exit: 689exit:
@@ -719,15 +730,18 @@ static void lm87_init_client(struct i2c_client *client)
719 730
720static int lm87_detach_client(struct i2c_client *client) 731static 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