public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/3] PM: runtime: Auto-cleanup macros for pm_runtime_resume_and_get()
@ 2025-09-19 16:34 Rafael J. Wysocki
  2025-09-19 16:35 ` [PATCH v1 1/3] PM: runtime: Add auto-cleanup " Rafael J. Wysocki
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Rafael J. Wysocki @ 2025-09-19 16:34 UTC (permalink / raw)
  To: Linux PM
  Cc: LKML, Linux PCI, Alex Williamson, Bjorn Helgaas, Takashi Iwai,
	Zhang Qilong, Ulf Hansson

Hi All,

This series adds two auto-cleanup macros for runtime PM usage counter
incrementations carried out by pm_runtime_resume_and_get() ([1/3]),
converts the only user of the previously introduced DEFINE_FREE()
macro for pm_runtime_put() to using one of the new macros ([2/3]),
and drops the DEFINE_FREE() mentioned above ([3/3]).

The new macros should be somewhat more straightforward to use than
the existing _FREE and they enforce error handling.

Thanks!




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

* [PATCH v1 1/3] PM: runtime: Add auto-cleanup macros for pm_runtime_resume_and_get()
  2025-09-19 16:34 [PATCH v1 0/3] PM: runtime: Auto-cleanup macros for pm_runtime_resume_and_get() Rafael J. Wysocki
@ 2025-09-19 16:35 ` Rafael J. Wysocki
  2025-09-19 16:38 ` [PATCH v1 2/3] PCI/sysfs: Use PM runtime class macro for auto cleanup in reset_method_store() Rafael J. Wysocki
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Rafael J. Wysocki @ 2025-09-19 16:35 UTC (permalink / raw)
  To: Linux PM
  Cc: LKML, Linux PCI, Alex Williamson, Bjorn Helgaas, Takashi Iwai,
	Zhang Qilong, Ulf Hansson

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

It is generally useful to be able to automatically drop a device's
runtime PM usage counter incremented by pm_runtime_resume_and_get() [1].

To that end, add two DEFINE_CLASS() macros allowing pm_runtime_put()
and pm_runtime_put_autosuspend() to be used for the auto-cleanup in
those cases.

Link: https://lore.kernel.org/linux-pm/878qimv24u.wl-tiwai@suse.de/ [1]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 include/linux/pm_runtime.h |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

--- a/include/linux/pm_runtime.h
+++ b/include/linux/pm_runtime.h
@@ -533,6 +533,30 @@ static inline int pm_runtime_resume_and_
 }
 
 /**
+ * pm_runtime_resume_and_get_dev - Resume device and bump up its usage counter.
+ * @dev: Target device.
+ *
+ * Resume @dev synchronously and if that is successful, increment its runtime
+ * PM usage counter.
+ *
+ * Return:
+ * * 0 if the runtime PM usage counter of @dev has been incremented.
+ * * Negative error code otherwise.
+ */
+static inline struct device *pm_runtime_resume_and_get_dev(struct device *dev)
+{
+	int ret;
+
+	ret = __pm_runtime_resume(dev, RPM_GET_PUT);
+	if (ret < 0) {
+		pm_runtime_put_noidle(dev);
+		return ERR_PTR(ret);
+	}
+
+	return dev;
+}
+
+/**
  * pm_runtime_put - Drop device usage counter and queue up "idle check" if 0.
  * @dev: Target device.
  *
@@ -606,6 +630,25 @@ static inline int pm_runtime_put_autosus
 	return __pm_runtime_put_autosuspend(dev);
 }
 
+/*
+ * The way to use the classes defined below is to define a class variable and
+ * use it going forward for representing the target device until it goes out of
+ * the scope.  For example:
+ *
+ * CLASS(pm_runtime_resume_and_get, active_dev)(dev);
+ * if (IS_ERR(active_dev))
+ *         return PTR_ERR(active_dev);
+ *
+ * ... do something with active_dev (which is guaranteed to never suspend) ...
+ */
+DEFINE_CLASS(pm_runtime_resume_and_get, struct device *,
+	     if (!IS_ERR_OR_NULL(_T)) pm_runtime_put(_T),
+	     pm_runtime_resume_and_get_dev(dev), struct device *dev)
+
+DEFINE_CLASS(pm_runtime_resume_and_get_auto, struct device *,
+	     if (!IS_ERR_OR_NULL(_T)) pm_runtime_put_autosuspend(_T),
+	     pm_runtime_resume_and_get_dev(dev), struct device *dev)
+
 /**
  * pm_runtime_put_sync - Drop device usage counter and run "idle check" if 0.
  * @dev: Target device.




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

* [PATCH v1 2/3] PCI/sysfs: Use PM runtime class macro for auto cleanup in reset_method_store()
  2025-09-19 16:34 [PATCH v1 0/3] PM: runtime: Auto-cleanup macros for pm_runtime_resume_and_get() Rafael J. Wysocki
  2025-09-19 16:35 ` [PATCH v1 1/3] PM: runtime: Add auto-cleanup " Rafael J. Wysocki
