diff options
author | Kyle McMartin <kyle@mcmartin.ca> | 2012-04-02 14:19:02 -0400 |
---|---|---|
committer | Guenter Roeck <guenter.roeck@ericsson.com> | 2012-05-20 22:41:48 -0400 |
commit | f49d6a7ed2406b0c9b1c134f2e9aa4426a5266f0 (patch) | |
tree | 60a788dfcd2242ef46dcb32f5d12a92872cfc2f3 | |
parent | 3c45f2c78db21f4676287df19c89343acf04e7ef (diff) |
acpi_power_meter: remove duplicate code between register_{ro,rw}_attrs
Key off the attr->set method being present to set the sysfs attribute
as writable.
Signed-off-by: Kyle McMartin <kyle@redhat.com>
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
-rw-r--r-- | drivers/hwmon/acpi_power_meter.c | 59 |
1 files changed, 17 insertions, 42 deletions
diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c index 11922c835860..954e21f4dd18 100644 --- a/drivers/hwmon/acpi_power_meter.c +++ b/drivers/hwmon/acpi_power_meter.c | |||
@@ -630,49 +630,24 @@ end: | |||
630 | } | 630 | } |
631 | 631 | ||
632 | /* Registration and deregistration */ | 632 | /* Registration and deregistration */ |
633 | static int register_ro_attrs(struct acpi_power_meter_resource *resource, | 633 | static int register_attrs(struct acpi_power_meter_resource *resource, |
634 | struct sensor_template *ro) | 634 | struct sensor_template *attrs) |
635 | { | 635 | { |
636 | struct device *dev = &resource->acpi_dev->dev; | 636 | struct device *dev = &resource->acpi_dev->dev; |
637 | struct sensor_device_attribute *sensors = | 637 | struct sensor_device_attribute *sensors = |
638 | &resource->sensors[resource->num_sensors]; | 638 | &resource->sensors[resource->num_sensors]; |
639 | int res = 0; | 639 | int res = 0; |
640 | 640 | ||
641 | while (ro->label) { | 641 | while (attrs->label) { |
642 | sensors->dev_attr.attr.name = ro->label; | 642 | sensors->dev_attr.attr.name = attrs->label; |
643 | sensors->dev_attr.attr.mode = S_IRUGO; | 643 | sensors->dev_attr.attr.mode = S_IRUGO; |
644 | sensors->dev_attr.show = ro->show; | 644 | sensors->dev_attr.show = attrs->show; |
645 | sensors->index = ro->index; | 645 | sensors->index = attrs->index; |
646 | 646 | ||
647 | sysfs_attr_init(&sensors->dev_attr.attr); | 647 | if (attrs->set) { |
648 | res = device_create_file(dev, &sensors->dev_attr); | 648 | sensors->dev_attr.attr.mode |= S_IWUSR; |
649 | if (res) { | 649 | sensors->dev_attr.store = attrs->set; |
650 | sensors->dev_attr.attr.name = NULL; | ||
651 | goto error; | ||
652 | } | 650 | } |
653 | sensors++; | ||
654 | resource->num_sensors++; | ||
655 | ro++; | ||
656 | } | ||
657 | |||
658 | error: | ||
659 | return res; | ||
660 | } | ||
661 | |||
662 | static int register_rw_attrs(struct acpi_power_meter_resource *resource, | ||
663 | struct sensor_template *rw) | ||
664 | { | ||
665 | struct device *dev = &resource->acpi_dev->dev; | ||
666 | struct sensor_device_attribute *sensors = | ||
667 | &resource->sensors[resource->num_sensors]; | ||
668 | int res = 0; | ||
669 | |||
670 | while (rw->label) { | ||
671 | sensors->dev_attr.attr.name = rw->label; | ||
672 | sensors->dev_attr.attr.mode = S_IRUGO | S_IWUSR; | ||
673 | sensors->dev_attr.show = rw->show; | ||
674 | sensors->dev_attr.store = rw->set; | ||
675 | sensors->index = rw->index; | ||
676 | 651 | ||
677 | sysfs_attr_init(&sensors->dev_attr.attr); | 652 | sysfs_attr_init(&sensors->dev_attr.attr); |
678 | res = device_create_file(dev, &sensors->dev_attr); | 653 | res = device_create_file(dev, &sensors->dev_attr); |
@@ -682,7 +657,7 @@ static int register_rw_attrs(struct acpi_power_meter_resource *resource, | |||
682 | } | 657 | } |
683 | sensors++; | 658 | sensors++; |
684 | resource->num_sensors++; | 659 | resource->num_sensors++; |
685 | rw++; | 660 | attrs++; |
686 | } | 661 | } |
687 | 662 | ||
688 | error: | 663 | error: |
@@ -714,10 +689,10 @@ static int setup_attrs(struct acpi_power_meter_resource *resource) | |||
714 | return res; | 689 | return res; |
715 | 690 | ||
716 | if (resource->caps.flags & POWER_METER_CAN_MEASURE) { | 691 | if (resource->caps.flags & POWER_METER_CAN_MEASURE) { |
717 | res = register_ro_attrs(resource, meter_ro_attrs); | 692 | res = register_attrs(resource, meter_ro_attrs); |
718 | if (res) | 693 | if (res) |
719 | goto error; | 694 | goto error; |
720 | res = register_rw_attrs(resource, meter_rw_attrs); | 695 | res = register_attrs(resource, meter_rw_attrs); |
721 | if (res) | 696 | if (res) |
722 | goto error; | 697 | goto error; |
723 | } | 698 | } |
@@ -730,27 +705,27 @@ static int setup_attrs(struct acpi_power_meter_resource *resource) | |||
730 | } | 705 | } |
731 | 706 | ||
732 | if (resource->caps.configurable_cap) { | 707 | if (resource->caps.configurable_cap) { |
733 | res = register_rw_attrs(resource, rw_cap_attrs); | 708 | res = register_attrs(resource, rw_cap_attrs); |
734 | if (res) | 709 | if (res) |
735 | goto error; | 710 | goto error; |
736 | } else { | 711 | } else { |
737 | res = register_ro_attrs(resource, ro_cap_attrs); | 712 | res = register_attrs(resource, ro_cap_attrs); |
738 | if (res) | 713 | if (res) |
739 | goto error; | 714 | goto error; |
740 | } | 715 | } |
741 | res = register_ro_attrs(resource, misc_cap_attrs); | 716 | res = register_attrs(resource, misc_cap_attrs); |
742 | if (res) | 717 | if (res) |
743 | goto error; | 718 | goto error; |
744 | } | 719 | } |
745 | skip_unsafe_cap: | 720 | skip_unsafe_cap: |
746 | 721 | ||
747 | if (resource->caps.flags & POWER_METER_CAN_TRIP) { | 722 | if (resource->caps.flags & POWER_METER_CAN_TRIP) { |
748 | res = register_rw_attrs(resource, trip_attrs); | 723 | res = register_attrs(resource, trip_attrs); |
749 | if (res) | 724 | if (res) |
750 | goto error; | 725 | goto error; |
751 | } | 726 | } |
752 | 727 | ||
753 | res = register_ro_attrs(resource, misc_attrs); | 728 | res = register_attrs(resource, misc_attrs); |
754 | if (res) | 729 | if (res) |
755 | goto error; | 730 | goto error; |
756 | 731 | ||