Skip to contentSkip to conversation

extcon: gpio: Request gpio pin before modifying its state

PATCH In review Guenter Roeck 2 participants 4 messages Nov 22, 2013 – Nov 26, 2013 External connector subsystem (extcon)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 extcon: gpio: Request gpio pin before modifying its state

Commit 338de0ca (extcon: gpio: Use gpio driver/chip debounce if supported) introduced a call to gpio_set_debounce() before actually requesting the respective gpio pin from the gpio subsystem.

The gpio subsystem expects that a gpio pin was requested before modifying its state. Not doing so results in a warning from gpiolib, and the gpio pin is auto-requested. This in turn causes the subsequent devm_gpio_request_one() to fail. So devm_gpio_request_one() must be called prior to calling gpio_set_debounce().

---
 drivers/extcon/extcon-gpio.c |   11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/extcon/extcon-gpio.c +6 -5
index 7e0dff5..4736a9c 100644
@@ -105,6 +105,12 @@ static int gpio_extcon_probe(struct platform_device *pdev)
 	extcon_data->state_off = pdata->state_off;
 	if (pdata->state_on && pdata->state_off)
 		extcon_data->edev.print_state = extcon_gpio_print_state;
+
+	ret = devm_gpio_request_one(&pdev->dev, extcon_data->gpio, GPIOF_DIR_IN,
+				    pdev->name);
+	if (ret < 0)
+		return ret;
+
 	if (pdata->debounce) {
 		ret = gpio_set_debounce(extcon_data->gpio,
 					pdata->debounce * 1000);
@@ -117,11 +123,6 @@ static int gpio_extcon_probe(struct platform_device *pdev)
 	if (ret < 0)
 		return ret;
 
-	ret = devm_gpio_request_one(&pdev->dev, extcon_data->gpio, GPIOF_DIR_IN,
-				    pdev->name);
-	if (ret < 0)
-		goto err;
-
 	INIT_DELAYED_WORK(&extcon_data->work, gpio_extcon_work);
 
 	extcon_data->irq = gpio_to_irq(extcon_data->gpio);
Signature · 1 line
1.7.9.7
maintainer
#1 lore raw

Hi Guenter,

Quoted 10 lines · Guenter Roeck

Commit 338de0ca (extcon: gpio: Use gpio driver/chip debounce if supported) introduced a call to gpio_set_debounce() before actually requesting the respective gpio pin from the gpio subsystem.

The gpio subsystem expects that a gpio pin was requested before modifying its state. Not doing so results in a warning from gpiolib, and the gpio pin is auto-requested. This in turn causes the subsequent devm_gpio_request_one() to fail. So devm_gpio_request_one() must be called prior to calling gpio_set_debounce().

Quoted 5 lines
---
 drivers/extcon/extcon-gpio.c |   11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Applid it on extcon-next branch.

Thanks,
Chanwoo Choi

#2 lore raw
Quoted 13 lines · Chanwoo Choi

Hi Guenter,

Quoted 10 lines · Guenter Roeck

Commit 338de0ca (extcon: gpio: Use gpio driver/chip debounce if supported) introduced a call to gpio_set_debounce() before actually requesting the respective gpio pin from the gpio subsystem.

The gpio subsystem expects that a gpio pin was requested before modifying its state. Not doing so results in a warning from gpiolib, and the gpio pin is auto-requested. This in turn causes the subsequent devm_gpio_request_one() to fail. So devm_gpio_request_one() must be called prior to calling gpio_set_debounce().

Quoted 8 lines
Quoted 5 lines
---
  drivers/extcon/extcon-gpio.c |   11 ++++++-----
  1 file changed, 6 insertions(+), 5 deletions(-)

Applid it on extcon-next branch.

As this is a bug fix, I think it would make sense to have this applied to the current kernel and not wait for 3.14.

Thanks,
Guenter

maintainer
#3 lore raw
Quoted 20 lines · Guenter Roeck
Quoted 19 lines · Chanwoo Choi

Hi Guenter,

Quoted 15 lines · Guenter Roeck

Commit 338de0ca (extcon: gpio: Use gpio driver/chip debounce if supported) introduced a call to gpio_set_debounce() before actually requesting the respective gpio pin from the gpio subsystem.

The gpio subsystem expects that a gpio pin was requested before modifying its state. Not doing so results in a warning from gpiolib, and the gpio pin is auto-requested. This in turn causes the subsequent devm_gpio_request_one() to fail. So devm_gpio_request_one() must be called prior to calling gpio_set_debounce().

---
  drivers/extcon/extcon-gpio.c |   11 ++++++-----
  1 file changed, 6 insertions(+), 5 deletions(-)
Quoted 6 lines
Quoted 2 lines

Applid it on extcon-next branch.

As this is a bug fix, I think it would make sense to have this applied to the current kernel and not wait for 3.14.

OK, I move it on extcon-linus branch.

Thanks,
Chanwoo Choi