Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: Matti Vaittinen <mazziesaccount@gmail.com>
To: Mark Brown <broonie@kernel.org>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: "Stephen Boyd" <sboyd@kernel.org>,
	"Matti Vaittinen" <matti.vaittinen@fi.rohmeurope.com>,
	dri-devel@lists.freedesktop.org,
	"Johan Hovold" <johan+linaro@kernel.org>,
	"Neil Armstrong" <narmstrong@baylibre.com>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Kevin Hilman" <khilman@baylibre.com>,
	linux-kernel@vger.kernel.org, "Daniel Vetter" <daniel@ffwll.ch>,
	linux-amlogic@lists.infradead.org,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	linux-doc@vger.kernel.org, "Jonathan Cameron" <jic23@kernel.org>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Miaoqian Lin" <linmq006@gmail.com>,
	linux-arm-kernel@lists.infradead.org,
	"Alexandru Tachici" <alexandru.tachici@analog.com>,
	"Jerome Brunet" <jbrunet@baylibre.com>,
	"Andrzej Hajda" <andrzej.hajda@intel.com>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Guenter Roeck" <linux@roeck-us.net>,
	"Jonas Karlman" <jonas@kwiboo.se>,
	"Lorenzo Bianconi" <lorenzo@kernel.org>,
	"Michael Turq uette" <mturquette@baylibre.com>,
	"Jernej Skrabec" <jernej.skrabec@gmail.com>,
	"Martin Blumenstingl" <martin.blumenstingl@googlemail.com>,
	"Jean Delvare" <jdelvare@suse.com>,
	"Alexandru Ardelean" <aardelean@deviqon.com>,
	linux-hwmon@vger.kernel.org, linux-clk@vger.kernel.org,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Robert Foss" <robert.foss@linaro.org>,
	"Aswath Govindraju" <a-govindraju@ti.com>,
	"David Airlie" <airlied@linux.ie>,
	linux-iio@vger.kernel.org
Subject: Re: (subset) [PATCH v2 0/7] Devm helpers for regulator get and enable
Date: Tue, 16 Aug 2022 07:56:06 +0300	[thread overview]
Message-ID: <57c312b3-ca5b-6efb-6356-43b6513a0c88@gmail.com> (raw)
In-Reply-To: <YvrO+velKdYdGVve@sirena.org.uk>

Hi dee Ho Mark, Laurent, Stephen, all

On 8/16/22 01:55, Mark Brown wrote:
> On Tue, Aug 16, 2022 at 12:17:17AM +0300, Laurent Pinchart wrote:
>> On Mon, Aug 15, 2022 at 01:58:55PM -0700, Stephen Boyd wrote:
> 
>> You will very quickly see drivers doing this (either directly or
>> indirectly):
> 
>> probe()
>> {
>> 	devm_clk_get_enabled();
>> 	devm_regulator_get_enable();
>> }
> 
>> Without a devres-based get+enable API drivers can get the resources they
>> need in any order, possibly moving some of those resource acquisition
>> operations to different functions, and then have a clear block of code
>> that enables the resources in the right order.

I agree. And I think that drivers which do that should stick with it. 
Still, as you know the devm-unwinding is also done in well defined 
order. I believe that instead of fighting against the devm we should try 
educate people to pay attention in the order of unwinding (also when not 
handled by the devm. Driver writers occasionally break things also w/o 
devm for example by freeing resources needed by IRQ handlers prior 
freeing the IRQ.)

If "purging" must not be done in reverse order compared to the 
aquisition - then one should not use devm. I know people have done 
errors with devm - OTOH, I've seen devm also fixing bunch of errors.

>> These devres helpers give
>> a false sense of security to driver authors and they will end up
>> introducing problems, the same way that devm_kzalloc() makes it
>> outrageously easy to crash the kernel by disconnecting a device that is
>> in use.

