* [PATCH v3 0/2] ACPI: TAD: Use auto-cleanup macros for runtime PM
@ 2025-10-21 17:32 Rafael J. Wysocki
2025-10-21 17:33 ` [PATCH v3 1/2] ACPI: TAD: Rearrange runtime PM operations in acpi_tad_remove() Rafael J. Wysocki
2025-10-21 17:35 ` [PATCH v3 2/2] ACPI: TAD: Improve runtime PM using guard macros Rafael J. Wysocki
0 siblings, 2 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2025-10-21 17:32 UTC (permalink / raw)
To: Linux ACPI
Cc: Linux PM, Jonathan Cameron, Takashi Iwai, LKML, Zhang Qilong,
Frank Li, Dhruva Gole, Mika Westerberg, Dan Williams
Hi All,
This supersedes
https://lore.kernel.org/linux-acpi/8599731.T7Z3S40VBb@rafael.j.wysocki/
that had a kind of an issue in the second patch. Namely, ACQUIRE()/ACQUIRE_ERR()
were used along with gotos in one function.
This addresses the problem by introducing an auxiliary function to separate
the two mechanisms.
The first patch has not been changed.
Thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v3 1/2] ACPI: TAD: Rearrange runtime PM operations in acpi_tad_remove()
2025-10-21 17:32 [PATCH v3 0/2] ACPI: TAD: Use auto-cleanup macros for runtime PM Rafael J. Wysocki
@ 2025-10-21 17:33 ` Rafael J. Wysocki
2025-10-21 17:35 ` [PATCH v3 2/2] ACPI: TAD: Improve runtime PM using guard macros Rafael J. Wysocki
1 sibling, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2025-10-21 17:33 UTC (permalink / raw)
To: Linux ACPI
Cc: Linux PM, Jonathan Cameron, Takashi Iwai, LKML, Zhang Qilong,
Frank Li, Dhruva Gole, Mika Westerberg, Dan Williams
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Subject: [PATCH v1]
It is not necessary to resume the device upfront in acpi_tad_remove()
because both acpi_tad_disable_timer() and acpi_tad_clear_status()
attempt to resume it, but it is better to prevent it from suspending
between these calls by incrementing its runtime PM usage counter.
Accordingly, replace the pm_runtime_get_sync() call in acpi_tad_remove()
with a pm_runtime_get_noresume() one and put the latter right before the
first invocation of acpi_tad_disable_timer().
In addition, use pm_runtime_put_noidle() to drop the device's runtime
PM usage counter after using pm_runtime_get_noresume() to bump it up
to follow a common pattern and use pm_runtime_suspend() for suspending
the device afterward.
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
v1 -> v3: No changes
---
drivers/acpi/acpi_tad.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
--- a/drivers/acpi/acpi_tad.c
+++ b/drivers/acpi/acpi_tad.c
@@ -563,8 +563,6 @@ static void acpi_tad_remove(struct platf
device_init_wakeup(dev, false);
- pm_runtime_get_sync(dev);
-
if (dd->capabilities & ACPI_TAD_RT)
sysfs_remove_group(&dev->kobj, &acpi_tad_time_attr_group);
@@ -573,6 +571,8 @@ static void acpi_tad_remove(struct platf
sysfs_remove_group(&dev->kobj, &acpi_tad_attr_group);
+ pm_runtime_get_noresume(dev);
+
acpi_tad_disable_timer(dev, ACPI_TAD_AC_TIMER);
acpi_tad_clear_status(dev, ACPI_TAD_AC_TIMER);
if (dd->capabilities & ACPI_TAD_DC_WAKE) {
@@ -580,7 +580,8 @@ static void acpi_tad_remove(struct platf
acpi_tad_clear_status(dev, ACPI_TAD_DC_TIMER);
}
- pm_runtime_put_sync(dev);
+ pm_runtime_put_noidle(dev);
+ pm_runtime_suspend(dev);
pm_runtime_disable(dev);
acpi_remove_cmos_rtc_space_handler(handle);
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v3 2/2] ACPI: TAD: Improve runtime PM using guard macros
2025-10-21 17:32 [PATCH v3 0/2] ACPI: TAD: Use auto-cleanup macros for runtime PM Rafael J. Wysocki
2025-10-21 17:33 ` [PATCH v3 1/2] ACPI: TAD: Rearrange runtime PM operations in acpi_tad_remove() Rafael J. Wysocki
@ 2025-10-21 17:35 ` Rafael J. Wysocki
2025-10-22 10:14 ` Jonathan Cameron
1 sibling, 1 reply; 4+ messages in thread
From: Rafael J. Wysocki @ 2025-10-21 17:35 UTC (permalink / raw)
To: Linux ACPI
Cc: Linux PM, Jonathan Cameron, Takashi Iwai, LKML, Zhang Qilong,
Frank Li, Dhruva Gole, Mika Westerberg, Dan Williams
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Use guard pm_runtime_active_try to simplify runtime PM cleanup and
implement runtime resume error handling in multiple places.
Also use guard pm_runtime_noresume to simplify acpi_tad_remove().
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
v2 -> v3: Introduce a helper function to avoid using goto statements along
with cleanup.h macros in one function (Jonathan).
v1 -> v2: Rebase after dropping the first patch in the series.
---
drivers/acpi/acpi_tad.c | 72 +++++++++++++++++++++++++-----------------------
1 file changed, 38 insertions(+), 34 deletions(-)
--- a/drivers/acpi/acpi_tad.c
+++ b/drivers/acpi/acpi_tad.c
@@ -90,19 +90,18 @@ static int acpi_tad_set_real_time(struct
args[0].buffer.pointer = (u8 *)rt;
args[0].buffer.length = sizeof(*rt);
- pm_runtime_get_sync(dev);
+ ACQUIRE(pm_runtime_active_try, pm)(dev);
+ if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
+ return -ENXIO;
status = acpi_evaluate_integer(handle, "_SRT", &arg_list, &retval);
-
- pm_runtime_put_sync(dev);
-
if (ACPI_FAILURE(status) || retval)
return -EIO;
return 0;
}
-static int acpi_tad_get_real_time(struct device *dev, struct acpi_tad_rt *rt)
+static int acpi_tad_evaluate_grt(struct device *dev, struct acpi_tad_rt *rt)
{
acpi_handle handle = ACPI_HANDLE(dev);
struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER };
@@ -111,12 +110,7 @@ static int acpi_tad_get_real_time(struct
acpi_status status;
int ret = -EIO;
- pm_runtime_get_sync(dev);
-
status = acpi_evaluate_object(handle, "_GRT", NULL, &output);
-
- pm_runtime_put_sync(dev);
-
if (ACPI_FAILURE(status))
goto out_free;
@@ -139,6 +133,21 @@ out_free:
return ret;
}
+static int acpi_tad_get_real_time(struct device *dev, struct acpi_tad_rt *rt)
+{
+ int ret;
+
+ ACQUIRE(pm_runtime_active_try, pm)(dev);
+ if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
+ return -ENXIO;
+
+ ret = acpi_tad_evaluate_grt(dev, rt);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
static char *acpi_tad_rt_next_field(char *s, int *val)
{
char *p;
@@ -266,12 +275,11 @@ static int acpi_tad_wake_set(struct devi
args[0].integer.value = timer_id;
args[1].integer.value = value;
- pm_runtime_get_sync(dev);
+ ACQUIRE(pm_runtime_active_try, pm)(dev);
+ if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
+ return -ENXIO;
status = acpi_evaluate_integer(handle, method, &arg_list, &retval);
-
- pm_runtime_put_sync(dev);
-
if (ACPI_FAILURE(status) || retval)
return -EIO;
@@ -314,12 +322,11 @@ static ssize_t acpi_tad_wake_read(struct
args[0].integer.value = timer_id;
- pm_runtime_get_sync(dev);
+ ACQUIRE(pm_runtime_active_try, pm)(dev);
+ if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
+ return -ENXIO;
status = acpi_evaluate_integer(handle, method, &arg_list, &retval);
-
- pm_runtime_put_sync(dev);
-
if (ACPI_FAILURE(status))
return -EIO;
@@ -370,12 +377,11 @@ static int acpi_tad_clear_status(struct
args[0].integer.value = timer_id;
- pm_runtime_get_sync(dev);
+ ACQUIRE(pm_runtime_active_try, pm)(dev);
+ if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
+ return -ENXIO;
status = acpi_evaluate_integer(handle, "_CWS", &arg_list, &retval);
-
- pm_runtime_put_sync(dev);
-
if (ACPI_FAILURE(status) || retval)
return -EIO;
@@ -411,12 +417,11 @@ static ssize_t acpi_tad_status_read(stru
args[0].integer.value = timer_id;
- pm_runtime_get_sync(dev);
+ ACQUIRE(pm_runtime_active_try, pm)(dev);
+ if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
+ return -ENXIO;
status = acpi_evaluate_integer(handle, "_GWS", &arg_list, &retval);
-
- pm_runtime_put_sync(dev);
-
if (ACPI_FAILURE(status))
return -EIO;
@@ -571,16 +576,15 @@ static void acpi_tad_remove(struct platf
sysfs_remove_group(&dev->kobj, &acpi_tad_attr_group);
- pm_runtime_get_noresume(dev);
-
- acpi_tad_disable_timer(dev, ACPI_TAD_AC_TIMER);
- acpi_tad_clear_status(dev, ACPI_TAD_AC_TIMER);
- if (dd->capabilities & ACPI_TAD_DC_WAKE) {
- acpi_tad_disable_timer(dev, ACPI_TAD_DC_TIMER);
- acpi_tad_clear_status(dev, ACPI_TAD_DC_TIMER);
+ scoped_guard(pm_runtime_noresume, dev) {
+ acpi_tad_disable_timer(dev, ACPI_TAD_AC_TIMER);
+ acpi_tad_clear_status(dev, ACPI_TAD_AC_TIMER);
+ if (dd->capabilities & ACPI_TAD_DC_WAKE) {
+ acpi_tad_disable_timer(dev, ACPI_TAD_DC_TIMER);
+ acpi_tad_clear_status(dev, ACPI_TAD_DC_TIMER);
+ }
}
- pm_runtime_put_noidle(dev);
pm_runtime_suspend(dev);
pm_runtime_disable(dev);
acpi_remove_cmos_rtc_space_handler(handle);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3 2/2] ACPI: TAD: Improve runtime PM using guard macros
2025-10-21 17:35 ` [PATCH v3 2/2] ACPI: TAD: Improve runtime PM using guard macros Rafael J. Wysocki
@ 2025-10-22 10:14 ` Jonathan Cameron
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2025-10-22 10:14 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: Linux ACPI, Linux PM, Takashi Iwai, LKML, Zhang Qilong, Frank Li,
Dhruva Gole, Mika Westerberg, Dan Williams
On Tue, 21 Oct 2025 19:35:54 +0200
"Rafael J. Wysocki" <rafael@kernel.org> wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Use guard pm_runtime_active_try to simplify runtime PM cleanup and
> implement runtime resume error handling in multiple places.
>
> Also use guard pm_runtime_noresume to simplify acpi_tad_remove().
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-10-22 10:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-21 17:32 [PATCH v3 0/2] ACPI: TAD: Use auto-cleanup macros for runtime PM Rafael J. Wysocki
2025-10-21 17:33 ` [PATCH v3 1/2] ACPI: TAD: Rearrange runtime PM operations in acpi_tad_remove() Rafael J. Wysocki
2025-10-21 17:35 ` [PATCH v3 2/2] ACPI: TAD: Improve runtime PM using guard macros Rafael J. Wysocki
2025-10-22 10:14 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).