Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH v2 0/3] PM: runtime: Wrapper macros for usage counter guards
@ 2025-11-13 19:24 Rafael J. Wysocki
  2025-11-13 19:33 ` [PATCH v2 1/3] PM: runtime: Wrapper macros for ACQUIRE()/ACQUIRE_ERR() Rafael J. Wysocki
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Rafael J. Wysocki @ 2025-11-13 19:24 UTC (permalink / raw)
  To: Linux PM
  Cc: Linux ACPI, Jonathan Cameron, Takashi Iwai, LKML, Zhang Qilong,
	Frank Li, Dhruva Gole, Dan Williams, Linux PCI, Bjorn Helgaas

Hi All,

This supersedes

https://lore.kernel.org/linux-pm/13883374.uLZWGnKmhe@rafael.j.wysocki/

as discussed here:

https://lore.kernel.org/linux-pm/5068916.31r3eYUQgx@rafael.j.wysocki/

It adds runtime PM wrapper macros around ACQUIRE() and ACQUIRE_ERR() involving
the guards added recently (patch [1/3]) and then updates the code already
using those guards (patches [2/3] and [3/3]) to make it look more
straightforward.

Thanks!




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2 1/3] PM: runtime: Wrapper macros for ACQUIRE()/ACQUIRE_ERR()
  2025-11-13 19:24 [PATCH v2 0/3] PM: runtime: Wrapper macros for usage counter guards Rafael J. Wysocki
@ 2025-11-13 19:33 ` Rafael J. Wysocki
  2025-11-14  8:53   ` Dhruva Gole
  2025-11-14 20:15   ` Frank Li
  2025-11-13 19:34 ` [PATCH v2 2/3] ACPI: TAD: Use PM_RUNTIME_ACQUIRE()/PM_RUNTIME_ACQUIRE_ERR() Rafael J. Wysocki
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 11+ messages in thread
From: Rafael J. Wysocki @ 2025-11-13 19:33 UTC (permalink / raw)
  To: Linux PM
  Cc: Linux ACPI, Jonathan Cameron, Takashi Iwai, LKML, Zhang Qilong,
	Frank Li, Dhruva Gole, Dan Williams, Linux PCI, Bjorn Helgaas

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Add wrapper macros for ACQUIRE()/ACQUIRE_ERR() and runtime PM
usage counter guards introduced recently: pm_runtime_active_try,
pm_runtime_active_auto_try, pm_runtime_active_try_enabled, and
pm_runtime_active_auto_try_enabled.

The new macros should be more straightforward to use.

For example, they can be used for rewriting a piece of code like below:

        ACQUIRE(pm_runtime_active_try, pm)(dev);
        if ((ret = ACQUIRE_ERR(pm_runtime_active_try, &pm)))
                return ret;

in the following way:

        PM_RUNTIME_ACQUIRE(dev, pm);
        if ((ret = PM_RUNTIME_ACQUIRE_ERR(&pm)))
                return ret;

If the original code does not care about the specific error code
returned when attepmting to resume the device:

        ACQUIRE(pm_runtime_active_try, pm)(dev);
        if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
                return -ENXIO;

it may be changed like this:

        PM_RUNTIME_ACQUIRE(dev, pm);
        if (PM_RUNTIME_ACQUIRE_ERR(&pm))
                return -ENXIO;

Link: https://lore.kernel.org/linux-pm/5068916.31r3eYUQgx@rafael.j.wysocki/
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
---

v1 -> v2:
   * The new macros take the guard variable name as a parameter.
   * The new ERR macro takes a guard variable pointer as a parameter (Dan).
   * Added underscore prefix to the macro parameter names.

---
 include/linux/pm_runtime.h |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

--- a/include/linux/pm_runtime.h
+++ b/include/linux/pm_runtime.h
@@ -637,6 +637,30 @@ DEFINE_GUARD_COND(pm_runtime_active_auto
 DEFINE_GUARD_COND(pm_runtime_active_auto, _try_enabled,
 		  pm_runtime_resume_and_get(_T), _RET == 0)
 
+/* ACQUIRE() wrapper macros for the guards defined above. */
+
+#define PM_RUNTIME_ACQUIRE(_dev, _var)			\
+	ACQUIRE(pm_runtime_active_try, _var)(_dev)
+
+#define PM_RUNTIME_ACQUIRE_AUTOSUSPEND(_dev, _var)	\
+	ACQUIRE(pm_runtime_active_auto_try, _var)(_dev)
+
+#define PM_RUNTIME_ACQUIRE_IF_ENABLED(_dev, _var)	\
+	ACQUIRE(pm_runtime_active_try_enabled, _var)(_dev)
+
+#define PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND(_dev, _var)	\
+	ACQUIRE(pm_runtime_active_auto_try_enabled, _var)(_dev)
+
+/*
+ * ACQUIRE_ERR() wrapper macro for guard pm_runtime_active.
+ *
+ * Always check PM_RUNTIME_ACQUIRE_ERR() after using one of the
+ * PM_RUNTIME_ACQUIRE*() macros defined above (yes, it can be used with
+ * any of them) and if it is nonzero, avoid accessing the given device.
+ */
+#define PM_RUNTIME_ACQUIRE_ERR(_var_ptr)	\
+	ACQUIRE_ERR(pm_runtime_active, _var_ptr)
+
 /**
  * pm_runtime_put_sync - Drop device usage counter and run "idle check" if 0.
  * @dev: Target device.




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2 2/3] ACPI: TAD: Use PM_RUNTIME_ACQUIRE()/PM_RUNTIME_ACQUIRE_ERR()
  2025-11-13 19:24 [PATCH v2 0/3] PM: runtime: Wrapper macros for usage counter guards Rafael J. Wysocki
  2025-11-13 19:33 ` [PATCH v2 1/3] PM: runtime: Wrapper macros for ACQUIRE()/ACQUIRE_ERR() Rafael J. Wysocki
