diff mbox series

[08/10] regulator: max77686: Let core handle GPIO descriptor

Message ID 20181128104350.31902-9-linus.walleij@linaro.org
State New
Headers show
Series Regulator ena_gpiod fixups | expand

Commit Message

Linus Walleij Nov. 28, 2018, 10:43 a.m. UTC
Use the gpiod_get_from_of_node() rather than the devm_*
version so that the regulator core can handle the lifecycle
of these descriptors.

Fixes: 96392c3d8ca4 ("regulator: max77686: Pass descriptor instead of GPIO number")
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

---
 drivers/regulator/max77686-regulator.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

-- 
2.19.1

Comments

Charles Keepax Nov. 28, 2018, 3:24 p.m. UTC | #1
On Wed, Nov 28, 2018 at 11:43:48AM +0100, Linus Walleij wrote:
> Use the gpiod_get_from_of_node() rather than the devm_*

> version so that the regulator core can handle the lifecycle

> of these descriptors.

> 

> Fixes: 96392c3d8ca4 ("regulator: max77686: Pass descriptor instead of GPIO number")

> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

> ---

>  drivers/regulator/max77686-regulator.c | 3 +--

>  1 file changed, 1 insertion(+), 2 deletions(-)

> 

> diff --git a/drivers/regulator/max77686-regulator.c b/drivers/regulator/max77686-regulator.c

> index f5cee1775905..236cd42002f0 100644

> --- a/drivers/regulator/max77686-regulator.c

> +++ b/drivers/regulator/max77686-regulator.c

> @@ -255,8 +255,7 @@ static int max77686_of_parse_cb(struct device_node *np,

>  	case MAX77686_BUCK8:

>  	case MAX77686_BUCK9:

>  	case MAX77686_LDO20 ... MAX77686_LDO22:

> -		config->ena_gpiod = devm_gpiod_get_from_of_node(max77686->dev,

> -				np,

> +		config->ena_gpiod = gpiod_get_from_of_node(np,


As this is inside the of_parse_cb, it probably needs some thought
on where the GPIO would need to be freed on which error paths, I
am not sure it is immediately obvious to me but I suspect it will
need to be freed in some cases.

Thanks,
Charles
Linus Walleij Nov. 30, 2018, 9:07 a.m. UTC | #2
On Wed, Nov 28, 2018 at 4:24 PM Charles Keepax
<ckeepax@opensource.cirrus.com> wrote:
> On Wed, Nov 28, 2018 at 11:43:48AM +0100, Linus Walleij wrote:


> > @@ -255,8 +255,7 @@ static int max77686_of_parse_cb(struct device_node *np,

(...)
> > +             config->ena_gpiod = gpiod_get_from_of_node(np,

>

> As this is inside the of_parse_cb, it probably needs some thought

> on where the GPIO would need to be freed on which error paths, I

> am not sure it is immediately obvious to me but I suspect it will

> need to be freed in some cases.


I looked it over and came up with a patch making sure that if
the regulator_of_get_init_data() assigns config->ena_gpiod
it gets freed unless handled over to the regulator core.

Thanks for pointing this out, it was a tricky corner case!

Yours,
Linus Walleij
diff mbox series

Patch

diff --git a/drivers/regulator/max77686-regulator.c b/drivers/regulator/max77686-regulator.c
index f5cee1775905..236cd42002f0 100644
--- a/drivers/regulator/max77686-regulator.c
+++ b/drivers/regulator/max77686-regulator.c
@@ -255,8 +255,7 @@  static int max77686_of_parse_cb(struct device_node *np,
 	case MAX77686_BUCK8:
 	case MAX77686_BUCK9:
 	case MAX77686_LDO20 ... MAX77686_LDO22:
-		config->ena_gpiod = devm_gpiod_get_from_of_node(max77686->dev,
-				np,
+		config->ena_gpiod = gpiod_get_from_of_node(np,
 				"maxim,ena",
 				0,
 				GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE,