hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/hwmon/acpi_power_meter.c
....@@ -1,22 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * A hwmon driver for ACPI 4.0 power meters
34 * Copyright (C) 2009 IBM
45 *
56 * 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
207 */
218
229 #include <linux/module.h>
....@@ -368,7 +355,9 @@
368355 struct acpi_device *acpi_dev = to_acpi_device(dev);
369356 struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
370357 acpi_string val;
358
+ int ret;
371359
360
+ mutex_lock(&resource->lock);
372361 switch (attr->index) {
373362 case 0:
374363 val = resource->model_number;
....@@ -385,8 +374,9 @@
385374 val = "";
386375 break;
387376 }
388
-
389
- return sprintf(buf, "%s\n", val);
377
+ ret = sprintf(buf, "%s\n", val);
378
+ mutex_unlock(&resource->lock);
379
+ return ret;
390380 }
391381
392382 static ssize_t show_val(struct device *dev,
....@@ -638,12 +628,12 @@
638628
639629 while (attrs->label) {
640630 sensors->dev_attr.attr.name = attrs->label;
641
- sensors->dev_attr.attr.mode = S_IRUGO;
631
+ sensors->dev_attr.attr.mode = 0444;
642632 sensors->dev_attr.show = attrs->show;
643633 sensors->index = attrs->index;
644634
645635 if (attrs->set) {
646
- sensors->dev_attr.attr.mode |= S_IWUSR;
636
+ sensors->dev_attr.attr.mode |= 0200;
647637 sensors->dev_attr.store = attrs->set;
648638 }
649639
....@@ -830,11 +820,12 @@
830820
831821 resource = acpi_driver_data(device);
832822
833
- mutex_lock(&resource->lock);
834823 switch (event) {
835824 case METER_NOTIFY_CONFIG:
825
+ mutex_lock(&resource->lock);
836826 free_capabilities(resource);
837827 res = read_capabilities(resource);
828
+ mutex_unlock(&resource->lock);
838829 if (res)
839830 break;
840831
....@@ -843,15 +834,12 @@
843834 break;
844835 case METER_NOTIFY_TRIP:
845836 sysfs_notify(&device->dev.kobj, NULL, POWER_AVERAGE_NAME);
846
- update_meter(resource);
847837 break;
848838 case METER_NOTIFY_CAP:
849839 sysfs_notify(&device->dev.kobj, NULL, POWER_CAP_NAME);
850
- update_cap(resource);
851840 break;
852841 case METER_NOTIFY_INTERVAL:
853842 sysfs_notify(&device->dev.kobj, NULL, POWER_AVG_INTERVAL_NAME);
854
- update_avg_interval(resource);
855843 break;
856844 case METER_NOTIFY_CAPPING:
857845 sysfs_notify(&device->dev.kobj, NULL, POWER_ALARM_NAME);
....@@ -861,7 +849,6 @@
861849 WARN(1, "Unexpected event %d\n", event);
862850 break;
863851 }
864
- mutex_unlock(&resource->lock);
865852
866853 acpi_bus_generate_netlink_event(ACPI_POWER_METER_CLASS,
867854 dev_name(&device->dev), event, 0);
....@@ -927,8 +914,8 @@
927914 resource = acpi_driver_data(device);
928915 hwmon_device_unregister(resource->hwmon_dev);
929916
930
- free_capabilities(resource);
931917 remove_attrs(resource);
918
+ free_capabilities(resource);
932919
933920 kfree(resource);
934921 return 0;