Commit 0e39e01c908fdc498fff0d788fd7b955ab75ebb6

Authored by Jean Delvare
Committed by Greg Kroah-Hartman
1 parent 681c6f7a67

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>

Showing 4 changed files with 357 additions and 264 deletions Side-by-side Diff

drivers/hwmon/f71805f.c
... ... @@ -31,6 +31,7 @@
31 31 #include <linux/hwmon-sysfs.h>
32 32 #include <linux/err.h>
33 33 #include <linux/mutex.h>
  34 +#include <linux/sysfs.h>
34 35 #include <asm/io.h>
35 36  
36 37 static struct platform_device *pdev;
37 38  
38 39  
39 40  
40 41  
41 42  
... ... @@ -593,106 +594,191 @@
593 594 return sprintf(buf, "%s\n", data->name);
594 595 }
595 596  
596   -static struct device_attribute f71805f_dev_attr[] = {
597   - __ATTR(in0_input, S_IRUGO, show_in0, NULL),
598   - __ATTR(in0_max, S_IRUGO| S_IWUSR, show_in0_max, set_in0_max),
599   - __ATTR(in0_min, S_IRUGO| S_IWUSR, show_in0_min, set_in0_min),
600   - __ATTR(alarms_in, S_IRUGO, show_alarms_in, NULL),
601   - __ATTR(alarms_fan, S_IRUGO, show_alarms_fan, NULL),
602   - __ATTR(alarms_temp, S_IRUGO, show_alarms_temp, NULL),
603   - __ATTR(name, S_IRUGO, show_name, NULL),
604   -};
  597 +static DEVICE_ATTR(in0_input, S_IRUGO, show_in0, NULL);
  598 +static DEVICE_ATTR(in0_max, S_IRUGO| S_IWUSR, show_in0_max, set_in0_max);
  599 +static DEVICE_ATTR(in0_min, S_IRUGO| S_IWUSR, show_in0_min, set_in0_min);
  600 +static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in, NULL, 1);
  601 +static SENSOR_DEVICE_ATTR(in1_max, S_IRUGO | S_IWUSR,
  602 + show_in_max, set_in_max, 1);
  603 +static SENSOR_DEVICE_ATTR(in1_min, S_IRUGO | S_IWUSR,
  604 + show_in_min, set_in_min, 1);
  605 +static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in, NULL, 2);
  606 +static SENSOR_DEVICE_ATTR(in2_max, S_IRUGO | S_IWUSR,
  607 + show_in_max, set_in_max, 2);
  608 +static SENSOR_DEVICE_ATTR(in2_min, S_IRUGO | S_IWUSR,
  609 + show_in_min, set_in_min, 2);
  610 +static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in, NULL, 3);
  611 +static SENSOR_DEVICE_ATTR(in3_max, S_IRUGO | S_IWUSR,
  612 + show_in_max, set_in_max, 3);
  613 +static SENSOR_DEVICE_ATTR(in3_min, S_IRUGO | S_IWUSR,
  614 + show_in_min, set_in_min, 3);
  615 +static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in, NULL, 4);
  616 +static SENSOR_DEVICE_ATTR(in4_max, S_IRUGO | S_IWUSR,
  617 + show_in_max, set_in_max, 4);
  618 +static SENSOR_DEVICE_ATTR(in4_min, S_IRUGO | S_IWUSR,
  619 + show_in_min, set_in_min, 4);
  620 +static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_in, NULL, 5);
  621 +static SENSOR_DEVICE_ATTR(in5_max, S_IRUGO | S_IWUSR,
  622 + show_in_max, set_in_max, 5);
  623 +static SENSOR_DEVICE_ATTR(in5_min, S_IRUGO | S_IWUSR,
  624 + show_in_min, set_in_min, 5);
  625 +static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_in, NULL, 6);
  626 +static SENSOR_DEVICE_ATTR(in6_max, S_IRUGO | S_IWUSR,
  627 + show_in_max, set_in_max, 6);
  628 +static SENSOR_DEVICE_ATTR(in6_min, S_IRUGO | S_IWUSR,
  629 + show_in_min, set_in_min, 6);
  630 +static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_in, NULL, 7);
  631 +static SENSOR_DEVICE_ATTR(in7_max, S_IRUGO | S_IWUSR,
  632 + show_in_max, set_in_max, 7);
  633 +static SENSOR_DEVICE_ATTR(in7_min, S_IRUGO | S_IWUSR,
  634 + show_in_min, set_in_min, 7);
  635 +static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_in, NULL, 8);
  636 +static SENSOR_DEVICE_ATTR(in8_max, S_IRUGO | S_IWUSR,
  637 + show_in_max, set_in_max, 8);
  638 +static SENSOR_DEVICE_ATTR(in8_min, S_IRUGO | S_IWUSR,
  639 + show_in_min, set_in_min, 8);
