Skip to contentSkip to conversation

regulator: core: Fix resolve supply

PATCH In review Kory Maincent 2 participants 6 messages Nov 13, 2024 – Nov 14, 2024 Voltage and current regulator framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 regulator: core: Fix resolve supply

The regulator should not use the device parent to resolve the regulator supply. It fails to resolve the correct supply when the of_node variable in the regulator_config structure is not within the parent node.

Fixes 6261b06de565 ("regulator: Defer lookup of supply to regulator_get")

---

It is weird that it wasn't seen before, maybe there was not any case were it can't find the supply_name from the parent device.

---
 drivers/regulator/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/regulator/core.c +1 -1
index 76d3cd5ae6ea..ee5bc070b5bb 100644
@@ -2023,7 +2023,7 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
 static int regulator_resolve_supply(struct regulator_dev *rdev)
 {
 	struct regulator_dev *r;
-	struct device *dev = rdev->dev.parent;
+	struct device *dev = &rdev->dev;
 	struct ww_acquire_ctx ww_ctx;
 	int ret = 0;
 
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 4 lines · Kory Maincent

The regulator should not use the device parent to resolve the regulator supply. It fails to resolve the correct supply when the of_node variable in the regulator_config structure is not within the parent node.

I can't understand what you are saying here at all. What is "it", why and in what way does it fail and why would we expect it to succeed? How does your proposed change fix whatever the issue is? The DT binding is against the actual device, not the virtual device. Please describe both the problem and the fix more specifically.

drivers/regulator/core.c static struct regulator_dev *regulator_dev_lookup(struct device *dev, · line 2026

Quoted 7 lines
Fixes 6261b06de565 ("regulator: Defer lookup of supply to regulator_get")

static int regulator_resolve_supply(struct regulator_dev *rdev) {

drivers/regulator/core.c +1 -1
 	struct regulator_dev *r;
-	struct device *dev = rdev->dev.parent;
+	struct device *dev = &rdev->dev;

The rdev is a virtual device, it's not going to have any OF configuration, and given that prior to the refactoring in the commit you're referencing in the Fixes: we were using the struct device passed into regulator_register() which should be the same device as we're using here so if there is an issue it doesn't look like it was introduced in the refactoring. What makes you believe that there is an issue in htat commit?

#2 lore raw
Quoted 7 lines · On Wed, 13 Nov 2024 16:05:46 +0000 Mark Brown <[email protected]> wrote:
Quoted 4 lines · Kory Maincent

The regulator should not use the device parent to resolve the regulator supply. It fails to resolve the correct supply when the of_node variable in the regulator_config structure is not within the parent node.

Quoted 5 lines

I can't understand what you are saying here at all. What is "it", why and in what way does it fail and why would we expect it to succeed? How does your proposed change fix whatever the issue is? The DT binding is against the actual device, not the virtual device. Please describe both the problem and the fix more specifically.

Sorry, I was not explicit enough.

Quoted 10 lines

drivers/regulator/core.c static struct regulator_dev *regulator_dev_lookup(struct device *dev, · line 2026

Quoted 7 lines
Fixes 6261b06de565 ("regulator: Defer lookup of supply to regulator_get")

static int regulator_resolve_supply(struct regulator_dev *rdev) {

drivers/regulator/core.c +1 -1
 	struct regulator_dev *r;
-	struct device *dev = rdev->dev.parent;
+	struct device *dev = &rdev->dev;  

The rdev is a virtual device, it's not going to have any OF configuration

It does:
https://elixir.bootlin.com/linux/v6.11.7/source/drivers/regulator/core.c#L5687

My issue is that it does not look for the regulator supply in the OF node described in the regulator_config structure:
https://elixir.bootlin.com/linux/v6.11.7/source/include/linux/regulator/driver.h#L445
It looks at the parent device OF node instead.

My use case is that a PSE controller have several PIs (Power Interface) which can have different regulator supply. A regulator device is registered for each PIs. The OF node used by the regulator core to lookup for the regulator supply is the PSE controller node and its children instead of the node of the PI which is described by the regulator_config->of_node.

Quoted 6 lines

, and given that prior to the refactoring in the commit you're referencing in the Fixes: we were using the struct device passed into regulator_register() which should be the same device as we're using here so if there is an issue it doesn't look like it was introduced in the refactoring. What makes you believe that there is an issue in htat commit?

Yes you are right I looked at it too quickly sorry.

Regards,

Signature · 3 lines
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
maintainer
#3 lore raw
Quoted 10 lines · Kory Maincent

My issue is that it does not look for the regulator supply in the OF node described in the regulator_config structure:
https://elixir.bootlin.com/linux/v6.11.7/source/include/linux/regulator/driver.h#L445
It looks at the parent device OF node instead.

My use case is that a PSE controller have several PIs (Power Interface) which can have different regulator supply. A regulator device is registered for each PIs. The OF node used by the regulator core to lookup for the regulator supply is the PSE controller node and its children instead of the node of the PI which is described by the regulator_config->of_node.

Please resubmit with a clearer commit log.

#4 lore raw
Quoted 7 lines · On Thu, 14 Nov 2024 13:27:55 +0000 Mark Brown <[email protected]> wrote:
Quoted 5 lines · Kory Maincent

My issue is that it does not look for the regulator supply in the OF node described in the regulator_config structure:
https://elixir.bootlin.com/linux/v6.11.7/source/include/linux/regulator/driver.h#L445
It looks at the parent device OF node instead.

Quoted 7 lines
Quoted 5 lines

My use case is that a PSE controller have several PIs (Power Interface) which can have different regulator supply. A regulator device is registered for each PIs. The OF node used by the regulator core to lookup for the regulator supply is the PSE controller node and its children instead of the node of the PI which is described by the regulator_config->of_node.

Please resubmit with a clearer commit log.

Still I am not sure it is the right way to do it.
In regulator_dev_lookup function if the regulator is not found in the dt it uses the dev_name string to look for it.
https://elixir.bootlin.com/linux/v6.11.7/source/drivers/regulator/core.c#L2035

The dev name of the rdev->dev.parent device or the rdev->dev virtual device is not the same. I am not regulator expert therefore I am afraid that the suggested change could break things.

Maybe this change is safer: https://termbin.com/g0xi

Regards,

Signature · 3 lines
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com