I think this is going a bit "off-topic" but I'd like to understand what 
is behind this statement? From device-writer's perspective - I don't 
know much better alternatives to free up the memory. I don't see how 
freeing stuff at .remove would be any better? As far as I understand - 
if someone is using driver's resources after the device has gone and the 
driver is detached, then there is not much the driver could do to 
free-up the stuff be it devm or not? This sounds like fundamentally 
different problem (to me).

> TBH I think the problem you have here is with devm not with this
> particular function.

I must say I kind of agree with Mark. If we stop for a second to think 
what would the Laurent's example look like if there were no 
devm_regulator_get_enable() provided. I bet the poor driver author could 
have used devm_clk_get_enabled() - and then implemented a .remove for 
disabling the regulator. That would be even worse, right?

> That's a different conversation, and a totally
> valid one especially when you start looking at things like implementing
> userspace APIs which need to cope with hardware going away while still
> visible to userspace.

This is interesting. It's not easy for me to spot how devm changes 
things here? If we consider some removable device - then I guess also 
the .remove() is ran only after HW has already gone? Yes, devm might 
make the time window when userspace can see hardware that has gone 
longer but does it bring any new problem there? It seems to me devm can 
make hitting the spot more likely - but I don't think it brings 
completely new issues? (Well, I may be wrong here - wouldn't be the 
first time :])

> It's *probably* more of a subsystem conversation
> than a driver one though, or at least I think subsystems should try to
> arrange to make it so.


-- 
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~

Discuss - Estimate - Plan - Report and finally accomplish this:
void do_work(int time) __attribute__ ((const));

  reply	other threads:[~2022-08-16  7:22 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-12 10:08 [PATCH v2 0/7] Devm helpers for regulator get and enable Matti Vaittinen
2022-08-12 10:11 ` [PATCH v2 6/7] hwmon: lm90: simplify using devm_regulator_get_enable() Matti Vaittinen
     [not found] ` <166057828406.697572.228317501909350108.b4-ty@kernel.org>
2022-08-15 15:54   ` (subset) [PATCH v2 0/7] Devm helpers for regulator get and enable Laurent Pinchart
2022-08-15 16:33     ` Mark Brown
2022-08-15 18:52       ` Laurent Pinchart
2022-08-15 20:58         ` Stephen Boyd
2022-08-15 21:17           ` Laurent Pinchart
2022-08-15 22:55             ` Mark Brown
2022-08-16  4:56               ` Matti Vaittinen [this message]
2022-08-16 10:36                 ` Mark Brown
2022-08-16 11:06                   ` Vaittinen, Matti
2022-08-16 11:31                     ` Mark Brown
2022-08-16  8:42             ` Andy Shevchenko
2022-08-15 22:07           ` Mark Brown
2022-08-30 19:42             ` Stephen Boyd
2022-08-16  8:23         ` Andy Shevchenko
2022-08-18 11:33   ` Matti Vaittinen
2022-08-18 11:54     ` Mark Brown
2022-08-18 12:04       ` Vaittinen, Matti

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=57c312b3-ca5b-6efb-6356-43b6513a0c88@gmail.com \
    --to=mazziesaccount@gmail.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=a-govindraju@ti.com \
    --cc=aardelean@deviqon.com \
    --cc=airlied@linux.ie \
    --cc=alexandru.tachici@analog.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andrzej.hajda@intel.com \
    --cc=broonie@kernel.org \
    --cc=corbet@lwn.net \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jbrunet@baylibre.com \
    --cc=jdelvare@suse.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=jic23@kernel.org \
    --cc=johan+linaro@kernel.org \
    --cc=jonas@kwiboo.se \
    --cc=khilman@baylibre.com \
    --cc=lars@metafoo.de \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=lgirdwood@gmail.com \
    --cc=linmq006@gmail.com \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=lorenzo@kernel.org \
    --cc=martin.blumenstingl@googlemail.com \
    --cc=matti.vaittinen@fi.rohmeurope.com \
    --cc=mturquette@baylibre.com \
    --cc=narmstrong@baylibre.com \
    --cc=nuno.sa@analog.com \
    --cc=robert.foss@linaro.org \
    --cc=sboyd@kernel.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