605 640  
606   -static struct sensor_device_attribute f71805f_sensor_attr[] = {
607   - SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1),
608   - SENSOR_ATTR(in1_max, S_IRUGO | S_IWUSR,
609   - show_in_max, set_in_max, 1),
610   - SENSOR_ATTR(in1_min, S_IRUGO | S_IWUSR,
611   - show_in_min, set_in_min, 1),
612   - SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2),
613   - SENSOR_ATTR(in2_max, S_IRUGO | S_IWUSR,
614   - show_in_max, set_in_max, 2),
615   - SENSOR_ATTR(in2_min, S_IRUGO | S_IWUSR,
616   - show_in_min, set_in_min, 2),
617   - SENSOR_ATTR(in3_input, S_IRUGO, show_in, NULL, 3),
618   - SENSOR_ATTR(in3_max, S_IRUGO | S_IWUSR,
619   - show_in_max, set_in_max, 3),
620   - SENSOR_ATTR(in3_min, S_IRUGO | S_IWUSR,
621   - show_in_min, set_in_min, 3),
622   - SENSOR_ATTR(in4_input, S_IRUGO, show_in, NULL, 4),
623   - SENSOR_ATTR(in4_max, S_IRUGO | S_IWUSR,
624   - show_in_max, set_in_max, 4),
625   - SENSOR_ATTR(in4_min, S_IRUGO | S_IWUSR,
626   - show_in_min, set_in_min, 4),
627   - SENSOR_ATTR(in5_input, S_IRUGO, show_in, NULL, 5),
628   - SENSOR_ATTR(in5_max, S_IRUGO | S_IWUSR,
629   - show_in_max, set_in_max, 5),
630   - SENSOR_ATTR(in5_min, S_IRUGO | S_IWUSR,
631   - show_in_min, set_in_min, 5),
632   - SENSOR_ATTR(in6_input, S_IRUGO, show_in, NULL, 6),
633   - SENSOR_ATTR(in6_max, S_IRUGO | S_IWUSR,
634   - show_in_max, set_in_max, 6),
635   - SENSOR_ATTR(in6_min, S_IRUGO | S_IWUSR,
636   - show_in_min, set_in_min, 6),
637   - SENSOR_ATTR(in7_input, S_IRUGO, show_in, NULL, 7),
638   - SENSOR_ATTR(in7_max, S_IRUGO | S_IWUSR,
639   - show_in_max, set_in_max, 7),
640   - SENSOR_ATTR(in7_min, S_IRUGO | S_IWUSR,
641   - show_in_min, set_in_min, 7),
642   - SENSOR_ATTR(in8_input, S_IRUGO, show_in, NULL, 8),
643   - SENSOR_ATTR(in8_max, S_IRUGO | S_IWUSR,
644   - show_in_max, set_in_max, 8),
645   - SENSOR_ATTR(in8_min, S_IRUGO | S_IWUSR,
646   - show_in_min, set_in_min, 8),
  641 +static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
  642 +static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR,
  643 + show_fan_min, set_fan_min, 0);
  644 +static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
  645 +static SENSOR_DEVICE_ATTR(fan2_min, S_IRUGO | S_IWUSR,
  646 + show_fan_min, set_fan_min, 1);
  647 +static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2);
  648 +static SENSOR_DEVICE_ATTR(fan3_min, S_IRUGO | S_IWUSR,
  649 + show_fan_min, set_fan_min, 2);
