public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* PM runtime auto-cleanup macros
@ 2025-09-10 14:00 Takashi Iwai
  2025-09-11  7:31 ` Takashi Iwai
  0 siblings, 1 reply; 15+ messages in thread
From: Takashi Iwai @ 2025-09-10 14:00 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: linux-pm, linux-kernel

Hi,

while I worked on the code cleanups in the drivers with the recent
auto-cleanup macros, I noticed that pm_runtime_get*() and _put*() can
be also managed with the auto-cleanup gracefully, too.  Actually we
already defined the __free(pm_runtime_put) in commit bfa4477751e9, and
there is a (single) user of it in pci-sysfs.c.

Now I wanted to extend it to pm_runtime_put_autosuspend() as:

DEFINE_FREE(pm_runtime_put_autosuspend, struct device *,
           if (_T) pm_runtime_put_autosuspend(_T))

Then one can use it like

	ret = pm_runtime_resume_and_get(dev);
	if (ret < 0)
		return ret;
	struct device *pmdev __free(pm_runtime_put_autosuspend) = dev;

that is similar as done in pci-sysfs.c.  So far, so good.

But, I find putting the line like above at each place a bit ugly.
So I'm wondering whether it'd be better to introduce some helper
macros, e.g.

#define pm_runtime_auto_clean(dev, var) \
	struct device *var __free(pm_runtime_put) = (dev)

#define pm_runtime_auto_clean_autosuspend(dev, var) \
	struct device *var __free(pm_runtime_put_autosuspend) = (dev)

and the code will be like:

	pm_runtime_get_sync(dev);
	pm_runtime_auto_clean(dev, pmdev);

or
	ret = pm_runtime_resume_and_get(dev);
	if (ret < 0)
		return ret;
	pm_runtime_auto_clean_autosuspend(dev, pmdev);

Alternatively, we may define a class, e.g.

	CLASS(pm_runtime_resume_and_get, pmdev);
	if (pmdev.ret < 0)
		return pmdev.ret;

but it'll be a bit more code to define the full class, and the get*()
and put*() combination would be fixed with this approach -- which is a
downside.

All above are an idea for now.  Let me know if I should go further
along with this, or there is already a better another approach.

(And the macros can be better named, sure :)


thanks,

Takashi

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

end of thread, other threads:[~2025-09-19 16:06 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-10 14:00 PM runtime auto-cleanup macros Takashi Iwai
2025-09-11  7:31 ` Takashi Iwai
2025-09-17 18:58   ` Rafael J. Wysocki
2025-09-18  7:10     ` Takashi Iwai
2025-09-18 11:28       ` Rafael J. Wysocki
2025-09-18 20:19         ` Rafael J. Wysocki
2025-09-18 20:41           ` Rafael J. Wysocki
2025-09-19  7:37             ` Takashi Iwai
2025-09-19 13:05               ` Rafael J. Wysocki
2025-09-19 13:41                 ` Takashi Iwai
2025-09-19 13:43                   ` Takashi Iwai
2025-09-19 15:49                     ` Rafael J. Wysocki
2025-09-19 16:04                       ` Takashi Iwai
2025-09-19 15:52                   ` Rafael J. Wysocki
2025-09-19 16:06                     ` Takashi Iwai

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