From: Claudiu Beznea <claudiu.beznea@tuxon.dev>
To: Ulf Hansson <ulf.hansson@linaro.org>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
dakr@kernel.org, linux-kernel@vger.kernel.org,
linux-pm@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
geert@linux-m68k.org,
Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-iio@vger.kernel.org, bhelgaas@google.com
Subject: Re: [PATCH] driver core: platform: Use devres group to free driver probe resources
Date: Fri, 23 May 2025 13:52:03 +0300 [thread overview]
Message-ID: <47853bb8-db03-42b1-bcc2-3338fc208abb@tuxon.dev> (raw)
In-Reply-To: <CAPDyKFpRUhTK=UfcEdRdT0f5EVoGN5okLosd9_tYjdGKr0qvkA@mail.gmail.com>
Hi, Ulf,
On 23.05.2025 12:47, Ulf Hansson wrote:
> On Fri, 23 May 2025 at 01:06, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
>>
>> On Fri, May 23, 2025 at 12:09:08AM +0200, Ulf Hansson wrote:
>>> On Thu, 22 May 2025 at 20:47, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
>>>>
>>>> On Thu, May 22, 2025 at 06:28:44PM +0200, Ulf Hansson wrote:
>>>>> On Thu, 22 May 2025 at 16:08, Claudiu Beznea <claudiu.beznea@tuxon.dev> wrote:
>>>>>>
>>>>>> Hi, Ulf,
>>>>>>
>>>>>> On 22.05.2025 14:53, Ulf Hansson wrote:
>>>>>>>
>>>>>>> That said, I think adding a devm_pm_domain_attach() interface would
>>>>>>> make perfect sense. Then we can try to replace
>>>>>>> dev_pm_domain_attach|detach() in bus level code, with just a call to
>>>>>>> devm_pm_domain_attach(). In this way, we should preserve the
>>>>>>> expectation for drivers around devres for PM domains. Even if it would
>>>>>>> change the behaviour for some drivers, it still sounds like the
>>>>>>> correct thing to do in my opinion.
>>>>>>
>>>>>> This looks good to me, as well. I did prototype it on my side and tested on
>>>>>> all my failure cases and it works.
>>>>>
>>>>> That's great! I am happy to help review, if/when you decide to post it.
>>>>
>>>> So you are saying you'd be OK with essentially the following (with
>>>> devm_pm_domain_attach() actually being elsewhere in a real patch and not
>>>> necessarily mimicked by devm_add_action_or_reset()):
>>>
>>> Correct!
>>>
>>>>
>>>> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
>>>> index cfccf3ff36e7..1e017bfa5caf 100644
>>>> --- a/drivers/base/platform.c
>>>> +++ b/drivers/base/platform.c
>>>> @@ -1376,6 +1376,27 @@ static int platform_uevent(const struct device *dev, struct kobj_uevent_env *env
>>>> return 0;
>>>> }
>>>>
>>>> +
>>>> +static void platform_pm_domain_detach(void *d)
>>>> +{
>>>> + dev_pm_domain_detach(d, true);
>>>> +}
>>>
>>> Well, I would not limit this to the platform bus, even if that is the
>>> most widely used.
>>>
>>> Let's add the new generic interface along with
>>> dev_pm_domain_attach|detach* and friends instead.
>>>
>>> Then we can convert bus level code (and others), such as the platform
>>> bus to use it, in a step-by-step approach.
>>
>> Right, this was only a draft:
>>
>> "... with devm_pm_domain_attach() actually being elsewhere in a real
>> patch and not necessarily mimicked by devm_add_action_or_reset() ..."
>>
>>>
>>>> +
>>>> +static int devm_pm_domain_attach(struct device *dev)
>>>> +{
>>>> + int error;
>>>> +
>>>> + error = dev_pm_domain_attach(dev, true);
>>>> + if (error)
>>>> + return error;
>>>> +
>>>> + error = devm_add_action_or_reset(dev, platform_pm_domain_detach, dev);
>>>> + if (error)
>>>> + return error;
>>>> +
>>>> + return 0;
>>>> +}
>>>> +
>>>> static int platform_probe(struct device *_dev)
>>>> {
>>>> struct platform_driver *drv = to_platform_driver(_dev->driver);
>>>> @@ -1396,15 +1417,12 @@ static int platform_probe(struct device *_dev)
>>>> if (ret < 0)
>>>> return ret;
>>>>
>>>> - ret = dev_pm_domain_attach(_dev, true);
>>>> + ret = devm_pm_domain_attach(_dev);
>>>> if (ret)
>>>> goto out;
>>>>
>>>> - if (drv->probe) {
>>>> + if (drv->probe)
>>>> ret = drv->probe(dev);
>>>> - if (ret)
>>>> - dev_pm_domain_detach(_dev, true);
>>>> - }
>>>>
>>>> out:
>>>> if (drv->prevent_deferred_probe && ret == -EPROBE_DEFER) {
>>>> @@ -1422,7 +1440,6 @@ static void platform_remove(struct device *_dev)
>>>>
>>>> if (drv->remove)
>>>> drv->remove(dev);
>>>> - dev_pm_domain_detach(_dev, true);
>>>> }
>>>>
>>>> static void platform_shutdown(struct device *_dev)
>>>>
>>>>
>>>> If so, then OK, it will work for me as well. This achieves the
>>>> same behavior as with using devres group. The only difference is that if
>>>> we ever need to extend the platform bus to acquire/release more
>>>> resources they will also have to use devm API and not the regular one.
>>>
>>> Sounds reasonable to me! Thanks for a nice discussion!
>>>
>>> When it comes to the devm_pm_runtime_enable() API, I think we
>>> seriously should consider removing it. Let me have a closer look at
>>> that.
>>
>> I think once we sort out the power domain detach being out of order with
>> regard to other devm-managed resources in bus code you need to analyze
>> this again and you will find out that much as with IRQs, devm API for
>> runtime PM is useful for majority of cases. Of course there will be
>> exceptions, but by and large it will cut down on boilerplate code.
>
> Well, the problem is that the interface is just too difficult to
> understand how to use correctly.
>
> A quick look for deployments in drivers confirms my worries.
Maybe we can add something like:
diff --git a/MAINTAINERS b/MAINTAINERS
index 96e64f3d7b47..568a8307863b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10100,6 +10100,7 @@ F:
Documentation/devicetree/bindings/power/power?domain*
T: git git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/linux-pm.git
F: drivers/pmdomain/
F: include/linux/pm_domain.h
+K: \bpm_runtime_\w+\b
in MAINTAINERS file so that any new patch using the RPM will also be sent
to PM maintainers and checked accordingly?
Thank you,
Claudiu
next prev parent reply other threads:[~2025-05-23 10:52 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-15 13:08 [PATCH] driver core: platform: Use devres group to free driver probe resources Claudiu
2025-02-15 13:25 ` Greg KH
2025-02-15 13:51 ` Claudiu Beznea
2025-02-19 12:45 ` Claudiu Beznea
2025-03-05 14:03 ` Jonathan Cameron
2025-03-06 6:11 ` Dmitry Torokhov
2025-03-27 16:47 ` Claudiu Beznea
2025-03-30 15:31 ` Jonathan Cameron
2025-04-09 16:12 ` Claudiu Beznea
2025-05-09 11:51 ` Claudiu Beznea
2025-05-09 13:07 ` Ulf Hansson
2025-05-09 14:12 ` Claudiu Beznea
2025-05-11 11:01 ` Jonathan Cameron
2025-05-19 16:20 ` Dmitry Torokhov
2025-05-19 15:02 ` Ulf Hansson
2025-05-19 16:13 ` Dmitry Torokhov
2025-05-20 12:09 ` Ulf Hansson
2025-05-20 19:08 ` Dmitry Torokhov
2025-05-21 5:41 ` Claudiu Beznea
2025-05-21 12:37 ` Ulf Hansson
2025-05-21 14:57 ` Dmitry Torokhov
2025-05-22 9:48 ` Claudiu Beznea
2025-05-22 11:53 ` Ulf Hansson
2025-05-22 14:08 ` Claudiu Beznea
2025-05-22 16:28 ` Ulf Hansson
2025-05-22 18:47 ` Dmitry Torokhov
2025-05-22 22:09 ` Ulf Hansson
2025-05-22 23:06 ` Dmitry Torokhov
2025-05-23 9:47 ` Ulf Hansson
2025-05-23 10:52 ` Claudiu Beznea [this message]
2025-05-23 13:48 ` Ulf Hansson
2025-05-22 14:55 ` Geert Uytterhoeven
2025-05-22 22:24 ` Ulf Hansson
2025-05-22 10:32 ` Ulf Hansson
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=47853bb8-db03-42b1-bcc2-3338fc208abb@tuxon.dev \
--to=claudiu.beznea@tuxon.dev \
--cc=bhelgaas@google.com \
--cc=claudiu.beznea.uj@bp.renesas.com \
--cc=dakr@kernel.org \
--cc=daniel.lezcano@linaro.org \
--cc=dmitry.torokhov@gmail.com \
--cc=geert@linux-m68k.org \
--cc=gregkh@linuxfoundation.org \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=ulf.hansson@linaro.org \
/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