647 650  
648   - SENSOR_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0),
649   - SENSOR_ATTR(temp1_max, S_IRUGO | S_IWUSR,
650   - show_temp_max, set_temp_max, 0),
651   - SENSOR_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
652   - show_temp_hyst, set_temp_hyst, 0),
653   - SENSOR_ATTR(temp1_type, S_IRUGO, show_temp_type, NULL, 0),
654   - SENSOR_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1),
655   - SENSOR_ATTR(temp2_max, S_IRUGO | S_IWUSR,
656   - show_temp_max, set_temp_max, 1),
657   - SENSOR_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR,
658   - show_temp_hyst, set_temp_hyst, 1),
659   - SENSOR_ATTR(temp2_type, S_IRUGO, show_temp_type, NULL, 1),
660   - SENSOR_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2),
661   - SENSOR_ATTR(temp3_max, S_IRUGO | S_IWUSR,
662   - show_temp_max, set_temp_max, 2),
663   - SENSOR_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR,
664   - show_temp_hyst, set_temp_hyst, 2),
665   - SENSOR_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2),
  651 +static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
  652 +static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR,
  653 + show_temp_max, set_temp_max, 0);
  654 +static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
  655 + show_temp_hyst, set_temp_hyst, 0);
  656 +static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO, show_temp_type, NULL, 0);
  657 +static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
  658 +static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO | S_IWUSR,
  659 + show_temp_max, set_temp_max, 1);
  660 +static SENSOR_DEVICE_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR,
  661 + show_temp_hyst, set_temp_hyst, 1);
  662 +static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO, show_temp_type, NULL, 1);
  663 +static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
  664 +static SENSOR_DEVICE_ATTR(temp3_max, S_IRUGO | S_IWUSR,
  665 + show_temp_max, set_temp_max, 2);
  666 +static SENSOR_DEVICE_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR,
  667 + show_temp_hyst, set_temp_hyst, 2);
  668 +static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2);
