The probe path of this driver is a bit complex: sometimes the
GPIO descriptor is passed to the regulator core, sometimes
it is not.

To handle it in a simple way: stick with the devm_* resource
management and unhinge the GPIO descriptor devres handling
right before passing it to the regulator core, if we pass it
to the regulator core.

Fixes: e7d2be696faa ("regulator: max8973: Pass descriptor instead of GPIO 
number")
Signed-off-by: Linus Walleij <[email protected]>
---
ChangeLog v3->v4:
- Stick with devm_*, use devm_gpiod_unhinge() to handle the
  descriptor for lifecycling in the regulator core as suggested
  by Charles.
ChangeLog v2->v3:
- Resending.
ChangeLog v1->v2:
- Drop the gpiod_put() on the errorpath after devm_regulator_register()
  as this will be handled by the regulator core.
- Fix the second case of devm_gpiod_get()
- Put a comment in the code so maintainers knows not to
  use managed resources (devm*)
---
 drivers/regulator/max8973-regulator.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/regulator/max8973-regulator.c 
b/drivers/regulator/max8973-regulator.c
index e7a58b509032..9aee1444181d 100644
--- a/drivers/regulator/max8973-regulator.c
+++ b/drivers/regulator/max8973-regulator.c
@@ -808,7 +808,13 @@ static int max8973_probe(struct i2c_client *client,
        config.of_node = client->dev.of_node;
        config.regmap = max->regmap;
 
-       /* Register the regulators */
+       /*
+        * Register the regulators
+        * Turn the GPIO descriptor over to the regulator core for
+        * lifecycle management if we pass an ena_gpiod.
+        */
+       if (config.ena_gpiod)
+               devm_gpiod_unhinge(&client->dev, config.ena_gpiod);
        rdev = devm_regulator_register(&client->dev, &max->desc, &config);
        if (IS_ERR(rdev)) {
                ret = PTR_ERR(rdev);
-- 
2.19.2

Reply via email to