@ 2025-11-13 19:34 ` Rafael J. Wysocki
  2025-11-14  9:02   ` Dhruva Gole
  2025-11-13 19:35 ` [PATCH v2 3/3] PCI/sysfs: " Rafael J. Wysocki
  2025-11-14 13:10 ` [PATCH v2 0/3] PM: runtime: Wrapper macros for usage counter guards Jonathan Cameron
  3 siblings, 1 reply; 11+ messages in thread
From: Rafael J. Wysocki @ 2025-11-13 19:34 UTC (permalink / raw)
  To: Linux PM
  Cc: Linux ACPI, Jonathan Cameron, Takashi Iwai, LKML, Zhang Qilong,
	Frank Li, Dhruva Gole, Dan Williams, Linux PCI, Bjorn Helgaas

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Use new PM_RUNTIME_ACQUIRE() and PM_RUNTIME_ACQUIRE_ERR() wrapper macros
to make the code look more straightforward.

No intentional funtional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

v1 -> v2: Adjust to the changes in patch [1/3].

---
 drivers/acpi/acpi_tad.c |   24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

--- a/drivers/acpi/acpi_tad.c
+++ b/drivers/acpi/acpi_tad.c
@@ -90,8 +90,8 @@ static int acpi_tad_set_real_time(struct
 	args[0].buffer.pointer = (u8 *)rt;
 	args[0].buffer.length = sizeof(*rt);
 
-	ACQUIRE(pm_runtime_active_try, pm)(dev);
-	if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
+	PM_RUNTIME_ACQUIRE(dev, pm);
+	if (PM_RUNTIME_ACQUIRE_ERR(&pm))
 		return -ENXIO;
 
 	status = acpi_evaluate_integer(handle, "_SRT", &arg_list, &retval);
@@ -137,8 +137,8 @@ static int acpi_tad_get_real_time(struct
 {
 	int ret;
 
-	ACQUIRE(pm_runtime_active_try, pm)(dev);
-	if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
+	PM_RUNTIME_ACQUIRE(dev, pm);
+	if (PM_RUNTIME_ACQUIRE_ERR(&pm))
 		return -ENXIO;
 
 	ret = acpi_tad_evaluate_grt(dev, rt);
@@ -275,8 +275,8 @@ static int acpi_tad_wake_set(struct devi
 	args[0].integer.value = timer_id;
 	args[1].integer.value = value;
 
-	ACQUIRE(pm_runtime_active_try, pm)(dev);
-	if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
+	PM_RUNTIME_ACQUIRE(dev, pm);
+	if (PM_RUNTIME_ACQUIRE_ERR(&pm))
 		return -ENXIO;
 
 	status = acpi_evaluate_integer(handle, method, &arg_list, &retval);
@@ -322,8 +322,8 @@ static ssize_t acpi_tad_wake_read(struct
 
 	args[0].integer.value = timer_id;
 
-	ACQUIRE(pm_runtime_active_try, pm)(dev);
-	if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
+	PM_RUNTIME_ACQUIRE(dev, pm);
+	if (PM_RUNTIME_ACQUIRE_ERR(&pm))
 		return -ENXIO;
 
 	status = acpi_evaluate_integer(handle, method, &arg_list, &retval);
@@ -377,8 +377,8 @@ static int acpi_tad_clear_status(struct
 
 	args[0].integer.value = timer_id;
 
-	ACQUIRE(pm_runtime_active_try, pm)(dev);
-	if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
+	PM_RUNTIME_ACQUIRE(dev, pm);
+	if (PM_RUNTIME_ACQUIRE_ERR(&pm))
 		return -ENXIO;
 
 	status = acpi_evaluate_integer(handle, "_CWS", &arg_list, &retval);
@@ -417,8 +417,8 @@ static ssize_t acpi_tad_status_read(stru
 
 	args[0].integer.value = timer_id;
 
-	ACQUIRE(pm_runtime_active_try, pm)(dev);
-	if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
+	PM_RUNTIME_ACQUIRE(dev, pm);
+	if (PM_RUNTIME_ACQUIRE_ERR(&pm))
 		return -ENXIO;
 
 	status = acpi_evaluate_integer(handle, "_GWS", &arg_list, &retval);




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2 3/3] PCI/sysfs: Use PM_RUNTIME_ACQUIRE()/PM_RUNTIME_ACQUIRE_ERR()
  2025-11-13 19:24 [PATCH v2 0/3] PM: runtime: Wrapper macros for usage counter guards Rafael J. Wysocki
  2025-11-13 19:33 ` [PATCH v2 1/3] PM: runtime: Wrapper macros for ACQUIRE()/ACQUIRE_ERR() Rafael J. Wysocki
  2025-11-13 19:34 ` [PATCH v2 2/3] ACPI: TAD: Use PM_RUNTIME_ACQUIRE()/PM_RUNTIME_ACQUIRE_ERR() Rafael J. Wysocki
@ 2025-11-13 19:35 ` Rafael J. Wysocki
  2025-11-14  9:02   ` Dhruva Gole
  2025-11-14 13:10 ` [PATCH v2 0/3] PM: runtime: Wrapper macros for usage counter guards Jonathan Cameron
  3 siblings, 1 reply; 11+ messages in thread
From: Rafael J. Wysocki @ 2025-11-13 19:35 UTC (permalink / raw)
  To: Linux PM
  Cc: Linux ACPI, Jonathan Cameron, Takashi Iwai, LKML, Zhang Qilong,
	Frank Li, Dhruva Gole, Dan Williams, Linux PCI, Bjorn Helgaas

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Use new PM_RUNTIME_ACQUIRE() and PM_RUNTIME_ACQUIRE_ERR() wrapper macros
to make the code look more straightforward.

No intentional funtional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

v1 -> v2: Adjust to the changes in patch [1/3].

---
 drivers/pci/pci-sysfs.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1517,8 +1517,8 @@ static ssize_t reset_method_store(struct
 		return count;
 	}
 
-	ACQUIRE(pm_runtime_active_try, pm)(dev);
-	if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
+	PM_RUNTIME_ACQUIRE(dev, pm);
+	if (PM_RUNTIME_ACQUIRE_ERR(&pm))
 		return -ENXIO;
 
 	if (sysfs_streq(buf, "default")) {




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/3] PM: runtime: Wrapper macros for ACQUIRE()/ACQUIRE_ERR()
  2025-11-13 19:33 ` [PATCH v2 1/3] PM: runtime: Wrapper macros for ACQUIRE()/ACQUIRE_ERR() Rafael J. Wysocki
@ 2025-11-14  8:53   ` Dhruva Gole
  2025-11-14 20:15   ` Frank Li
  1 sibling, 0 replies; 11+ messages in thread
From: Dhruva Gole @ 2025-11-14  8:53 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM, Linux ACPI, Jonathan Cameron, Takashi Iwai, LKML,
	Zhang Qilong, Frank Li, Dan Williams, Linux PCI, Bjorn Helgaas

On Nov 13, 2025 at 20:33:33 +0100, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Add wrapper macros for ACQUIRE()/ACQUIRE_ERR() and runtime PM
> usage counter guards introduced recently: pm_runtime_active_try,
> pm_runtime_active_auto_try, pm_runtime_active_try_enabled, and
> pm_runtime_active_auto_try_enabled.
> 
> The new macros should be more straightforward to use.
> 
> For example, they can be used for rewriting a piece of code like below:
> 
>         ACQUIRE(pm_runtime_active_try, pm)(dev);
>         if ((ret = ACQUIRE_ERR(pm_runtime_active_try, &pm)))
>                 return ret;
> 
> in the following way:
> 
>         PM_RUNTIME_ACQUIRE(dev, pm);
>         if ((ret = PM_RUNTIME_ACQUIRE_ERR(&pm)))
>                 return ret;
> 
> If the original code does not care about the specific error code
> returned when attepmting to resume the device:
> 
>         ACQUIRE(pm_runtime_active_try, pm)(dev);
>         if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
>                 return -ENXIO;
> 
> it may be changed like this:
> 
>         PM_RUNTIME_ACQUIRE(dev, pm);
>         if (PM_RUNTIME_ACQUIRE_ERR(&pm))
>                 return -ENXIO;
> 
> Link: https://lore.kernel.org/linux-pm/5068916.31r3eYUQgx@rafael.j.wysocki/
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Reviewed-by: Dan Williams <dan.j.williams@intel.com>
> ---
> 
> v1 -> v2:
>    * The new macros take the guard variable name as a parameter.
>    * The new ERR macro takes a guard variable pointer as a parameter (Dan).
>    * Added underscore prefix to the macro parameter names.
> 
> ---
>  include/linux/pm_runtime.h |   24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
> 
> --- a/include/linux/pm_runtime.h
> +++ b/include/linux/pm_runtime.h
> @@ -637,6 +637,30 @@ DEFINE_GUARD_COND(pm_runtime_active_auto
>  DEFINE_GUARD_COND(pm_runtime_active_auto, _try_enabled,
>  		  pm_runtime_resume_and_get(_T), _RET == 0)
>  
> +/* ACQUIRE() wrapper macros for the guards defined above. */
> +
> +#define PM_RUNTIME_ACQUIRE(_dev, _var)			\
> +	ACQUIRE(pm_runtime_active_try, _var)(_dev)
> +
> +#define PM_RUNTIME_ACQUIRE_AUTOSUSPEND(_dev, _var)	\
> +	ACQUIRE(pm_runtime_active_auto_try, _var)(_dev)
> +
> +#define PM_RUNTIME_ACQUIRE_IF_ENABLED(_dev, _var)	\
> +	ACQUIRE(pm_runtime_active_try_enabled, _var)(_dev)
> +
> +#define PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND(_dev, _var)	\
> +	ACQUIRE(pm_runtime_active_auto_try_enabled, _var)(_dev)
> +
> +/*
> + * ACQUIRE_ERR() wrapper macro for guard pm_runtime_active.
> + *
> + * Always check PM_RUNTIME_ACQUIRE_ERR() after using one of the
> + * PM_RUNTIME_ACQUIRE*() macros defined above (yes, it can be used with
> + * any of them) and if it is nonzero, avoid accessing the given device.
> + */
> +#define PM_RUNTIME_ACQUIRE_ERR(_var_ptr)	\
> +	ACQUIRE_ERR(pm_runtime_active, _var_ptr)
> +

Reviewed-by: Dhruva Gole <d-gole@ti.com>

-- 
Best regards,
Dhruva Gole
Texas Instruments Incorporated

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/3] ACPI: TAD: Use PM_RUNTIME_ACQUIRE()/PM_RUNTIME_ACQUIRE_ERR()
  2025-11-13 19:34 ` [PATCH v2 2/3] ACPI: TAD: Use PM_RUNTIME_ACQUIRE()/PM_RUNTIME_ACQUIRE_ERR() Rafael J. Wysocki
@ 2025-11-14  9:02   ` Dhruva Gole
  0 siblings, 0 replies; 11+ messages in thread
From: Dhruva Gole @ 2025-11-14  9:02 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM, Linux ACPI, Jonathan Cameron, Takashi Iwai, LKML,
	Zhang Qilong, Frank Li, Dan Williams, Linux PCI, Bjorn Helgaas

On Nov 13, 2025 at 20:34:53 +0100, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Use new PM_RUNTIME_ACQUIRE() and PM_RUNTIME_ACQUIRE_ERR() wrapper macros
> to make the code look more straightforward.
> 
> No intentional funtional impact.

Nit: 'functional'

Reviewed-by: Dhruva Gole <d-gole@ti.com>

> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> 
> v1 -> v2: Adjust to the changes in patch [1/3].
> 
> ---
>  drivers/acpi/acpi_tad.c |   24 ++++++++++++------------
>  1 file changed, 12 insertions(+), 12 deletions(-)
> 
> --- a/drivers/acpi/acpi_tad.c
> +++ b/drivers/acpi/acpi_tad.c
> @@ -90,8 +90,8 @@ static int acpi_tad_set_real_time(struct
>  	args[0].buffer.pointer = (u8 *)rt;
>  	args[0].buffer.length = sizeof(*rt);
>  
> -	ACQUIRE(pm_runtime_active_try, pm)(dev);
> -	if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
> +	PM_RUNTIME_ACQUIRE(dev, pm);
> +	if (PM_RUNTIME_ACQUIRE_ERR(&pm))
>  		return -ENXIO;
>  
>  	status = acpi_evaluate_integer(handle, "_SRT", &arg_list, &retval);
> @@ -137,8 +137,8 @@ static int acpi_tad_get_real_time(struct
>  {
>  	int ret;
>  
> -	ACQUIRE(pm_runtime_active_try, pm)(dev);
> -	if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
> +	PM_RUNTIME_ACQUIRE(dev, pm);
> +	if (PM_RUNTIME_ACQUIRE_ERR(&pm))
>  		return -ENXIO;
>  
>  	ret = acpi_tad_evaluate_grt(dev, rt);
> @@ -275,8 +275,8 @@ static int acpi_tad_wake_set(struct devi
>  	args[0].integer.value = timer_id;
>  	args[1].integer.value = value;
>  
> -	ACQUIRE(pm_runtime_active_try, pm)(dev);
> -	if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
> +	PM_RUNTIME_ACQUIRE(dev, pm);
> +	if (PM_RUNTIME_ACQUIRE_ERR(&pm))
>  		return -ENXIO;
>  
>  	status = acpi_evaluate_integer(handle, method, &arg_list, &retval);
> @@ -322,8 +322,8 @@ static ssize_t acpi_tad_wake_read(struct
>  
>  	args[0].integer.value = timer_id;
>  
> -	ACQUIRE(pm_runtime_active_try, pm)(dev);
> -	if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
> +	PM_RUNTIME_ACQUIRE(dev, pm);
> +	if (PM_RUNTIME_ACQUIRE_ERR(&pm))
>  		return -ENXIO;
>  
>  	status = acpi_evaluate_integer(handle, method, &arg_list, &retval);
> @@ -377,8 +377,8 @@ static int acpi_tad_clear_status(struct
>  
>  	args[0].integer.value = timer_id;
>  
> -	ACQUIRE(pm_runtime_active_try, pm)(dev);
> -	if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
> +	PM_RUNTIME_ACQUIRE(dev, pm);
> +	if (PM_RUNTIME_ACQUIRE_ERR(&pm))
>  		return -ENXIO;
>  
>  	status = acpi_evaluate_integer(handle, "_CWS", &arg_list, &retval);
> @@ -417,8 +417,8 @@ static ssize_t acpi_tad_status_read(stru
>  
>  	args[0].integer.value = timer_id;
>  
> -	ACQUIRE(pm_runtime_active_try, pm)(dev);
> -	if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
> +	PM_RUNTIME_ACQUIRE(dev, pm);
> +	if (PM_RUNTIME_ACQUIRE_ERR(&pm))
>  		return -ENXIO;
>  
>  	status = acpi_evaluate_integer(handle, "_GWS", &arg_list, &retval);
> 
> 
> 

-- 
Best regards,
Dhruva Gole
Texas Instruments Incorporated

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 3/3] PCI/sysfs: Use PM_RUNTIME_ACQUIRE()/PM_RUNTIME_ACQUIRE_ERR()
  2025-11-13 19:35 ` [PATCH v2 3/3] PCI/sysfs: " Rafael J. Wysocki
@ 2025-11-14  9:02   ` Dhruva Gole
  2025-11-14 15:47     ` Rafael J. Wysocki
  0 siblings, 1 reply; 11+ messages in thread
From: Dhruva Gole @ 2025-11-14  9:02 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM, Linux ACPI, Jonathan Cameron, Takashi Iwai, LKML,
	Zhang Qilong, Frank Li, Dan Williams, Linux PCI, Bjorn Helgaas

On Nov 13, 2025 at 20:35:27 +0100, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Use new PM_RUNTIME_ACQUIRE() and PM_RUNTIME_ACQUIRE_ERR() wrapper macros
> to make the code look more straightforward.
> 
> No intentional funtional impact.

Same here ...

Reviewed-by: Dhruva Gole <d-gole@ti.com> 

> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> 
> v1 -> v2: Adjust to the changes in patch [1/3].
> 
> ---
>  drivers/pci/pci-sysfs.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> --- a/drivers/pci/pci-sysfs.c
> +++ b/drivers/pci/pci-sysfs.c
> @@ -1517,8 +1517,8 @@ static ssize_t reset_method_store(struct
>  		return count;
>  	}
>  
> -	ACQUIRE(pm_runtime_active_try, pm)(dev);
> -	if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
> +	PM_RUNTIME_ACQUIRE(dev, pm);
> +	if (PM_RUNTIME_ACQUIRE_ERR(&pm))
>  		return -ENXIO;
>  
>  	if (sysfs_streq(buf, "default")) {
> 
> 
> 

-- 
Best regards,
Dhruva Gole
Texas Instruments Incorporated

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 0/3] PM: runtime: Wrapper macros for usage counter guards
  2025-11-13 19:24 [PATCH v2 0/3] PM: runtime: Wrapper macros for usage counter guards Rafael J. Wysocki
                   ` (2 preceding siblings ...)
  2025-11-13 19:35 ` [PATCH v2 3/3] PCI/sysfs: " Rafael J. Wysocki
@ 2025-11-14 13:10 ` Jonathan Cameron
  2025-11-14 15:49   ` Rafael J. Wysocki
  3 siblings, 1 reply; 11+ messages in thread
From: Jonathan Cameron @ 2025-11-14 13:10 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM, Linux ACPI, Takashi Iwai, LKML, Zhang Qilong, Frank Li,
	Dhruva Gole, Dan Williams, Linux PCI, Bjorn Helgaas

On Thu, 13 Nov 2025 20:24:57 +0100
"Rafael J. Wysocki" <rafael@kernel.org> wrote:

> Hi All,
> 
> This supersedes
> 
> https://lore.kernel.org/linux-pm/13883374.uLZWGnKmhe@rafael.j.wysocki/
> 
> as discussed here:
> 
> https://lore.kernel.org/linux-pm/5068916.31r3eYUQgx@rafael.j.wysocki/
> 
> It adds runtime PM wrapper macros around ACQUIRE() and ACQUIRE_ERR() involving
> the guards added recently (patch [1/3]) and then updates the code already
> using those guards (patches [2/3] and [3/3]) to make it look more
> straightforward.
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
for whole series. 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 3/3] PCI/sysfs: Use PM_RUNTIME_ACQUIRE()/PM_RUNTIME_ACQUIRE_ERR()
  2025-11-14  9:02   ` Dhruva Gole
@ 2025-11-14 15:47     ` Rafael J. Wysocki
  0 siblings, 0 replies; 11+ messages in thread
From: Rafael J. Wysocki @ 2025-11-14 15:47 UTC (permalink / raw)
  To: Dhruva Gole, Bjorn Helgaas
  Cc: Linux PM, Linux ACPI, Jonathan Cameron, Takashi Iwai, LKML,
	Zhang Qilong, Frank Li, Dan Williams, Linux PCI

On Fri, Nov 14, 2025 at 10:03 AM Dhruva Gole <d-gole@ti.com> wrote:
>
> On Nov 13, 2025 at 20:35:27 +0100, Rafael J. Wysocki wrote:
> > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> >
> > Use new PM_RUNTIME_ACQUIRE() and PM_RUNTIME_ACQUIRE_ERR() wrapper macros
> > to make the code look more straightforward.
> >
> > No intentional funtional impact.
>
> Same here ...

Yup, will fix.

> Reviewed-by: Dhruva Gole <d-gole@ti.com>

Thanks!

Bjorn & PCI people, if there are any concerns regarding the change
below, please let me know.

> >
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > ---
> >
> > v1 -> v2: Adjust to the changes in patch [1/3].
> >
> > ---
> >  drivers/pci/pci-sysfs.c |    4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > --- a/drivers/pci/pci-sysfs.c
> > +++ b/drivers/pci/pci-sysfs.c
> > @@ -1517,8 +1517,8 @@ static ssize_t reset_method_store(struct
> >               return count;
> >       }
> >
> > -     ACQUIRE(pm_runtime_active_try, pm)(dev);
> > -     if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
> > +     PM_RUNTIME_ACQUIRE(dev, pm);
> > +     if (PM_RUNTIME_ACQUIRE_ERR(&pm))
> >               return -ENXIO;
> >
> >       if (sysfs_streq(buf, "default")) {
> >
> >
> >
>
> --

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 0/3] PM: runtime: Wrapper macros for usage counter guards
  2025-11-14 13:10 ` [PATCH v2 0/3] PM: runtime: Wrapper macros for usage counter guards Jonathan Cameron
@ 2025-11-14 15:49   ` Rafael J. Wysocki
  0 siblings, 0 replies; 11+ messages in thread
From: Rafael J. Wysocki @ 2025-11-14 15:49 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Rafael J. Wysocki, Linux PM, Linux ACPI, Takashi Iwai, LKML,
	Zhang Qilong, Frank Li, Dhruva Gole, Dan Williams, Linux PCI,
	Bjorn Helgaas

On Fri, Nov 14, 2025 at 2:10 PM Jonathan Cameron
<jonathan.cameron@huawei.com> wrote:
>
> On Thu, 13 Nov 2025 20:24:57 +0100
> "Rafael J. Wysocki" <rafael@kernel.org> wrote:
>
> > Hi All,
> >
> > This supersedes
> >
> > https://lore.kernel.org/linux-pm/13883374.uLZWGnKmhe@rafael.j.wysocki/
> >
> > as discussed here:
> >
> > https://lore.kernel.org/linux-pm/5068916.31r3eYUQgx@rafael.j.wysocki/
> >
> > It adds runtime PM wrapper macros around ACQUIRE() and ACQUIRE_ERR() involving
> > the guards added recently (patch [1/3]) and then updates the code already
> > using those guards (patches [2/3] and [3/3]) to make it look more
> > straightforward.
> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
> for whole series.

Thank you!

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/3] PM: runtime: Wrapper macros for ACQUIRE()/ACQUIRE_ERR()
  2025-11-13 19:33 ` [PATCH v2 1/3] PM: runtime: Wrapper macros for ACQUIRE()/ACQUIRE_ERR() Rafael J. Wysocki
  2025-11-14  8:53   ` Dhruva Gole
@ 2025-11-14 20:15   ` Frank Li
  1 sibling, 0 replies; 11+ messages in thread
From: Frank Li @ 2025-11-14 20:15 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM, Linux ACPI, Jonathan Cameron, Takashi Iwai, LKML,
	Zhang Qilong, Dhruva Gole, Dan Williams, Linux PCI, Bjorn Helgaas

On Thu, Nov 13, 2025 at 08:33:33PM +0100, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Add wrapper macros for ACQUIRE()/ACQUIRE_ERR() and runtime PM
> usage counter guards introduced recently: pm_runtime_active_try,
> pm_runtime_active_auto_try, pm_runtime_active_try_enabled, and
> pm_runtime_active_auto_try_enabled.
>
> The new macros should be more straightforward to use.
>
> For example, they can be used for rewriting a piece of code like below:
>
>         ACQUIRE(pm_runtime_active_try, pm)(dev);
>         if ((ret = ACQUIRE_ERR(pm_runtime_active_try, &pm)))
>                 return ret;
>
> in the following way:
>
>         PM_RUNTIME_ACQUIRE(dev, pm);
>         if ((ret = PM_RUNTIME_ACQUIRE_ERR(&pm)))
>                 return ret;
>
> If the original code does not care about the specific error code
> returned when attepmting to resume the device:
>
>         ACQUIRE(pm_runtime_active_try, pm)(dev);
>         if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
>                 return -ENXIO;
>
> it may be changed like this:
>
>         PM_RUNTIME_ACQUIRE(dev, pm);
>         if (PM_RUNTIME_ACQUIRE_ERR(&pm))
>                 return -ENXIO;
>
> Link: https://lore.kernel.org/linux-pm/5068916.31r3eYUQgx@rafael.j.wysocki/
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Reviewed-by: Dan Williams <dan.j.williams@intel.com>
> ---
>
> v1 -> v2:
>    * The new macros take the guard variable name as a parameter.
>    * The new ERR macro takes a guard variable pointer as a parameter (Dan).
>    * Added underscore prefix to the macro parameter names.

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>
> ---
>  include/linux/pm_runtime.h |   24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
>
> --- a/include/linux/pm_runtime.h
> +++ b/include/linux/pm_runtime.h
> @@ -637,6 +637,30 @@ DEFINE_GUARD_COND(pm_runtime_active_auto
>  DEFINE_GUARD_COND(pm_runtime_active_auto, _try_enabled,
>  		  pm_runtime_resume_and_get(_T), _RET == 0)
>
> +/* ACQUIRE() wrapper macros for the guards defined above. */
> +
> +#define PM_RUNTIME_ACQUIRE(_dev, _var)			\
> +	ACQUIRE(pm_runtime_active_try, _var)(_dev)
> +
> +#define PM_RUNTIME_ACQUIRE_AUTOSUSPEND(_dev, _var)	\
> +	ACQUIRE(pm_runtime_active_auto_try, _var)(_dev)
> +
> +#define PM_RUNTIME_ACQUIRE_IF_ENABLED(_dev, _var)	\
> +	ACQUIRE(pm_runtime_active_try_enabled, _var)(_dev)
> +
> +#define PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND(_dev, _var)	\
> +	ACQUIRE(pm_runtime_active_auto_try_enabled, _var)(_dev)
> +
> +/*
> + * ACQUIRE_ERR() wrapper macro for guard pm_runtime_active.
> + *
> + * Always check PM_RUNTIME_ACQUIRE_ERR() after using one of the
> + * PM_RUNTIME_ACQUIRE*() macros defined above (yes, it can be used with
> + * any of them) and if it is nonzero, avoid accessing the given device.
> + */
> +#define PM_RUNTIME_ACQUIRE_ERR(_var_ptr)	\
> +	ACQUIRE_ERR(pm_runtime_active, _var_ptr)
> +
>  /**
>   * pm_runtime_put_sync - Drop device usage counter and run "idle check" if 0.
>   * @dev: Target device.
>
>
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-11-14 20:16 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-13 19:24 [PATCH v2 0/3] PM: runtime: Wrapper macros for usage counter guards Rafael J. Wysocki
2025-11-13 19:33 ` [PATCH v2 1/3] PM: runtime: Wrapper macros for ACQUIRE()/ACQUIRE_ERR() Rafael J. Wysocki
2025-11-14  8:53   ` Dhruva Gole
2025-11-14 20:15   ` Frank Li
2025-11-13 19:34 ` [PATCH v2 2/3] ACPI: TAD: Use PM_RUNTIME_ACQUIRE()/PM_RUNTIME_ACQUIRE_ERR() Rafael J. Wysocki
2025-11-14  9:02   ` Dhruva Gole
2025-11-13 19:35 ` [PATCH v2 3/3] PCI/sysfs: " Rafael J. Wysocki
2025-11-14  9:02   ` Dhruva Gole
2025-11-14 15:47     ` Rafael J. Wysocki
2025-11-14 13:10 ` [PATCH v2 0/3] PM: runtime: Wrapper macros for usage counter guards Jonathan Cameron
2025-11-14 15:49   ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox