aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/lm83.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/lm83.c')
-rw-r--r--drivers/hwmon/lm83.c16
1 files changed, 15 insertions, 1 deletions
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
139struct lm83_data { 141struct 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
352exit_detach:
353 i2c_detach_client(new_client);
343exit_free: 354exit_free:
344 kfree(data); 355 kfree(data);
345exit: 356exit:
@@ -348,15 +359,18 @@ exit:
348 359
349static int lm83_detach_client(struct i2c_client *client) 360static 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