diff options
author | Jean Delvare <khali@linux-fr.org> | 2006-09-24 15:16:40 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-09-28 18:31:18 -0400 |
commit | 0e39e01c908fdc498fff0d788fd7b955ab75ebb6 (patch) | |
tree | 2e117466ec9a60f3dac6d678e95af97454aa6c8c /drivers/hwmon/lm83.c | |
parent | 681c6f7a6702f208d48b501c8829dbc03a2ca238 (diff) |
hwmon: Fix unchecked return status, batch 4
hwmon: Fix unchecked return status, batch 4
Fix up some hwmon drivers so that they no longer ignore return status
from device_create_file().
Note: f71805f actually checked the status from device_create_file
already. However it did not remove the files on device destruction.
It was also an opportunity to use sysfs_create/remove_group instead
of hand-made loops. This makes the changes much more important but
I think the result is worth it.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/hwmon/lm83.c')
-rw-r--r-- | drivers/hwmon/lm83.c | 125 |
1 files changed, 60 insertions, 65 deletions
diff --git a/drivers/hwmon/lm83.c b/drivers/hwmon/lm83.c index ea224891d311..feb87b41e986 100644 --- a/drivers/hwmon/lm83.c +++ b/drivers/hwmon/lm83.c | |||
@@ -40,6 +40,7 @@ | |||
40 | #include <linux/hwmon.h> | 40 | #include <linux/hwmon.h> |
41 | #include <linux/err.h> | 41 | #include <linux/err.h> |
42 | #include <linux/mutex.h> | 42 | #include <linux/mutex.h> |
43 | #include <linux/sysfs.h> | ||
43 | 44 | ||
44 | /* | 45 | /* |
45 | * Addresses to scan | 46 | * Addresses to scan |
@@ -234,6 +235,48 @@ static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 15); | |||
234 | /* Raw alarm file for compatibility */ | 235 | /* Raw alarm file for compatibility */ |
235 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | 236 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
236 | 237 | ||
238 | static struct attribute *lm83_attributes[] = { | ||
239 | &sensor_dev_attr_temp1_input.dev_attr.attr, | ||
240 | &sensor_dev_attr_temp3_input.dev_attr.attr, | ||
241 | &sensor_dev_attr_temp1_max.dev_attr.attr, | ||
242 | &sensor_dev_attr_temp3_max.dev_attr.attr, | ||
243 | &sensor_dev_attr_temp1_crit.dev_attr.attr, | ||
244 | &sensor_dev_attr_temp3_crit.dev_attr.attr, | ||
245 | |||
246 | &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, | ||
247 | &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr, | ||
248 | &sensor_dev_attr_temp3_input_fault.dev_attr.attr, | ||
249 | &sensor_dev_attr_temp3_max_alarm.dev_attr.attr, | ||
250 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, | ||
251 | &dev_attr_alarms.attr, | ||
252 | NULL | ||
253 | }; | ||
254 | |||
255 | static const struct attribute_group lm83_group = { | ||
256 | .attrs = lm83_attributes, | ||
257 | }; | ||
258 | |||
259 | static struct attribute *lm83_attributes_opt[] = { | ||
260 | &sensor_dev_attr_temp2_input.dev_attr.attr, | ||
261 | &sensor_dev_attr_temp4_input.dev_attr.attr, | ||
262 | &sensor_dev_attr_temp2_max.dev_attr.attr, | ||
263 | &sensor_dev_attr_temp4_max.dev_attr.attr, | ||
264 | &sensor_dev_attr_temp2_crit.dev_attr.attr, | ||
265 | &sensor_dev_attr_temp4_crit.dev_attr.attr, | ||
266 | |||
267 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, | ||
268 | &sensor_dev_attr_temp4_crit_alarm.dev_attr.attr, | ||
269 | &sensor_dev_attr_temp4_input_fault.dev_attr.attr, | ||
270 | &sensor_dev_attr_temp4_max_alarm.dev_attr.attr, | ||
271 | &sensor_dev_attr_temp2_input_fault.dev_attr.attr, | ||
272 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, | ||
273 | NULL | ||
274 | }; | ||
275 | |||
276 | static const struct attribute_group lm83_group_opt = { | ||
277 | .attrs = lm83_attributes_opt, | ||
278 | }; | ||
279 | |||
237 | /* | 280 | /* |
238 | * Real code | 281 | * Real code |
239 | */ | 282 | */ |
@@ -342,82 +385,32 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind) | |||
342 | goto exit_free; | 385 | goto exit_free; |
343 | 386 | ||
344 | /* | 387 | /* |
345 | * Initialize the LM83 chip | 388 | * Register sysfs hooks |
346 | * (Nothing to do for this one.) | ||
347 | */ | ||
348 | |||
349 | /* Register sysfs hooks */ | ||
350 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
351 | if (IS_ERR(data->class_dev)) { | ||
352 | err = PTR_ERR(data->class_dev); | ||
353 | goto exit_detach; | ||
354 | } | ||
355 | |||
356 | /* | ||
357 | * The LM82 can only monitor one external diode which is | 389 | * The LM82 can only monitor one external diode which is |
358 | * at the same register as the LM83 temp3 entry - so we | 390 | * at the same register as the LM83 temp3 entry - so we |
359 | * declare 1 and 3 common, and then 2 and 4 only for the LM83. | 391 | * declare 1 and 3 common, and then 2 and 4 only for the LM83. |
360 | */ | 392 | */ |
361 | 393 | ||
362 | device_create_file(&new_client->dev, | 394 | if ((err = sysfs_create_group(&new_client->dev.kobj, &lm83_group))) |
363 | &sensor_dev_attr_temp1_input.dev_attr); | 395 | goto exit_detach; |
364 | device_create_file(&new_client->dev, | ||
365 | &sensor_dev_attr_temp3_input.dev_attr); | ||
366 | |||
367 | device_create_file(&new_client->dev, | ||
368 | &sensor_dev_attr_temp1_max.dev_attr); | ||
369 | device_create_file(&new_client->dev, | ||
370 | &sensor_dev_attr_temp3_max.dev_attr); | ||
371 | |||
372 | device_create_file(&new_client->dev, | ||
373 | &sensor_dev_attr_temp1_crit.dev_attr); | ||
374 | device_create_file(&new_client->dev, | ||
375 | &sensor_dev_attr_temp3_crit.dev_attr); | ||
376 | |||
377 | device_create_file(&new_client->dev, | ||
378 | &sensor_dev_attr_temp3_input_fault.dev_attr); | ||
379 | device_create_file(&new_client->dev, | ||
380 | &sensor_dev_attr_temp1_max_alarm.dev_attr); | ||
381 | device_create_file(&new_client->dev, | ||
382 | &sensor_dev_attr_temp3_max_alarm.dev_attr); | ||
383 | device_create_file(&new_client->dev, | ||
384 | &sensor_dev_attr_temp1_crit_alarm.dev_attr); | ||
385 | device_create_file(&new_client->dev, | ||
386 | &sensor_dev_attr_temp3_crit_alarm.dev_attr); | ||
387 | device_create_file(&new_client->dev, &dev_attr_alarms); | ||
388 | 396 | ||
389 | if (kind == lm83) { | 397 | if (kind == lm83) { |
390 | device_create_file(&new_client->dev, | 398 | if ((err = sysfs_create_group(&new_client->dev.kobj, |
391 | &sensor_dev_attr_temp2_input.dev_attr); | 399 | &lm83_group_opt))) |
392 | device_create_file(&new_client->dev, | 400 | goto exit_remove_files; |
393 | &sensor_dev_attr_temp4_input.dev_attr); | 401 | } |
394 | 402 | ||
395 | device_create_file(&new_client->dev, | 403 | data->class_dev = hwmon_device_register(&new_client->dev); |
396 | &sensor_dev_attr_temp2_max.dev_attr); | 404 | if (IS_ERR(data->class_dev)) { |
397 | device_create_file(&new_client->dev, | 405 | err = PTR_ERR(data->class_dev); |
398 | &sensor_dev_attr_temp4_max.dev_attr); | 406 | goto exit_remove_files; |
399 | |||
400 | device_create_file(&new_client->dev, | ||
401 | &sensor_dev_attr_temp2_crit.dev_attr); | ||
402 | device_create_file(&new_client->dev, | ||
403 | &sensor_dev_attr_temp4_crit.dev_attr); | ||
404 | |||
405 | device_create_file(&new_client->dev, | ||
406 | &sensor_dev_attr_temp2_input_fault.dev_attr); | ||
407 | device_create_file(&new_client->dev, | ||
408 | &sensor_dev_attr_temp4_input_fault.dev_attr); | ||
409 | device_create_file(&new_client->dev, | ||
410 | &sensor_dev_attr_temp2_max_alarm.dev_attr); | ||
411 | device_create_file(&new_client->dev, | ||
412 | &sensor_dev_attr_temp4_max_alarm.dev_attr); | ||
413 | device_create_file(&new_client->dev, | ||
414 | &sensor_dev_attr_temp2_crit_alarm.dev_attr); | ||
415 | device_create_file(&new_client->dev, | ||
416 | &sensor_dev_attr_temp4_crit_alarm.dev_attr); | ||
417 | } | 407 | } |
418 | 408 | ||
419 | return 0; | 409 | return 0; |
420 | 410 | ||
411 | exit_remove_files: | ||
412 | sysfs_remove_group(&new_client->dev.kobj, &lm83_group); | ||
413 | sysfs_remove_group(&new_client->dev.kobj, &lm83_group_opt); | ||
421 | exit_detach: | 414 | exit_detach: |
422 | i2c_detach_client(new_client); | 415 | i2c_detach_client(new_client); |
423 | exit_free: | 416 | exit_free: |
@@ -432,6 +425,8 @@ static int lm83_detach_client(struct i2c_client *client) | |||
432 | int err; | 425 | int err; |
433 | 426 | ||
434 | hwmon_device_unregister(data->class_dev); | 427 | hwmon_device_unregister(data->class_dev); |
428 | sysfs_remove_group(&client->dev.kobj, &lm83_group); | ||
429 | sysfs_remove_group(&client->dev.kobj, &lm83_group_opt); | ||
435 | 430 | ||
436 | if ((err = i2c_detach_client(client))) | 431 | if ((err = i2c_detach_client(client))) |
437 | return err; | 432 | return err; |