[PATCH v3 2/3] PCI/sysfs: Use runtime PM class macro for auto-cleanup

Rafael J. Wysocki posted 3 patches 1 week, 2 days ago
There is a newer version of this series
[PATCH v3 2/3] PCI/sysfs: Use runtime PM class macro for auto-cleanup
Posted by Rafael J. Wysocki 1 week, 2 days ago
From: Takashi Iwai <tiwai@suse.de>

Use the newly introduced class macro to simplify the code.

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

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20250919163147.4743-3-tiwai@suse.de
[ rjw: Adjusted the subject and the name of the class ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

v2 -> v3: No changes

v1 -> v2:
   * Adjust the name of the class to handle the disabled runtime PM case
     transparently (like the original code).

---
 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_get_active, pmdev)(dev);
+	if (IS_ERR(pmdev))
+		return -ENXIO;
 
 	if (sysfs_streq(buf, "default")) {
 		pci_init_reset_methods(pdev);
Re: [PATCH v3 2/3] PCI/sysfs: Use runtime PM class macro for auto-cleanup
Posted by Bjorn Helgaas 1 week, 2 days ago
On Mon, Sep 22, 2025 at 05:31:53PM +0200, Rafael J. Wysocki wrote:
> From: Takashi Iwai <tiwai@suse.de>
> 
> Use the newly introduced class macro to simplify the code.
> 
> Also, add the proper error handling for the PM runtime get errors.
> 
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> Link: https://patch.msgid.link/20250919163147.4743-3-tiwai@suse.de
> [ rjw: Adjusted the subject and the name of the class ]
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Acked-by: Bjorn Helgaas <bhelgaas@google.com>

> ---
> 
> v2 -> v3: No changes
> 
> v1 -> v2:
>    * Adjust the name of the class to handle the disabled runtime PM case
>      transparently (like the original code).
> 
> ---
>  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_get_active, pmdev)(dev);
> +	if (IS_ERR(pmdev))
> +		return -ENXIO;
>  
>  	if (sysfs_streq(buf, "default")) {
>  		pci_init_reset_methods(pdev);
> 
> 
>
Re: [PATCH v3 2/3] PCI/sysfs: Use runtime PM class macro for auto-cleanup
Posted by Jonathan Cameron 5 days, 14 hours ago
On Mon, 22 Sep 2025 13:50:36 -0500
Bjorn Helgaas <helgaas@kernel.org> wrote:

> On Mon, Sep 22, 2025 at 05:31:53PM +0200, Rafael J. Wysocki wrote:
> > From: Takashi Iwai <tiwai@suse.de>
> > 
> > Use the newly introduced class macro to simplify the code.
> > 
> > Also, add the proper error handling for the PM runtime get errors.
> > 
> > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > Link: https://patch.msgid.link/20250919163147.4743-3-tiwai@suse.de
> > [ rjw: Adjusted the subject and the name of the class ]
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>  
> 
> Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Being half asleep I went and  replied to v1 when v2 and indeed this v3
were already out. Sorry about that.

Anyhow question is why not ACQUIRE() and ACQUIRE_ERR()?

original discussion on how those came about rather that direct use of
class that you have here was I think here:
https://lore.kernel.org/all/20250509104028.GL4439@noisy.programming.kicks-ass.net/

Though note, we didn't end up with the parallel universe that is talking about.

+CC Dan,

Jonathan

> 
> > ---
> > 
> > v2 -> v3: No changes
> > 
> > v1 -> v2:
> >    * Adjust the name of the class to handle the disabled runtime PM case
> >      transparently (like the original code).
> > 
> > ---
> >  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_get_active, pmdev)(dev);
> > +	if (IS_ERR(pmdev))
> > +		return -ENXIO;
> >  
> >  	if (sysfs_streq(buf, "default")) {
> >  		pci_init_reset_methods(pdev);
> > 
> > 
> >   
>
Re: [PATCH v3 2/3] PCI/sysfs: Use runtime PM class macro for auto-cleanup
Posted by Rafael J. Wysocki 5 days, 14 hours ago
On Fri, Sep 26, 2025 at 4:06 PM Jonathan Cameron
<jonathan.cameron@huawei.com> wrote:
>
> On Mon, 22 Sep 2025 13:50:36 -0500
> Bjorn Helgaas <helgaas@kernel.org> wrote:
>
> > On Mon, Sep 22, 2025 at 05:31:53PM +0200, Rafael J. Wysocki wrote:
> > > From: Takashi Iwai <tiwai@suse.de>
> > >
> > > Use the newly introduced class macro to simplify the code.
> > >
> > > Also, add the proper error handling for the PM runtime get errors.
> > >
> > > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > > Link: https://patch.msgid.link/20250919163147.4743-3-tiwai@suse.de
> > > [ rjw: Adjusted the subject and the name of the class ]
> > > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> >
> > Acked-by: Bjorn Helgaas <bhelgaas@google.com>
> Being half asleep I went and  replied to v1 when v2 and indeed this v3
> were already out. Sorry about that.
>
> Anyhow question is why not ACQUIRE() and ACQUIRE_ERR()?

See my reply:

https://lore.kernel.org/linux-pm/CAJZ5v0gnqoJ8bALZT61ZvTA=chp8y5QBiA7ZpNQ6fFJuQzZUnA@mail.gmail.com/

I think that it can be done though.