666 669  
667   - SENSOR_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0),
668   - SENSOR_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1),
669   - SENSOR_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2),
670   - SENSOR_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3),
671   - SENSOR_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 4),
672   - SENSOR_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 5),
673   - SENSOR_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 6),
674   - SENSOR_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 7),
675   - SENSOR_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 8),
676   - SENSOR_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 11),
677   - SENSOR_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 12),
678   - SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13),
  670 +static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
  671 +static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
  672 +static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
  673 +static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
  674 +static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 4);
  675 +static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 5);
  676 +static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 6);
  677 +static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 7);
  678 +static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 8);
  679 +static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 11);
  680 +static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 12);
  681 +static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13);
  682 +static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 16);
  683 +static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 17);
  684 +static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 18);
  685 +static DEVICE_ATTR(alarms_in, S_IRUGO, show_alarms_in, NULL);
  686 +static DEVICE_ATTR(alarms_fan, S_IRUGO, show_alarms_fan, NULL);
  687 +static DEVICE_ATTR(alarms_temp, S_IRUGO, show_alarms_temp, NULL);
  688 +
  689 +static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
  690 +
  691 +static struct attribute *f71805f_attributes[] = {
  692 + &dev_attr_in0_input.attr,
  693 + &dev_attr_in0_max.attr,
  694 + &dev_attr_in0_min.attr,
  695 + &sensor_dev_attr_in1_input.dev_attr.attr,
  696 + &sensor_dev_attr_in1_max.dev_attr.attr,
  697 + &sensor_dev_attr_in1_min.dev_attr.attr,
  698 + &sensor_dev_attr_in2_input.dev_attr.attr,
  699 + &sensor_dev_attr_in2_max.dev_attr.attr,
  700 + &sensor_dev_attr_in2_min.dev_attr.attr,
  701 + &sensor_dev_attr_in3_input.dev_attr.attr,
  702 + &sensor_dev_attr_in3_max.dev_attr.attr,
  703 + &sensor_dev_attr_in3_min.dev_attr.attr,
  704 + &sensor_dev_attr_in4_input.dev_attr.attr,
  705 + &sensor_dev_attr_in4_max.dev_attr.attr,
  706 + &sensor_dev_attr_in4_min.dev_attr.attr,
  707 + &sensor_dev_attr_in5_input.dev_attr.attr,
  708 + &sensor_dev_attr_in5_max.dev_attr.attr,
  709 + &sensor_dev_attr_in5_min.dev_attr.attr,
  710 + &sensor_dev_attr_in6_input.dev_attr.attr,
  711 + &sensor_dev_attr_in6_max.dev_attr.attr,
  712 + &sensor_dev_attr_in6_min.dev_attr.attr,
  713 + &sensor_dev_attr_in7_input.dev_attr.attr,
  714 + &sensor_dev_attr_in7_max.dev_attr.attr,
  715 + &sensor_dev_attr_in7_min.dev_attr.attr,
  716 + &sensor_dev_attr_in8_input.dev_attr.attr,
  717 + &sensor_dev_attr_in8_max.dev_attr.attr,
  718 + &sensor_dev_attr_in8_min.dev_attr.attr,
  719 +
  720 + &sensor_dev_attr_temp1_input.dev_attr.attr,
  721 + &sensor_dev_attr_temp1_max.dev_attr.attr,
  722 + &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
  723 + &sensor_dev_attr_temp1_type.dev_attr.attr,
  724 + &sensor_dev_attr_temp2_input.dev_attr.attr,
  725 + &sensor_dev_attr_temp2_max.dev_attr.attr,
  726 + &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
  727 + &sensor_dev_attr_temp2_type.dev_attr.attr,
  728 + &sensor_dev_attr_temp3_input.dev_attr.attr,
  729 + &sensor_dev_attr_temp3_max.dev_attr.attr,
  730 + &sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
  731 + &sensor_dev_attr_temp3_type.dev_attr.attr,
  732 +
  733 + &sensor_dev_attr_in0_alarm.dev_attr.attr,
  734 + &sensor_dev_attr_in1_alarm.dev_attr.attr,
  735 + &sensor_dev_attr_in2_alarm.dev_attr.attr,
  736 + &sensor_dev_attr_in3_alarm.dev_attr.attr,
  737 + &sensor_dev_attr_in4_alarm.dev_attr.attr,
  738 + &sensor_dev_attr_in5_alarm.dev_attr.attr,
  739 + &sensor_dev_attr_in6_alarm.dev_attr.attr,
  740 + &sensor_dev_attr_in7_alarm.dev_attr.attr,
  741 + &sensor_dev_attr_in8_alarm.dev_attr.attr,
  742 + &dev_attr_alarms_in.attr,
  743 + &sensor_dev_attr_temp1_alarm.dev_attr.attr,
  744 + &sensor_dev_attr_temp2_alarm.dev_attr.attr,
  745 + &sensor_dev_attr_temp3_alarm.dev_attr.attr,
  746 + &dev_attr_alarms_temp.attr,
  747 + &dev_attr_alarms_fan.attr,
  748 +
  749 + &dev_attr_name.attr,
  750 + NULL
679 751 };
680 752  
681   -static struct sensor_device_attribute f71805f_fan_attr[] = {
682   - SENSOR_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0),
683   - SENSOR_ATTR(fan1_min, S_IRUGO | S_IWUSR,
684   - show_fan_min, set_fan_min, 0),
685   - SENSOR_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 16),
686   - SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1),
687   - SENSOR_ATTR(fan2_min, S_IRUGO | S_IWUSR,
688   - show_fan_min, set_fan_min, 1),
689   - SENSOR_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 17),
690   - SENSOR_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2),
691   - SENSOR_ATTR(fan3_min, S_IRUGO | S_IWUSR,
692   - show_fan_min, set_fan_min, 2),
693   - SENSOR_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 18),
  753 +static const struct attribute_group f71805f_group = {
  754 + .attrs = f71805f_attributes,
694 755 };
695 756  
  757 +static struct attribute *f71805f_attributes_fan[3][4] = {
  758 + {
  759 + &sensor_dev_attr_fan1_input.dev_attr.attr,
  760 + &sensor_dev_attr_fan1_min.dev_attr.attr,
  761 + &sensor_dev_attr_fan1_alarm.dev_attr.attr,
  762 + NULL
  763 + }, {
  764 + &sensor_dev_attr_fan2_input.dev_attr.attr,
  765 + &sensor_dev_attr_fan2_min.dev_attr.attr,
  766 + &sensor_dev_attr_fan2_alarm.dev_attr.attr,
  767 + NULL
  768 + }, {
  769 + &sensor_dev_attr_fan3_input.dev_attr.attr,
  770 + &sensor_dev_attr_fan3_min.dev_attr.attr,
  771 + &sensor_dev_attr_fan3_alarm.dev_attr.attr,
  772 + NULL
  773 + }
  774 +};
  775 +
  776 +static const struct attribute_group f71805f_group_fan[3] = {
  777 + { .attrs = f71805f_attributes_fan[0] },
  778 + { .attrs = f71805f_attributes_fan[1] },
  779 + { .attrs = f71805f_attributes_fan[2] },
  780 +};
  781 +
