From: "Luca Weiss" <luca.weiss@fairphone.com>
To: "Liam Girdwood" <lgirdwood@gmail.com>,
"Mark Brown" <broonie@kernel.org>, <linux-kernel@vger.kernel.org>,
"Griffin Kroah-Hartman" <griffin.kroah@fairphone.com>
Subject: Unexpected behavior of of_regulator_get()?
Date: Wed, 29 Apr 2026 10:18:31 +0200 [thread overview]
Message-ID: <DI5HOWHCCKKD.1SQFAA3L4QFDI@fairphone.com> (raw)
Hi Mark and Liam,
My colleague Griffin is currently working on a patchset and while doing
this we discovered some seemingly unexpected behavior with the
of_regulator_get() family of functions.
In a simplified version, we have this devicetree structure:
gpio-keys {
compatible = "gpio-keys";
event-hall-sensor {
label = "Hall Effect Sensor";
vdd-supply = <&vreg_l10b>;
};
key-volume-up {
label = "Volume Up";
};
switch {
label = "Switch";
};
};
Then on each subnode ("child") we call this function:
devm_of_regulator_get_optional(dev, to_of_node(child), "vdd");
The expected behavior would be that for event-hall-sensor it sucessfully
gets the vdd-supply, and for key-volume-up and switch it does not, and
return -ENODEV.
However we see that for every one of the 3 nodes it successfully gets
the vdd-supply.
Looking through the code this seems to be caused by of_get_regulator()
first doing of_parse_phandle(node, prop_name, 0) which is checking on
the node itself.
But then if this does not succeed, it calls
of_get_child_regulator(dev->of_node, prop_name) which goes through every
child node of the top-level device (gpio-keys) until it finds a
regulator. So this will find the vdd-supply of event-hall-sensor even
for key-volume-up and switch.
Going through the git history shows this commit from 2018 [0] which
definitely has a different use-case in mind given the commit message so
that very much seems like an unintentional side effect (not that I fully
understand the addressed problem in the first place).
[0] fe06051dbf8a ("regulator/of_get_regulator: add child path to find the regulator supplier")
A workaround from the driver side would be to check for the presence of
vdd-supply on the child (fwnode_property_present(child, "vdd-supply"))
before trying to get a regulator but I feel like resolving this in the
regulator core would be the better solution?
Let me know your thoughts.
Regards
Luca
next reply other threads:[~2026-04-29 8:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-29 8:18 Luca Weiss [this message]
2026-04-30 0:10 ` Unexpected behavior of of_regulator_get()? Mark Brown
2026-04-30 6:44 ` Luca Weiss
2026-04-30 11:18 ` Mark Brown
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=DI5HOWHCCKKD.1SQFAA3L4QFDI@fairphone.com \
--to=luca.weiss@fairphone.com \
--cc=broonie@kernel.org \
--cc=griffin.kroah@fairphone.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.