From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Linux PM <linux-pm@vger.kernel.org>
Cc: Jonathan Cameron <jonathan.cameron@huawei.com>,
Takashi Iwai <tiwai@suse.de>, LKML <linux-kernel@vger.kernel.org>,
Linux PCI <linux-pci@vger.kernel.org>,
Alex Williamson <alex.williamson@redhat.com>,
Bjorn Helgaas <helgaas@kernel.org>,
Zhang Qilong <zhangqilong3@huawei.com>,
Ulf Hansson <ulf.hansson@linaro.org>, Frank Li <Frank.Li@nxp.com>,
Dhruva Gole <d-gole@ti.com>,
Mika Westerberg <mika.westerberg@linux.intel.com>,
Linux ACPI <linux-acpi@vger.kernel.org>
Subject: [PATCH v1 1/3] PM: runtime: Introduce PM_RUNTIME_ACQUIRE_OR_FAIL() macro
Date: Wed, 15 Oct 2025 16:02:02 +0200 [thread overview]
Message-ID: <3324926.5fSG56mABF@rafael.j.wysocki> (raw)
In-Reply-To: <3925484.kQq0lBPeGt@rafael.j.wysocki>
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
There appears to be an emerging pattern in which guard
pm_runtime_active_try is used for resuming the given device and
incrementing its runtime PM usage counter if the resume has been
successful, that is followed by an ACQUIRE_ERR() check on the guard
variable and if that triggers, a specific error code is returned, for
example:
ACQUIRE(pm_runtime_active_try, pm)(dev);
if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
return -ENXIO
Introduce a macro called PM_RUNTIME_ACQUIRE_OR_FAIL() representing the
above sequence of statements that can be used to avoid code duplication
wherever that sequence would be used.
Use this macro right away in the PCI sysfs code where the above pattern
is already present.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
Admittedly, the new macro is slightly on the edge, but it really helps
reduce code duplication, so here it goes.
Any feedback (good, bad, ugly) will be appreciated.
Thanks!
---
drivers/pci/pci-sysfs.c | 4 +---
include/linux/pm_runtime.h | 5 +++++
2 files changed, 6 insertions(+), 3 deletions(-)
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1517,9 +1517,7 @@ static ssize_t reset_method_store(struct
return count;
}
- ACQUIRE(pm_runtime_active_try, pm)(dev);
- if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
- return -ENXIO;
+ PM_RUNTIME_ACQUIRE_OR_FAIL(dev, -ENXIO);
if (sysfs_streq(buf, "default")) {
pci_init_reset_methods(pdev);
--- a/include/linux/pm_runtime.h
+++ b/include/linux/pm_runtime.h
@@ -637,6 +637,11 @@ DEFINE_GUARD_COND(pm_runtime_active_auto
DEFINE_GUARD_COND(pm_runtime_active_auto, _try_enabled,
pm_runtime_resume_and_get(_T))
+#define PM_RUNTIME_ACQUIRE_OR_FAIL(dev, error) \
+ ACQUIRE(pm_runtime_active_try, __pm)(dev); \
+ if (ACQUIRE_ERR(pm_runtime_active_try, &__pm)) \
+ return error
+
/**
* pm_runtime_put_sync - Drop device usage counter and run "idle check" if 0.
* @dev: Target device.
next prev parent reply other threads:[~2025-10-15 14:05 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-15 13:59 [PATCH v1 0/3] PM: runtimePCI/ACPI: TAD: Auto-cleanup macros for runtime PM Rafael J. Wysocki
2025-10-15 14:02 ` Rafael J. Wysocki [this message]
2025-10-16 12:38 ` [PATCH v1 1/3] PM: runtime: Introduce PM_RUNTIME_ACQUIRE_OR_FAIL() macro Jonathan Cameron
2025-10-16 13:46 ` Rafael J. Wysocki
2025-10-16 14:59 ` Takashi Iwai
2025-10-16 16:06 ` Rafael J. Wysocki
2025-10-16 16:46 ` David Lechner
2025-10-16 18:13 ` Takashi Iwai
2025-10-16 19:07 ` Rafael J. Wysocki
2025-10-16 19:45 ` dan.j.williams
2025-10-16 20:38 ` Rafael J. Wysocki
2025-10-16 20:58 ` dan.j.williams
2025-10-17 9:43 ` Rafael J. Wysocki
2025-10-15 14:03 ` [PATCH v1 2/3] ACPI: TAD: Rearrange runtime PM operations in acpi_tad_remove() Rafael J. Wysocki
2025-10-15 14:04 ` [PATCH v1 3/3] ACPI: TAD: Improve runtime PM using guard macros Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3324926.5fSG56mABF@rafael.j.wysocki \
--to=rafael@kernel.org \
--cc=Frank.Li@nxp.com \
--cc=alex.williamson@redhat.com \
--cc=d-gole@ti.com \
--cc=helgaas@kernel.org \
--cc=jonathan.cameron@huawei.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mika.westerberg@linux.intel.com \
--cc=tiwai@suse.de \
--cc=ulf.hansson@linaro.org \
--cc=zhangqilong3@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).