696 782 /*
697 783 * Device registration and initialization
698 784 */
699 785  
700 786  
701 787  
702 788  
703 789  
... ... @@ -738,43 +824,35 @@
738 824  
739 825 platform_set_drvdata(pdev, data);
740 826  
741   - data->class_dev = hwmon_device_register(&pdev->dev);
742   - if (IS_ERR(data->class_dev)) {
743   - err = PTR_ERR(data->class_dev);
744   - dev_err(&pdev->dev, "Class registration failed (%d)\n", err);
745   - goto exit_free;
746   - }
747   -
748 827 /* Initialize the F71805F chip */
749 828 f71805f_init_device(data);
750 829  
751 830 /* Register sysfs interface files */
752   - for (i = 0; i < ARRAY_SIZE(f71805f_dev_attr); i++) {
753   - err = device_create_file(&pdev->dev, &f71805f_dev_attr[i]);
754   - if (err)
755   - goto exit_class;
756   - }
757   - for (i = 0; i < ARRAY_SIZE(f71805f_sensor_attr); i++) {
758   - err = device_create_file(&pdev->dev,
759   - &f71805f_sensor_attr[i].dev_attr);
760   - if (err)
761   - goto exit_class;
762   - }
763   - for (i = 0; i < ARRAY_SIZE(f71805f_fan_attr); i++) {
764   - if (!(data->fan_enabled & (1 << (i / 3))))
  831 + if ((err = sysfs_create_group(&pdev->dev.kobj, &f71805f_group)))
  832 + goto exit_free;
  833 + for (i = 0; i < 3; i++) {
  834 + if (!(data->fan_enabled & (1 << i)))
765 835 continue;
766   - err = device_create_file(&pdev->dev,
767   - &f71805f_fan_attr[i].dev_attr);
768   - if (err)
769   - goto exit_class;
  836 + if ((err = sysfs_create_group(&pdev->dev.kobj,
  837 + &f71805f_group_fan[i])))
  838 + goto exit_remove_files;
770 839 }
771 840  
  841 + data->class_dev = hwmon_device_register(&pdev->dev);
  842 + if (IS_ERR(data->class_dev)) {
  843 + err = PTR_ERR(data->class_dev);
  844 + dev_err(&pdev->dev, "Class registration failed (%d)\n", err);
  845 + goto exit_remove_files;
  846 + }
  847 +
772 848 return 0;
773 849  
774   -exit_class:
775   - dev_err(&pdev->dev, "Sysfs interface creation failed\n");
776   - hwmon_device_unregister(data->class_dev);
  850 +exit_remove_files:
  851 + sysfs_remove_group(&pdev->dev.kobj, &f71805f_group);
  852 + for (i = 0; i < 3; i++)
  853 + sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_fan[i]);
777 854 exit_free:
  855 + platform_set_drvdata(pdev, NULL);
778 856 kfree(data);
779 857 exit:
780 858 return err;
781 859  
... ... @@ -783,9 +861,13 @@
783 861 static int __devexit f71805f_remove(struct platform_device *pdev)
784 862 {
785 863 struct f71805f_data *data = platform_get_drvdata(pdev);
  864 + int i;
786 865  
787 866 platform_set_drvdata(pdev, NULL);
788 867 hwmon_device_unregister(data->class_dev);
  868 + sysfs_remove_group(&pdev->dev.kobj, &f71805f_group);
  869 + for (i = 0; i < 3; i++)
  870 + sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_fan[i]);
789 871 kfree(data);
790 872  
791 873 return 0;
drivers/hwmon/lm63.c
... ... @@ -46,6 +46,7 @@
46 46 #include <linux/hwmon.h>
47 47 #include <linux/err.h>
48 48 #include <linux/mutex.h>
  49 +#include <linux/sysfs.h>
