Skip to contentSkip to conversation

regulator: core: Still free GPIOs using gpio_free()

PATCH In review Mark Brown 4 participants 7 messages Jul 1, 2014 – Jul 8, 2014 Voltage and current regulator framework

lore
Share & tools
lore

Mark Brown

author maintainer
#0 lore raw

PATCH 1/1 regulator: core: Still free GPIOs using gpio_free()

From: Mark Brown <[email protected]>

Even though we mostly use GPIO descriptors internally we still use gpio_request_one() to request so we need to pair that with gpio_free() to release the GPIO.

---
 drivers/regulator/core.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/regulator/core.c +6 -1
index c563d93125cd..80381409f856 100644
@@ -1710,7 +1710,12 @@ static void regulator_ena_gpio_free(struct regulator_dev *rdev)
 		if (pin->gpiod == rdev->ena_pin->gpiod) {
 			if (pin->request_count <= 1) {
 				pin->request_count = 0;
-				gpiod_put(pin->gpiod);
+				/*
+				 * Since we requested with gpio_request_one()
+				 * we still need to free with gpio_free()
+				 * for now.
+				 */
+				gpio_free(desc_to_gpio(pin->gpiod));
 				list_del(&pin->list);
 				kfree(pin);
 			} else {
Signature · 1 line
2.0.0
#1 lore raw
Quoted 8 lines · Mark Brown

From: Mark Brown <[email protected]>

Even though we mostly use GPIO descriptors internally we still use gpio_request_one() to request so we need to pair that with gpio_free() to release the GPIO.

This doesn't explain the reason... I see the current GPIO code doing this:

void gpio_free(unsigned gpio)

{
        gpiod_free(gpio_to_desc(gpio));
}

EXPORT_SYMBOL_GPL(gpio_free);

Signature · 2 lines
FTTC broadband for 0.8mile line: now at 9.7Mbps down 460kbps up... slowly
improving, and getting towards what was expected from it.
author maintainer
#2 lore raw
Quoted 6 lines · Russell King - ARM Linux
Quoted 3 lines · Mark Brown

Even though we mostly use GPIO descriptors internally we still use gpio_request_one() to request so we need to pair that with gpio_free() to release the GPIO.

Quoted 7 lines

This doesn't explain the reason... I see the current GPIO code doing this:

void gpio_free(unsigned gpio)

{
        gpiod_free(gpio_to_desc(gpio));
}

EXPORT_SYMBOL_GPL(gpio_free);

Huh, good point (though it still seems a bit neater to match up the
request and release functions I guess). Linus?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140701/833c328d/attachment.sig>

#3 lore raw
Quoted 9 lines · Mark Brown
Quoted 7 lines · Russell King - ARM Linux
Quoted 3 lines · Mark Brown

Even though we mostly use GPIO descriptors internally we still use gpio_request_one() to request so we need to pair that with gpio_free() to release the GPIO.

This doesn't explain the reason... I see the current GPIO code doing this:

Quoted 8 lines
Quoted 5 lines

void gpio_free(unsigned gpio)

{
        gpiod_free(gpio_to_desc(gpio));
}

EXPORT_SYMBOL_GPL(gpio_free);

Huh, good point (though it still seems a bit neater to match up the request and release functions I guess). Linus?

Yeah it's a nice habit to free the GPIOs using the same interface as the one used to obtain them. Although if we are to allow the regulator framework to request GPIO through both the integer and descriptor interfaces, we certainly don't want to track that information forever.

On top of that we want to limit the use of gpio_to_desc() and desc_to_gpio() in drivers as much as possible, so I'd say I prefer to see gpiod_free() used no matter where the GPIO came from.

author maintainer
#4 lore raw
Quoted 5 lines · Alexandre Courbot
Quoted 2 lines · Mark Brown

Huh, good point (though it still seems a bit neater to match up the request and release functions I guess). Linus?

Quoted 8 lines

Yeah it's a nice habit to free the GPIOs using the same interface as the one used to obtain them. Although if we are to allow the regulator framework to request GPIO through both the integer and descriptor interfaces, we certainly don't want to track that information forever.

On top of that we want to limit the use of gpio_to_desc() and desc_to_gpio() in drivers as much as possible, so I'd say I prefer to see gpiod_free() used no matter where the GPIO came from.

Right, but Linus said we didn't need this conversion to descriptors so
I'm a bit confused as to what the issue he was raising was.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140701/cf003a82/attachment.sig>

#5 lore raw
Quoted 11 lines · Mark Brown
Quoted 9 lines · Alexandre Courbot
Quoted 2 lines · Mark Brown

Huh, good point (though it still seems a bit neater to match up the request and release functions I guess). Linus?

Yeah it's a nice habit to free the GPIOs using the same interface as the one used to obtain them. Although if we are to allow the regulator framework to request GPIO through both the integer and descriptor interfaces, we certainly don't want to track that information forever.

Quoted 6 lines
Quoted 3 lines

On top of that we want to limit the use of gpio_to_desc() and desc_to_gpio() in drivers as much as possible, so I'd say I prefer to see gpiod_free() used no matter where the GPIO came from.

Right, but Linus said we didn't need this conversion to descriptors so I'm a bit confused as to what the issue he was raising was.

Now I'm probably confusing myself...

All drivers should as far as possible use descriptors internally, doing things like gpio_to_desc() only for backward-compatibility where necessary, with the intent of eventually ridding the integer interfaces entirely.

It may be an eternal project, but hey, we are atleast two of us pursuing it.

Yours,
Linus Walleij

author maintainer
#6 lore raw
Quoted 7 lines · Linus Walleij
Quoted 2 lines · Mark Brown

Right, but Linus said we didn't need this conversion to descriptors so I'm a bit confused as to what the issue he was raising was.

Now I'm probably confusing myself...

Quoted 7 lines

All drivers should as far as possible use descriptors internally, doing things like gpio_to_desc() only for backward-compatibility where necessary, with the intent of eventually ridding the integer interfaces entirely.

It may be an eternal project, but hey, we are atleast two of us pursuing it.

OK, so in that case Russell's code should be fine then and we don't need
to do anything - great!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140708/7ce51eba/attachment.sig>