Skip to content

Commit ba9aeba

Browse files
committed
Merge branches 'acpi-tad', 'acpi-fan', 'acpi-dptf' and 'acpi-tools'
Merge updates of the ACPI time and alarm device (TAD) driver, ACPI fan driver, ACPI DPTF code and an ACPI utility update for 6.19-rc1: - Improve runtime PM in the ACPI time and alarm device (TAD) driver using guard macros and rearrange code related to runtime PM in acpi_tad_remove() (Rafael Wysocki) - Add support for Microsoft fan extensions to the ACPI fan driver along with notification support and work around a 64-bit firmware bug in that driver (Armin Wolf) - Use ACPI_FREE() to free ACPI buffer in the ACPI DPTF code (Kaushlendra Kumar) - Fix a memory leak and a resource leak in the ACPI pfrut utility (Malaya Kumar Rout) * acpi-tad: ACPI: TAD: Improve runtime PM using guard macros ACPI: TAD: Rearrange runtime PM operations in acpi_tad_remove() * acpi-fan: ACPI: fan: Add support for Microsoft fan extensions ACPI: fan: Add hwmon notification support ACPI: fan: Add basic notification support ACPI: fan: Workaround for 64-bit firmware bug * acpi-dptf: ACPI: DPTF: Use ACPI_FREE() for ACPI buffer deallocation * acpi-tools: ACPI: tools: pfrut: fix memory leak and resource leak in pfrut.c
5 parents 24d268a + 58ca21d + a5c2fcd + 2f58be8 + 8974573 commit ba9aeba

6 files changed

Lines changed: 321 additions & 49 deletions

File tree

drivers/acpi/acpi_tad.c

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,18 @@ static int acpi_tad_set_real_time(struct device *dev, struct acpi_tad_rt *rt)
9090
args[0].buffer.pointer = (u8 *)rt;
9191
args[0].buffer.length = sizeof(*rt);
9292

93-
pm_runtime_get_sync(dev);
93+
ACQUIRE(pm_runtime_active_try, pm)(dev);
94+
if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
95+
return -ENXIO;
9496

9597
status = acpi_evaluate_integer(handle, "_SRT", &arg_list, &retval);
96-
97-
pm_runtime_put_sync(dev);
98-
9998
if (ACPI_FAILURE(status) || retval)
10099
return -EIO;
101100

102101
return 0;
103102
}
104103

105-
static int acpi_tad_get_real_time(struct device *dev, struct acpi_tad_rt *rt)
104+
static int acpi_tad_evaluate_grt(struct device *dev, struct acpi_tad_rt *rt)
106105
{
107106
acpi_handle handle = ACPI_HANDLE(dev);
108107
struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER };
@@ -111,12 +110,7 @@ static int acpi_tad_get_real_time(struct device *dev, struct acpi_tad_rt *rt)
111110
acpi_status status;
112111
int ret = -EIO;
113112

114-
pm_runtime_get_sync(dev);
115-
116113
status = acpi_evaluate_object(handle, "_GRT", NULL, &output);
117-
118-
pm_runtime_put_sync(dev);
119-
120114
if (ACPI_FAILURE(status))
121115
goto out_free;
122116

@@ -139,6 +133,21 @@ static int acpi_tad_get_real_time(struct device *dev, struct acpi_tad_rt *rt)
139133
return ret;
140134
}
141135