49 50  
50 51 /*
51 52 * Addresses to scan
... ... @@ -370,6 +371,42 @@
370 371 /* Raw alarm file for compatibility */
371 372 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
372 373  
  374 +static struct attribute *lm63_attributes[] = {
  375 + &dev_attr_pwm1.attr,
  376 + &dev_attr_pwm1_enable.attr,
  377 + &sensor_dev_attr_temp1_input.dev_attr.attr,
  378 + &sensor_dev_attr_temp2_input.dev_attr.attr,
  379 + &sensor_dev_attr_temp2_min.dev_attr.attr,
  380 + &sensor_dev_attr_temp1_max.dev_attr.attr,
  381 + &sensor_dev_attr_temp2_max.dev_attr.attr,
  382 + &sensor_dev_attr_temp2_crit.dev_attr.attr,
  383 + &dev_attr_temp2_crit_hyst.attr,
  384 +
  385 + &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
  386 + &sensor_dev_attr_temp2_input_fault.dev_attr.attr,
  387 + &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
  388 + &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
  389 + &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
  390 + &dev_attr_alarms.attr,
  391 + NULL
  392 +};
  393 +
  394 +static const struct attribute_group lm63_group = {
  395 + .attrs = lm63_attributes,
  396 +};
  397 +
  398 +static struct attribute *lm63_attributes_fan1[] = {
  399 + &sensor_dev_attr_fan1_input.dev_attr.attr,
  400 + &sensor_dev_attr_fan1_min.dev_attr.attr,
  401 +
  402 + &sensor_dev_attr_fan1_min_alarm.dev_attr.attr,
  403 + NULL
  404 +};
  405 +
  406 +static const struct attribute_group lm63_group_fan1 = {
  407 + .attrs = lm63_attributes_fan1,
  408 +};
  409 +
373 410 /*
374 411 * Real code
375 412 */
376 413  
377 414  
378 415  
... ... @@ -456,50 +493,26 @@
456 493 lm63_init_client(new_client);
457 494  
458 495 /* Register sysfs hooks */
  496 + if ((err = sysfs_create_group(&new_client->dev.kobj,
  497 + &lm63_group)))
  498 + goto exit_detach;
  499 + if (data->config & 0x04) { /* tachometer enabled */
  500 + if ((err = sysfs_create_group(&new_client->dev.kobj,
  501 + &lm63_group_fan1)))
  502 + goto exit_remove_files;
  503 + }
  504 +
459 505 data->class_dev = hwmon_device_register(&new_client->dev);
460 506 if (IS_ERR(data->class_dev)) {
461 507 err = PTR_ERR(data->class_dev);
462   - goto exit_detach;
  508 + goto exit_remove_files;
463 509 }
464 510  
465   - if (data->config & 0x04) { /* tachometer enabled */
466   - device_create_file(&new_client->dev,
467   - &sensor_dev_attr_fan1_input.dev_attr);
468   - device_create_file(&new_client->dev,
469   - &sensor_dev_attr_fan1_min.dev_attr);
470   - device_create_file(&new_client->dev,
471   - &sensor_dev_attr_fan1_min_alarm.dev_attr);
472   - }
473   - device_create_file(&new_client->dev, &dev_attr_pwm1);
474   - device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
475   - device_create_file(&new_client->dev,
476   - &sensor_dev_attr_temp1_input.dev_attr);
477   - device_create_file(&new_client->dev,
478   - &sensor_dev_attr_temp2_input.dev_attr);
479   - device_create_file(&new_client->dev,
480   - &sensor_dev_attr_temp2_min.dev_attr);
481   - device_create_file(&new_client->dev,
482   - &sensor_dev_attr_temp1_max.dev_attr);
483   - device_create_file(&new_client->dev,
484   - &sensor_dev_attr_temp2_max.dev_attr);
485   - device_create_file(&new_client->dev,
486   - &sensor_dev_attr_temp2_crit.dev_attr);
487   - device_create_file(&new_client->dev, &dev_attr_temp2_crit_hyst);
488   -
489   - device_create_file(&new_client->dev,
490   - &sensor_dev_attr_temp2_input_fault.dev_attr);
491   - device_create_file(&new_client->dev,
492   - &sensor_dev_attr_temp2_min_alarm.dev_attr);
493   - device_create_file(&new_client->dev,
494   - &sensor_dev_attr_temp1_max_alarm.dev_attr);
495   - device_create_file(&new_client->dev,
496   - &sensor_dev_attr_temp2_max_alarm.dev_attr);
497   - device_create_file(&new_client->dev,
498   - &sensor_dev_attr_temp2_crit_alarm.dev_attr);
499   - device_create_file(&new_client->dev, &dev_attr_alarms);
500   -
501 511 return 0;
502 512  
  513 +exit_remove_files:
  514 + sysfs_remove_group(&new_client->dev.kobj, &lm63_group);
  515 + sysfs_remove_group(&new_client->dev.kobj, &lm63_group_fan1);