@ 2025-09-19 16:38 ` Rafael J. Wysocki
  2025-09-26 13:49   ` Jonathan Cameron
  2025-09-19 16:40 ` [PATCH v1 3/3] PM: runtime: Drop DEFINE_FREE() for pm_runtime_put Rafael J. Wysocki
  2025-09-20  6:37 ` [PATCH v1 0/3] PM: runtime: Auto-cleanup macros for pm_runtime_resume_and_get() Takashi Iwai
  3 siblings, 1 reply; 9+ messages in thread
From: Rafael J. Wysocki @ 2025-09-19 16:38 UTC (permalink / raw)
  To: Linux PM
  Cc: LKML, Linux PCI, Alex Williamson, Bjorn Helgaas, Takashi Iwai,
	Zhang Qilong, Ulf Hansson

From: Takashi Iwai <tiwai@suse.de>

The newly introduced class macro can simplify the code.

Also, add the proper error handling for the PM runtime get.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
[ rjw: Adjust subject and error handling ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/pci/pci-sysfs.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1475,8 +1475,9 @@ static ssize_t reset_method_store(struct
 		return count;
 	}
 
-	pm_runtime_get_sync(dev);
-	struct device *pmdev __free(pm_runtime_put) = dev;
+	CLASS(pm_runtime_resume_and_get, pmdev)(dev);
+	if (IS_ERR(pmdev))
+		return -ENXIO;
 
 	if (sysfs_streq(buf, "default")) {
 		pci_init_reset_methods(pdev);




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

* [PATCH v1 3/3] PM: runtime: Drop DEFINE_FREE() for pm_runtime_put
  2025-09-19 16:34 [PATCH v1 0/3] PM: runtime: Auto-cleanup macros for pm_runtime_resume_and_get() Rafael J. Wysocki
  2025-09-19 16:35 ` [PATCH v1 1/3] PM: runtime: Add auto-cleanup " Rafael J. Wysocki
  2025-09-19 16:38 ` [PATCH v1 2/3] PCI/sysfs: Use PM runtime class macro for auto cleanup in reset_method_store() Rafael J. Wysocki
@ 2025-09-19 16:40 ` Rafael J. Wysocki
  2025-09-20  6:37 ` [PATCH v1 0/3] PM: runtime: Auto-cleanup macros for pm_runtime_resume_and_get() Takashi Iwai
  3 siblings, 0 replies; 9+ messages in thread
From: Rafael J. Wysocki @ 2025-09-19 16:40 UTC (permalink / raw)
  To: Linux PM
  Cc: LKML, Linux PCI, Alex Williamson, Bjorn Helgaas, Takashi Iwai,
	Zhang Qilong, Ulf Hansson

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

The DEFINE_FREE() for pm_runtime_put has been superseded by recently
introduced runtime PM auto-cleanup macros and its only user has been
converted to using one of the new macros, so drop it.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 include/linux/pm_runtime.h |    2 --
 1 file changed, 2 deletions(-)

--- a/include/linux/pm_runtime.h
+++ b/include/linux/pm_runtime.h
@@ -579,8 +579,6 @@ static inline int pm_runtime_put(struct
 	return __pm_runtime_idle(dev, RPM_GET_PUT | RPM_ASYNC);
 }
 
-DEFINE_FREE(pm_runtime_put, struct device *, if (_T) pm_runtime_put(_T))
-
 /**
  * __pm_runtime_put_autosuspend - Drop device usage counter and queue autosuspend if 0.
  * @dev: Target device.




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

* Re: [PATCH v1 0/3] PM: runtime: Auto-cleanup macros for pm_runtime_resume_and_get()
  2025-09-19 16:34 [PATCH v1 0/3] PM: runtime: Auto-cleanup macros for pm_runtime_resume_and_get() Rafael J. Wysocki
                   ` (2 preceding siblings ...)
  2025-09-19 16:40 ` [PATCH v1 3/3] PM: runtime: Drop DEFINE_FREE() for pm_runtime_put Rafael J. Wysocki
@ 2025-09-20  6:37 ` Takashi Iwai
  3 siblings, 0 replies; 9+ messages in thread
From: Takashi Iwai @ 2025-09-20  6:37 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM, LKML, Linux PCI, Alex Williamson, Bjorn Helgaas,
	Takashi Iwai, Zhang Qilong, Ulf Hansson

On Fri, 19 Sep 2025 18:34:40 +0200,
Rafael J. Wysocki wrote:
> 
> Hi All,
> 
> This series adds two auto-cleanup macros for runtime PM usage counter
> incrementations carried out by pm_runtime_resume_and_get() ([1/3]),
> converts the only user of the previously introduced DEFINE_FREE()
> macro for pm_runtime_put() to using one of the new macros ([2/3]),
> and drops the DEFINE_FREE() mentioned above ([3/3]).
> 
> The new macros should be somewhat more straightforward to use than
> the existing _FREE and they enforce error handling.

For the series:

Reviewed-by: Takashi Iwai <tiwai@suse.de>


Thanks!

Takashi

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

* Re: [PATCH v1 2/3] PCI/sysfs: Use PM runtime class macro for auto cleanup in reset_method_store()
  2025-09-19 16:38 ` [PATCH v1 2/3] PCI/sysfs: Use PM runtime class macro for auto cleanup in reset_method_store() Rafael J. Wysocki
@ 2025-09-26 13:49   ` Jonathan Cameron
  2025-09-26 14:36     ` Rafael J. Wysocki
  0 siblings, 1 reply; 9+ messages in thread
From: Jonathan Cameron @ 2025-09-26 13:49 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM, LKML, Linux PCI, Alex Williamson, Bjorn Helgaas,
	Takashi Iwai, Zhang Qilong, Ulf Hansson, Dan Williams

On Fri, 19 Sep 2025 18:38:42 +0200
"Rafael J. Wysocki" <rafael@kernel.org> wrote:

> From: Takashi Iwai <tiwai@suse.de>
> 
> The newly introduced class macro can simplify the code.
> 
> Also, add the proper error handling for the PM runtime get.
> 
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> [ rjw: Adjust subject and error handling ]
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>  drivers/pci/pci-sysfs.c |    5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> --- a/drivers/pci/pci-sysfs.c
> +++ b/drivers/pci/pci-sysfs.c
> @@ -1475,8 +1475,9 @@ static ssize_t reset_method_store(struct
>  		return count;
>  	}
>  
> -	pm_runtime_get_sync(dev);
> -	struct device *pmdev __free(pm_runtime_put) = dev;
> +	CLASS(pm_runtime_resume_and_get, pmdev)(dev);
> +	if (IS_ERR(pmdev))
> +		return -ENXIO;
Hi Rafael,

Why this approach rather than treating runtime pm state like a conditional
lock (we use it much like one) and using ACQUIRE() / ACQUIRE_ERR()?

Ultimately that's a wrapper around the same infrastructure but
perhaps neater as it removes need to have that explicit magic pmdev.

+CC Dan as he can probably remember the discussions around ACQUIRE()
vs the way you have here better than I can.

In general great that you've done this.  Was on my list too, but I didn't
get around to actually spinning the patches!   This is going to be
very useful indeed.
 
Jonathan


>  
>  	if (sysfs_streq(buf, "default")) {
>  		pci_init_reset_methods(pdev);
> 
> 
> 
> 
> 


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

* Re: [PATCH v1 2/3] PCI/sysfs: Use PM runtime class macro for auto cleanup in reset_method_store()
  2025-09-26 13:49   ` Jonathan Cameron
@ 2025-09-26 14:36     ` Rafael J. Wysocki
  2025-09-26 18:13       ` dan.j.williams
  0 siblings, 1 reply; 9+ messages in thread
From: Rafael J. Wysocki @ 2025-09-26 14:36 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Rafael J. Wysocki, Linux PM, LKML, Linux PCI, Alex Williamson,
	Bjorn Helgaas, Takashi Iwai, Zhang Qilong, Ulf Hansson,
	Dan Williams

On Fri, Sep 26, 2025 at 3:49 PM Jonathan Cameron
<jonathan.cameron@huawei.com> wrote:
>
> On Fri, 19 Sep 2025 18:38:42 +0200
> "Rafael J. Wysocki" <rafael@kernel.org> wrote:
>
> > From: Takashi Iwai <tiwai@suse.de>
> >
> > The newly introduced class macro can simplify the code.
> >
> > Also, add the proper error handling for the PM runtime get.
> >
> > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > [ rjw: Adjust subject and error handling ]
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > ---
> >  drivers/pci/pci-sysfs.c |    5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > --- a/drivers/pci/pci-sysfs.c
> > +++ b/drivers/pci/pci-sysfs.c
> > @@ -1475,8 +1475,9 @@ static ssize_t reset_method_store(struct
> >               return count;
> >       }
> >
> > -     pm_runtime_get_sync(dev);
> > -     struct device *pmdev __free(pm_runtime_put) = dev;
> > +     CLASS(pm_runtime_resume_and_get, pmdev)(dev);
> > +     if (IS_ERR(pmdev))
> > +             return -ENXIO;
> Hi Rafael,
>
> Why this approach rather than treating runtime pm state like a conditional
> lock (we use it much like one) and using ACQUIRE() / ACQUIRE_ERR()?

Mostly because devices are not locks.

> Ultimately that's a wrapper around the same infrastructure but
> perhaps neater as it removes need to have that explicit magic pmdev.

You'll need to have a magic pmdev or similar regardless IIUC.

Say there is

DEFINE_GUARD(pm_runtime_active, struct device *,
pm_runtime_get_sync(_T), pm_runtime_put(_T))
DEFINE_GUARD_COND(pm_runtime_active, _try, pm_runtime_resume_and_get(_T))

so the user of this will do

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

and there's a "magic" pm though pm is not a struct device pointer.

Maybe it's nicer.  I guess people may be more used to dealing with int
error variables.

Let me try this and see how far I can get with this.

> +CC Dan as he can probably remember the discussions around ACQUIRE()
> vs the way you have here better than I can.
>
> In general great that you've done this.  Was on my list too, but I didn't
> get around to actually spinning the patches!   This is going to be
> very useful indeed.

Thanks!

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

* Re: [PATCH v1 2/3] PCI/sysfs: Use PM runtime class macro for auto cleanup in reset_method_store()
  2025-09-26 14:36     ` Rafael J. Wysocki
@ 2025-09-26 18:13       ` dan.j.williams
  2025-09-26 18:23         ` Rafael J. Wysocki
  0 siblings, 1 reply; 9+ messages in thread
From: dan.j.williams @ 2025-09-26 18:13 UTC (permalink / raw)
  To: Rafael J. Wysocki, Jonathan Cameron
  Cc: Rafael J. Wysocki, Linux PM, LKML, Linux PCI, Alex Williamson,
	Bjorn Helgaas, Takashi Iwai, Zhang Qilong, Ulf Hansson,
	Dan Williams

Rafael J. Wysocki wrote:
> On Fri, Sep 26, 2025 at 3:49 PM Jonathan Cameron
> <jonathan.cameron@huawei.com> wrote:
> >
> > On Fri, 19 Sep 2025 18:38:42 +0200
> > "Rafael J. Wysocki" <rafael@kernel.org> wrote:
> >
> > > From: Takashi Iwai <tiwai@suse.de>
> > >
> > > The newly introduced class macro can simplify the code.
> > >
> > > Also, add the proper error handling for the PM runtime get.
> > >
> > > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > > [ rjw: Adjust subject and error handling ]
> > > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > > ---
> > >  drivers/pci/pci-sysfs.c |    5 +++--
> > >  1 file changed, 3 insertions(+), 2 deletions(-)
> > >
> > > --- a/drivers/pci/pci-sysfs.c
> > > +++ b/drivers/pci/pci-sysfs.c
> > > @@ -1475,8 +1475,9 @@ static ssize_t reset_method_store(struct
> > >               return count;
> > >       }
> > >
> > > -     pm_runtime_get_sync(dev);
> > > -     struct device *pmdev __free(pm_runtime_put) = dev;
> > > +     CLASS(pm_runtime_resume_and_get, pmdev)(dev);
> > > +     if (IS_ERR(pmdev))
> > > +             return -ENXIO;
> > Hi Rafael,
> >
> > Why this approach rather than treating runtime pm state like a conditional
> > lock (we use it much like one) and using ACQUIRE() / ACQUIRE_ERR()?
> 
> Mostly because devices are not locks.
> 
> > Ultimately that's a wrapper around the same infrastructure but
> > perhaps neater as it removes need to have that explicit magic pmdev.
> 
> You'll need to have a magic pmdev or similar regardless IIUC.
> 
> Say there is
> 
> DEFINE_GUARD(pm_runtime_active, struct device *,
> pm_runtime_get_sync(_T), pm_runtime_put(_T))
> DEFINE_GUARD_COND(pm_runtime_active, _try, pm_runtime_resume_and_get(_T))
> 
> so the user of this will do
> 
> ACQUIRE(pm_runtime_active_try, pm)(dev);
> if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
>         return -ENXIO;

FWIW this looks better to me than the open-coded CLASS(). The pattern,
admittedly coding-style bending, we are using in drivers/cxl/ for
compactness and error code fidelity is:

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

> and there's a "magic" pm though pm is not a struct device pointer.
> 
> Maybe it's nicer.  I guess people may be more used to dealing with int
> error variables.
> 
> Let me try this and see how far I can get with this.
> 
> > +CC Dan as he can probably remember the discussions around ACQUIRE()
> > vs the way you have here better than I can.

Yes, effectively a new open-coded CLASS() prompted the ACQUIRE()
proposal [1]. This pm-active-state reference management indeed looks
more like a guard() of the active state than an object constructor
auto-unwind-on-error case.

[1]: http://lore.kernel.org/20250507072145.3614298-1-dan.j.williams@intel.com

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

* Re: [PATCH v1 2/3] PCI/sysfs: Use PM runtime class macro for auto cleanup in reset_method_store()
  2025-09-26 18:13       ` dan.j.williams
@ 2025-09-26 18:23         ` Rafael J. Wysocki
  0 siblings, 0 replies; 9+ messages in thread
From: Rafael J. Wysocki @ 2025-09-26 18:23 UTC (permalink / raw)
  To: dan.j.williams
  Cc: Rafael J. Wysocki, Jonathan Cameron, Linux PM, LKML, Linux PCI,
	Alex Williamson, Bjorn Helgaas, Takashi Iwai, Zhang Qilong,
	Ulf Hansson

On Fri, Sep 26, 2025 at 8:13 PM <dan.j.williams@intel.com> wrote:
>
> Rafael J. Wysocki wrote:
> > On Fri, Sep 26, 2025 at 3:49 PM Jonathan Cameron
> > <jonathan.cameron@huawei.com> wrote:
> > >
> > > On Fri, 19 Sep 2025 18:38:42 +0200
> > > "Rafael J. Wysocki" <rafael@kernel.org> wrote:
> > >
> > > > From: Takashi Iwai <tiwai@suse.de>
> > > >
> > > > The newly introduced class macro can simplify the code.
> > > >
> > > > Also, add the proper error handling for the PM runtime get.
> > > >
> > > > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > > > [ rjw: Adjust subject and error handling ]
> > > > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > > > ---
> > > >  drivers/pci/pci-sysfs.c |    5 +++--
> > > >  1 file changed, 3 insertions(+), 2 deletions(-)
> > > >
> > > > --- a/drivers/pci/pci-sysfs.c
> > > > +++ b/drivers/pci/pci-sysfs.c
> > > > @@ -1475,8 +1475,9 @@ static ssize_t reset_method_store(struct
> > > >               return count;
> > > >       }
> > > >
> > > > -     pm_runtime_get_sync(dev);
> > > > -     struct device *pmdev __free(pm_runtime_put) = dev;
> > > > +     CLASS(pm_runtime_resume_and_get, pmdev)(dev);
> > > > +     if (IS_ERR(pmdev))
> > > > +             return -ENXIO;
> > > Hi Rafael,
> > >
> > > Why this approach rather than treating runtime pm state like a conditional
> > > lock (we use it much like one) and using ACQUIRE() / ACQUIRE_ERR()?
> >
> > Mostly because devices are not locks.
> >
> > > Ultimately that's a wrapper around the same infrastructure but
> > > perhaps neater as it removes need to have that explicit magic pmdev.
> >
> > You'll need to have a magic pmdev or similar regardless IIUC.
> >
> > Say there is
> >
> > DEFINE_GUARD(pm_runtime_active, struct device *,
> > pm_runtime_get_sync(_T), pm_runtime_put(_T))
> > DEFINE_GUARD_COND(pm_runtime_active, _try, pm_runtime_resume_and_get(_T))
> >
> > so the user of this will do
> >
> > ACQUIRE(pm_runtime_active_try, pm)(dev);
> > if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
> >         return -ENXIO;
>
> FWIW this looks better to me than the open-coded CLASS(). The pattern,
> admittedly coding-style bending, we are using in drivers/cxl/ for
> compactness and error code fidelity is:
>
>    ACQUIRE(pm_runtime_active_try, pm)(dev);
>    if ((ret = ACQUIRE_ERR(pm_runtime_active_try, &pm)))
>            return ret;

I prefer somewhat more traditional

ret = ACQUIRE_ERR(pm_runtime_active_try, &pm);
if (ret < 0)
        return ret;

It would be nice to be able to hide the pm variable somehow, but this
is not too bad the way it looks now.

> > and there's a "magic" pm though pm is not a struct device pointer.
> >
> > Maybe it's nicer.  I guess people may be more used to dealing with int
> > error variables.
> >
> > Let me try this and see how far I can get with this.
> >
> > > +CC Dan as he can probably remember the discussions around ACQUIRE()
> > > vs the way you have here better than I can.
>
> Yes, effectively a new open-coded CLASS() prompted the ACQUIRE()
> proposal [1]. This pm-active-state reference management indeed looks
> more like a guard() of the active state than an object constructor
> auto-unwind-on-error case.
>
> [1]: http://lore.kernel.org/20250507072145.3614298-1-dan.j.williams@intel.com

OK, so please see
https://lore.kernel.org/linux-pm/6196611.lOV4Wx5bFT@rafael.j.wysocki/

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

end of thread, other threads:[~2025-09-26 18:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-19 16:34 [PATCH v1 0/3] PM: runtime: Auto-cleanup macros for pm_runtime_resume_and_get() Rafael J. Wysocki
2025-09-19 16:35 ` [PATCH v1 1/3] PM: runtime: Add auto-cleanup " Rafael J. Wysocki
2025-09-19 16:38 ` [PATCH v1 2/3] PCI/sysfs: Use PM runtime class macro for auto cleanup in reset_method_store() Rafael J. Wysocki
2025-09-26 13:49   ` Jonathan Cameron
2025-09-26 14:36     ` Rafael J. Wysocki
2025-09-26 18:13       ` dan.j.williams
2025-09-26 18:23         ` Rafael J. Wysocki
2025-09-19 16:40 ` [PATCH v1 3/3] PM: runtime: Drop DEFINE_FREE() for pm_runtime_put Rafael J. Wysocki
2025-09-20  6:37 ` [PATCH v1 0/3] PM: runtime: Auto-cleanup macros for pm_runtime_resume_and_get() Takashi Iwai

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