136+
static int acpi_tad_get_real_time(struct device *dev, struct acpi_tad_rt *rt)
137+
{
138+
int ret;
139+
140+
ACQUIRE(pm_runtime_active_try, pm)(dev);
141+
if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
142+
return -ENXIO;
143+
144+
ret = acpi_tad_evaluate_grt(dev, rt);
145+
if (ret)
146+
return ret;
147+
148+
return 0;
149+
}
150+
142151
static char *acpi_tad_rt_next_field(char *s, int *val)
143152
{
144153
char *p;
@@ -266,12 +275,11 @@ static int acpi_tad_wake_set(struct device *dev, char *method, u32 timer_id,
266275
args[0].integer.value = timer_id;
267276
args[1].integer.value = value;
268277

269-
pm_runtime_get_sync(dev);
278+
ACQUIRE(pm_runtime_active_try, pm)(dev);
279+
if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
280+
return -ENXIO;
270281

271282
status = acpi_evaluate_integer(handle, method, &arg_list, &retval);
272-
273-
pm_runtime_put_sync(dev);
274-
275283
if (ACPI_FAILURE(status) || retval)
276284
return -EIO;
277285

@@ -314,12 +322,11 @@ static ssize_t acpi_tad_wake_read(struct device *dev, char *buf, char *method,
314322

315323
args[0].integer.value = timer_id;
316324

317-
pm_runtime_get_sync(dev);
325+
ACQUIRE(pm_runtime_active_try, pm)(dev);
326+
if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
327+
return -ENXIO;
318328

319329
status = acpi_evaluate_integer(handle, method, &arg_list, &retval);
320-
321-
pm_runtime_put_sync(dev);
322-
323330
if (ACPI_FAILURE(status))
324331
return -EIO;
325332

@@ -370,12 +377,11 @@ static int acpi_tad_clear_status(struct device *dev, u32 timer_id)
370377

371378
args[0].integer.value = timer_id;
372379

373-
pm_runtime_get_sync(dev);
380+
ACQUIRE(pm_runtime_active_try, pm)(dev);
381+
if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
382+
return -ENXIO;
374383

375384
status = acpi_evaluate_integer(handle, "_CWS", &arg_list, &retval);
376-
377-
pm_runtime_put_sync(dev);
378-
379385
if (ACPI_FAILURE(status) || retval)
380386
return -EIO;
381387

@@ -411,12 +417,11 @@ static ssize_t acpi_tad_status_read(struct device *dev, char *buf, u32 timer_id)
411417

412418
args[0].integer.value = timer_id;
413419

414-
pm_runtime_get_sync(dev);
420+
ACQUIRE(pm_runtime_active_try, pm)(dev);
421+
if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
422+
return -ENXIO;
415423

416424
status = acpi_evaluate_integer(handle, "_GWS", &arg_list, &retval);
417-
418-
pm_runtime_put_sync(dev);
419-
420425
if (ACPI_FAILURE(status))
421426
return -EIO;
422427

@@ -563,8 +568,6 @@ static void acpi_tad_remove(struct platform_device *pdev)
563568

564569
device_init_wakeup(dev, false);
565570

566-
pm_runtime_get_sync(dev);
567-
568571
if (dd->capabilities & ACPI_TAD_RT)
569572
sysfs_remove_group(&dev->kobj, &acpi_tad_time_attr_group);
570573

@@ -573,14 +576,16 @@ static void acpi_tad_remove(struct platform_device *pdev)
573576

574577
sysfs_remove_group(&dev->kobj, &acpi_tad_attr_group);
575578

576-
acpi_tad_disable_timer(dev, ACPI_TAD_AC_TIMER);
577-
acpi_tad_clear_status(dev, ACPI_TAD_AC_TIMER);
578-
if (dd->capabilities & ACPI_TAD_DC_WAKE) {
579-
acpi_tad_disable_timer(dev, ACPI_TAD_DC_TIMER);
580-
acpi_tad_clear_status(dev, ACPI_TAD_DC_TIMER);
579+
scoped_guard(pm_runtime_noresume, dev) {
580+
acpi_tad_disable_timer(dev, ACPI_TAD_AC_TIMER);
581+
acpi_tad_clear_status(dev, ACPI_TAD_AC_TIMER);
582+
if (dd->capabilities & ACPI_TAD_DC_WAKE) {
583+
acpi_tad_disable_timer(dev, ACPI_TAD_DC_TIMER);
584+
acpi_tad_clear_status(dev, ACPI_TAD_DC_TIMER);
585+
}
581586
}
582587

583-
pm_runtime_put_sync(dev);
588+
pm_runtime_suspend(dev);
584589
pm_runtime_disable(dev);
585590
acpi_remove_cmos_rtc_space_handler(handle);
586591
}

drivers/acpi/dptf/dptf_pch_fivr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static int pch_fivr_read(acpi_handle handle, char *method, struct pch_fivr_resp
4141
ret = 0;
4242

4343
release_buffer:
44-
kfree(buffer.pointer);
44+
ACPI_FREE(buffer.pointer);
4545
return ret;
4646
}
4747

drivers/acpi/fan.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define _ACPI_FAN_H_
1212

1313
#include <linux/kconfig.h>
14+
#include <linux/limits.h>
1415

1516
#define ACPI_FAN_DEVICE_IDS \
1617
{"INT3404", }, /* Fan */ \
@@ -55,19 +56,58 @@ struct acpi_fan {
5556
struct acpi_fan_fif fif;
5657
struct acpi_fan_fps *fps;
5758
int fps_count;
59+
/* A value of 0 means that trippoint-related functions are not supported */
60+
u32 fan_trip_granularity;
61+
#if IS_REACHABLE(CONFIG_HWMON)
62+
struct device *hdev;
63+
#endif
5864
struct thermal_cooling_device *cdev;
5965
struct device_attribute fst_speed;
6066
struct device_attribute fine_grain_control;
6167
};
6268

69+
/**
70+
* acpi_fan_speed_valid - Check if fan speed value is valid
71+
* @speeed: Speed value returned by the ACPI firmware
72+
*
73+
* Check if the fan speed value returned by the ACPI firmware is valid. This function is
74+
* necessary as ACPI firmware implementations can return 0xFFFFFFFF to signal that the
75+
* ACPI fan does not support speed reporting. Additionally, some buggy ACPI firmware
76+
* implementations return a value larger than the 32-bit integer value defined by
77+
* the ACPI specification when using placeholder values. Such invalid values are also
78+
* detected by this function.
79+
*
80+
* Returns: True if the fan speed value is valid, false otherwise.
81+
*/
82+
static inline bool acpi_fan_speed_valid(u64 speed)
83+
{
84+
return speed < U32_MAX;
85+
}
86+
87+
/**
88+
* acpi_fan_power_valid - Check if fan power value is valid
89+
* @power: Power value returned by the ACPI firmware
90+
*
91+
* Check if the fan power value returned by the ACPI firmware is valid.
92+
* See acpi_fan_speed_valid() for details.
93+
*
94+
* Returns: True if the fan power value is valid, false otherwise.
95+
*/
96+
static inline bool acpi_fan_power_valid(u64 power)
97+
{
98+
return power < U32_MAX;
99+
}
100+
63101
int acpi_fan_get_fst(acpi_handle handle, struct acpi_fan_fst *fst);
64102
int acpi_fan_create_attributes(struct acpi_device *device);
65103
void acpi_fan_delete_attributes(struct acpi_device *device);
66104

67105
#if IS_REACHABLE(CONFIG_HWMON)
68106
int devm_acpi_fan_create_hwmon(struct device *dev);
107+
void acpi_fan_notify_hwmon(struct device *dev);
69108
#else
70109
static inline int devm_acpi_fan_create_hwmon(struct device *dev) { return 0; };
110+
static inline void acpi_fan_notify_hwmon(struct device *dev) { };
71111
#endif
72112

73113
#endif

0 commit comments

Comments
 (0)