503 516 exit_detach:
504 517 i2c_detach_client(new_client);
505 518 exit_free:
... ... @@ -549,6 +562,8 @@
549 562 int err;
550 563  
551 564 hwmon_device_unregister(data->class_dev);
  565 + sysfs_remove_group(&client->dev.kobj, &lm63_group);
  566 + sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1);
552 567  
553 568 if ((err = i2c_detach_client(client)))
554 569 return err;
drivers/hwmon/lm83.c
... ... @@ -40,6 +40,7 @@
40 40 #include <linux/hwmon.h>
41 41 #include <linux/err.h>
42 42 #include <linux/mutex.h>
  43 +#include <linux/sysfs.h>
43 44  
44 45 /*
45 46 * Addresses to scan
... ... @@ -234,6 +235,48 @@
234 235 /* Raw alarm file for compatibility */
235 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 281 * Real code
239 282 */
240 283  
241 284  
242 285  
243 286  
244 287  
... ... @@ -342,82 +385,32 @@
342 385 goto exit_free;
343 386  
344 387 /*
345   - * Initialize the LM83 chip
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   - /*
  388 + * Register sysfs hooks
357 389 * The LM82 can only monitor one external diode which is
358 390 * at the same register as the LM83 temp3 entry - so we
359 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,
363   - &sensor_dev_attr_temp1_input.dev_attr);
364   - device_create_file(&new_client->dev,
365   - &sensor_dev_attr_temp3_input.dev_attr);
  394 + if ((err = sysfs_create_group(&new_client->dev.kobj, &lm83_group)))
  395 + goto exit_detach;
366 396  
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   -
389 397 if (kind == lm83) {
390   - device_create_file(&new_client->dev,
391   - &sensor_dev_attr_temp2_input.dev_attr);
392   - device_create_file(&new_client->dev,
393   - &sensor_dev_attr_temp4_input.dev_attr);
  398 + if ((err = sysfs_create_group(&new_client->dev.kobj,
  399 + &lm83_group_opt)))
  400 + goto exit_remove_files;
  401 + }
394 402  
395   - device_create_file(&new_client->dev,
396   - &sensor_dev_attr_temp2_max.dev_attr);
397   - device_create_file(&new_client->dev,
398   - &sensor_dev_attr_temp4_max.dev_attr);
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);
  403 + data->class_dev = hwmon_device_register(&new_client->dev);
  404 + if (IS_ERR(data->class_dev)) {
  405 + err = PTR_ERR(data->class_dev);
  406 + goto exit_remove_files;
417 407 }
418 408  
419 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 414 exit_detach:
422 415 i2c_detach_client(new_client);
423 416 exit_free:
... ... @@ -432,6 +425,8 @@
432 425 int err;
433 426  
434 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 431 if ((err = i2c_detach_client(client)))
437 432 return err;
drivers/hwmon/lm90.c
... ... @@ -79,6 +79,7 @@
79 79 #include <linux/hwmon.h>
80 80 #include <linux/err.h>
81 81 #include <linux/mutex.h>
  82 +#include <linux/sysfs.h>
82 83  
83 84 /*
84 85 * Addresses to scan
... ... @@ -366,6 +367,33 @@
366 367 /* Raw alarm file for compatibility */
367 368 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
368 369  
  370 +static struct attribute *lm90_attributes[] = {
  371 + &sensor_dev_attr_temp1_input.dev_attr.attr,
  372 + &sensor_dev_attr_temp2_input.dev_attr.attr,
  373 + &sensor_dev_attr_temp1_min.dev_attr.attr,
  374 + &sensor_dev_attr_temp2_min.dev_attr.attr,
  375 + &sensor_dev_attr_temp1_max.dev_attr.attr,
  376 + &sensor_dev_attr_temp2_max.dev_attr.attr,
  377 + &sensor_dev_attr_temp1_crit.dev_attr.attr,
  378 + &sensor_dev_attr_temp2_crit.dev_attr.attr,
  379 + &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
  380 + &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
  381 +
  382 + &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
  383 + &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
  384 + &sensor_dev_attr_temp2_input_fault.dev_attr.attr,
  385 + &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
  386 + &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
  387 + &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
  388 + &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
  389 + &dev_attr_alarms.attr,
  390 + NULL
  391 +};
  392 +
  393 +static const struct attribute_group lm90_group = {
  394 + .attrs = lm90_attributes,
  395 +};
  396 +
