regulator: core: Don't link consumers on the same device
Mark Brown
maintainerPATCH 1/1 regulator: core: Don't link consumers on the same device
In some cases a device may end up supplying itself, for example when a DCDC is used to improve the efficiency of LDOs or when a LDO is provided to clean up sensitive supplies. In these cases the driver core will warn loudly about attempts to add links so suppress them here.
---
Compile tested only.
drivers/regulator/core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/regulator/core.c +3 -2
@@ -1741,7 +1741,8 @@ struct regulator *_regulator_get(struct device *dev, const char *id, rdev->use_count =0 ; } -device_link_add (dev, &rdev->dev,DL_FLAG_STATELESS ); +if (dev != &rdev->dev) +device_link_add (dev, &rdev->dev,DL_FLAG_STATELESS );return regulator; }
@@ -1840,7 +1841,7 @@ static void _regulator_put(struct regulator *regulator)if (r->dev == regulator->dev) count++; -if (count ==1 ) +if (count ==1 && regulator->dev != &rdev->dev)device_link_remove (regulator->dev, &rdev->dev);/* remove any sysfs entries */
Signature · 1 line
2.18.0.rc2
Hi Mark,
Quoted 10 lines · Mark Brown
In some cases a device may end up supplying itself, for example when a DCDC is used to improve the efficiency of LDOs or when a LDO is provided to clean up sensitive supplies. In these cases the driver core will warn loudly about attempts to add links so suppress them here.
Reported-by Marek Szyprowski <[email protected]>Signed-off-by Mark Brown <[email protected]>---
Compile tested only.
This patch doesn't help, because wm8994 creates separate struct device for each registered regulator, so you need to check the regulator parents too, see my fixes below in the patch.
I don't like such fixes for this specific case. It's not that uncommon that a complex device provides various functionalities used by its components, so it is not a bad design to use regulator provided by its parent/grandparent/other ancestor device.
Frankly, either the device_is_dependent() function should be exported and used in regulator core or device_link_add() should have another flag:DL_FLAG_SKIP_DEPENDANT.
drivers/regulator/core.c struct regulator *_regulator_get(struct device *dev, const char *id, · line 1744
Quoted 13 lines
drivers/regulator/core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/regulator/core.c +1
-1@@ -1741,7 +1741,8 @@ struct regulator *_regulator_get(struct device *dev, const char *id, rdev->use_count =0 ; } -device_link_add (dev, &rdev->dev,DL_FLAG_STATELESS ); +if (dev != &rdev->dev)
if (dev != &rdev->dev && dev != rdev->dev.parent)
drivers/regulator/core.c static void _regulator_put(struct regulator *regulator) · line 1844
Quoted 10 lines
drivers/regulator/core.c +2
-1+device_link_add (dev, &rdev->dev,DL_FLAG_STATELESS );return regulator; }@@ -1840,7 +1841,7 @@ static void _regulator_put(struct regulator *regulator)if (r->dev == regulator->dev) count++; -if (count ==1 ) +if (count ==1 && regulator->dev != &rdev->dev)
if (count == 1 && regulator->dev != &rdev->dev && regulator->dev != rdev->dev.parent)
drivers/regulator/core.c static void _regulator_put(struct regulator *regulator) · line 1847
Quoted 3 lines
drivers/regulator/core.c +0
-0device_link_remove (regulator->dev, &rdev->dev);/* remove any sysfs entries */
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
Mark Brown
maintainerQuoted 3 lines · Marek Szyprowski
This patch doesn't help, because wm8994 creates separate struct device for each registered regulator, so you need to check the regulator parents too, see my fixes below in the patch.
Ugh, right - I'd not looked at enough of the context to see what was being checked.
Quoted 8 lines
I don't like such fixes for this specific case. It's not that uncommon that a complex device provides various functionalities used by its components, so it is not a bad design to use regulator provided by its parent/grandparent/other ancestor device.
Frankly, either the
device_is_dependent()function should be exported and used in regulator core ordevice_link_add()should have another flag:DL_FLAG_SKIP_DEPENDANT.
Or it should just make the warning optional at the core level.