.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * A hwmon driver for ACPI 4.0 power meters |
---|
3 | 4 | * Copyright (C) 2009 IBM |
---|
4 | 5 | * |
---|
5 | 6 | * Author: Darrick J. Wong <darrick.wong@oracle.com> |
---|
6 | | - * |
---|
7 | | - * This program is free software; you can redistribute it and/or modify |
---|
8 | | - * it under the terms of the GNU General Public License as published by |
---|
9 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
10 | | - * (at your option) any later version. |
---|
11 | | - * |
---|
12 | | - * This program is distributed in the hope that it will be useful, |
---|
13 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | | - * GNU General Public License for more details. |
---|
16 | | - * |
---|
17 | | - * You should have received a copy of the GNU General Public License |
---|
18 | | - * along with this program; if not, write to the Free Software |
---|
19 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
20 | 7 | */ |
---|
21 | 8 | |
---|
22 | 9 | #include <linux/module.h> |
---|
.. | .. |
---|
368 | 355 | struct acpi_device *acpi_dev = to_acpi_device(dev); |
---|
369 | 356 | struct acpi_power_meter_resource *resource = acpi_dev->driver_data; |
---|
370 | 357 | acpi_string val; |
---|
| 358 | + int ret; |
---|
371 | 359 | |
---|
| 360 | + mutex_lock(&resource->lock); |
---|
372 | 361 | switch (attr->index) { |
---|
373 | 362 | case 0: |
---|
374 | 363 | val = resource->model_number; |
---|
.. | .. |
---|
385 | 374 | val = ""; |
---|
386 | 375 | break; |
---|
387 | 376 | } |
---|
388 | | - |
---|
389 | | - return sprintf(buf, "%s\n", val); |
---|
| 377 | + ret = sprintf(buf, "%s\n", val); |
---|
| 378 | + mutex_unlock(&resource->lock); |
---|
| 379 | + return ret; |
---|
390 | 380 | } |
---|
391 | 381 | |
---|
392 | 382 | static ssize_t show_val(struct device *dev, |
---|
.. | .. |
---|
638 | 628 | |
---|
639 | 629 | while (attrs->label) { |
---|
640 | 630 | sensors->dev_attr.attr.name = attrs->label; |
---|
641 | | - sensors->dev_attr.attr.mode = S_IRUGO; |
---|
| 631 | + sensors->dev_attr.attr.mode = 0444; |
---|
642 | 632 | sensors->dev_attr.show = attrs->show; |
---|
643 | 633 | sensors->index = attrs->index; |
---|
644 | 634 | |
---|
645 | 635 | if (attrs->set) { |
---|
646 | | - sensors->dev_attr.attr.mode |= S_IWUSR; |
---|
| 636 | + sensors->dev_attr.attr.mode |= 0200; |
---|
647 | 637 | sensors->dev_attr.store = attrs->set; |
---|
648 | 638 | } |
---|
649 | 639 | |
---|
.. | .. |
---|
830 | 820 | |
---|
831 | 821 | resource = acpi_driver_data(device); |
---|
832 | 822 | |
---|
833 | | - mutex_lock(&resource->lock); |
---|
834 | 823 | switch (event) { |
---|
835 | 824 | case METER_NOTIFY_CONFIG: |
---|
| 825 | + mutex_lock(&resource->lock); |
---|
836 | 826 | free_capabilities(resource); |
---|
837 | 827 | res = read_capabilities(resource); |
---|
| 828 | + mutex_unlock(&resource->lock); |
---|
838 | 829 | if (res) |
---|
839 | 830 | break; |
---|
840 | 831 | |
---|
.. | .. |
---|
843 | 834 | break; |
---|
844 | 835 | case METER_NOTIFY_TRIP: |
---|
845 | 836 | sysfs_notify(&device->dev.kobj, NULL, POWER_AVERAGE_NAME); |
---|
846 | | - update_meter(resource); |
---|
847 | 837 | break; |
---|
848 | 838 | case METER_NOTIFY_CAP: |
---|
849 | 839 | sysfs_notify(&device->dev.kobj, NULL, POWER_CAP_NAME); |
---|
850 | | - update_cap(resource); |
---|
851 | 840 | break; |
---|
852 | 841 | case METER_NOTIFY_INTERVAL: |
---|
853 | 842 | sysfs_notify(&device->dev.kobj, NULL, POWER_AVG_INTERVAL_NAME); |
---|
854 | | - update_avg_interval(resource); |
---|
855 | 843 | break; |
---|
856 | 844 | case METER_NOTIFY_CAPPING: |
---|
857 | 845 | sysfs_notify(&device->dev.kobj, NULL, POWER_ALARM_NAME); |
---|
.. | .. |
---|
861 | 849 | WARN(1, "Unexpected event %d\n", event); |
---|
862 | 850 | break; |
---|
863 | 851 | } |
---|
864 | | - mutex_unlock(&resource->lock); |
---|
865 | 852 | |
---|
866 | 853 | acpi_bus_generate_netlink_event(ACPI_POWER_METER_CLASS, |
---|
867 | 854 | dev_name(&device->dev), event, 0); |
---|
.. | .. |
---|
927 | 914 | resource = acpi_driver_data(device); |
---|
928 | 915 | hwmon_device_unregister(resource->hwmon_dev); |
---|
929 | 916 | |
---|
930 | | - free_capabilities(resource); |
---|
931 | 917 | remove_attrs(resource); |
---|
| 918 | + free_capabilities(resource); |
---|
932 | 919 | |
---|
933 | 920 | kfree(resource); |
---|
934 | 921 | return 0; |
---|