369 397 /* pec used for ADM1032 only */
370 398 static ssize_t show_pec(struct device *dev, struct device_attribute *dummy,
371 399 char *buf)
372 400  
373 401  
374 402  
... ... @@ -589,54 +617,25 @@
589 617 lm90_init_client(new_client);
590 618  
591 619 /* Register sysfs hooks */
  620 + if ((err = sysfs_create_group(&new_client->dev.kobj, &lm90_group)))
  621 + goto exit_detach;
  622 + if (new_client->flags & I2C_CLIENT_PEC) {
  623 + if ((err = device_create_file(&new_client->dev,
  624 + &dev_attr_pec)))
  625 + goto exit_remove_files;
  626 + }
  627 +
592 628 data->class_dev = hwmon_device_register(&new_client->dev);
593 629 if (IS_ERR(data->class_dev)) {
594 630 err = PTR_ERR(data->class_dev);
595   - goto exit_detach;
  631 + goto exit_remove_files;
596 632 }
597 633  
598   - device_create_file(&new_client->dev,
599   - &sensor_dev_attr_temp1_input.dev_attr);
600   - device_create_file(&new_client->dev,
601   - &sensor_dev_attr_temp2_input.dev_attr);
602   - device_create_file(&new_client->dev,
603   - &sensor_dev_attr_temp1_min.dev_attr);
604   - device_create_file(&new_client->dev,
605   - &sensor_dev_attr_temp2_min.dev_attr);
606   - device_create_file(&new_client->dev,
607   - &sensor_dev_attr_temp1_max.dev_attr);
608   - device_create_file(&new_client->dev,
609   - &sensor_dev_attr_temp2_max.dev_attr);
610   - device_create_file(&new_client->dev,
611   - &sensor_dev_attr_temp1_crit.dev_attr);
612   - device_create_file(&new_client->dev,
613   - &sensor_dev_attr_temp2_crit.dev_attr);
614   - device_create_file(&new_client->dev,
615   - &sensor_dev_attr_temp1_crit_hyst.dev_attr);
616   - device_create_file(&new_client->dev,
617   - &sensor_dev_attr_temp2_crit_hyst.dev_attr);
618   -
619   - device_create_file(&new_client->dev,
620   - &sensor_dev_attr_temp2_input_fault.dev_attr);
621   - device_create_file(&new_client->dev,
622   - &sensor_dev_attr_temp1_min_alarm.dev_attr);
623   - device_create_file(&new_client->dev,
624   - &sensor_dev_attr_temp2_min_alarm.dev_attr);
625   - device_create_file(&new_client->dev,
626   - &sensor_dev_attr_temp1_max_alarm.dev_attr);
627   - device_create_file(&new_client->dev,
628   - &sensor_dev_attr_temp2_max_alarm.dev_attr);
629   - device_create_file(&new_client->dev,
630   - &sensor_dev_attr_temp1_crit_alarm.dev_attr);
631   - device_create_file(&new_client->dev,
632   - &sensor_dev_attr_temp2_crit_alarm.dev_attr);
633   - device_create_file(&new_client->dev, &dev_attr_alarms);
634   -
635   - if (new_client->flags & I2C_CLIENT_PEC)
636   - device_create_file(&new_client->dev, &dev_attr_pec);
637   -
638 634 return 0;
639 635  
  636 +exit_remove_files:
  637 + sysfs_remove_group(&new_client->dev.kobj, &lm90_group);
  638 + device_remove_file(&new_client->dev, &dev_attr_pec);
640 639 exit_detach:
641 640 i2c_detach_client(new_client);
642 641 exit_free:
... ... @@ -669,6 +668,8 @@
669 668 int err;
670 669  
671 670 hwmon_device_unregister(data->class_dev);
  671 + sysfs_remove_group(&client->dev.kobj, &lm90_group);
  672 + device_remove_file(&client->dev, &dev_attr_pec);
672 673  
673 674 if ((err = i2c_detach_client(client)))
674 675 return err;