public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] leds: gpio: Fix device teardown on probe deferral
@ 2015-04-14 21:23 Sebastian Hesselbarth
  2015-04-15  9:11 ` Jacek Anaszewski
  0 siblings, 1 reply; 5+ messages in thread
From: Sebastian Hesselbarth @ 2015-04-14 21:23 UTC (permalink / raw)
  To: Sebastian Hesselbarth; +Cc: Bryan Wu, Richard Purdie, linux-leds, linux-kernel

In gpio_leds_create(), when devm_get_gpiod_from_child() fails with
-EPROBE_DEFER on the second gpio led to be created, the first already
registered led is not torn down properly. This causes create_gpio_led()
to fail for the first led on re-probe().

Fix this misbehaviour by incrementing num_leds only if all
potentially failing calls completed successfully.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: Bryan Wu <cooloney@gmail.com>
Cc: Richard Purdie <rpurdie@rpsys.net>
Cc: linux-leds@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/leds/leds-gpio.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index d26af0a79a90..f2eb13805b92 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -217,18 +217,19 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)
 		if (fwnode_property_present(child, "retain-state-suspended"))
 			led.retain_state_suspended = 1;
 
-		ret = create_gpio_led(&led, &priv->leds[priv->num_leds++],
+		ret = create_gpio_led(&led, &priv->leds[priv->num_leds],
 				      dev, NULL);
 		if (ret < 0) {
 			fwnode_handle_put(child);
 			goto err;
 		}
+		priv->num_leds++;
 	}
 
 	return priv;
 
 err:
-	for (count = priv->num_leds - 2; count >= 0; count--)
+	for (count = priv->num_leds - 1; count >= 0; count--)
 		delete_gpio_led(&priv->leds[count]);
 	return ERR_PTR(ret);
 }
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] leds: gpio: Fix device teardown on probe deferral
  2015-04-14 21:23 [PATCH] leds: gpio: Fix device teardown on probe deferral Sebastian Hesselbarth
@ 2015-04-15  9:11 ` Jacek Anaszewski
  2015-04-15  9:29   ` Sebastian Hesselbarth
  2015-04-20 18:23   ` Bryan Wu
  0 siblings, 2 replies; 5+ messages in thread
From: Jacek Anaszewski @ 2015-04-15  9:11 UTC (permalink / raw)
  To: Sebastian Hesselbarth; +Cc: Bryan Wu, Richard Purdie, linux-leds, linux-kernel

Hi Sebastian,

On 04/14/2015 11:23 PM, Sebastian Hesselbarth wrote:
> In gpio_leds_create(), when devm_get_gpiod_from_child() fails with
> -EPROBE_DEFER on the second gpio led to be created, the first already
> registered led is not torn down properly. This causes create_gpio_led()
> to fail for the first led on re-probe().
>
> Fix this misbehaviour by incrementing num_leds only if all
> potentially failing calls completed successfully.
>
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
> ---
> Cc: Bryan Wu <cooloney@gmail.com>
> Cc: Richard Purdie <rpurdie@rpsys.net>
> Cc: linux-leds@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
>   drivers/leds/leds-gpio.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)

For this patch:

Acked-by: Jacek Anaszewski <j.anaszewski@samsung.com>

I have a question regarding the sequence above on line 201:

if (!led.name)
	return ERR_PTR(-EINVAL);

Shouldn't this be also 'goto err"?

-- 
Best Regards,
Jacek Anaszewski

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] leds: gpio: Fix device teardown on probe deferral
  2015-04-15  9:11 ` Jacek Anaszewski
@ 2015-04-15  9:29   ` Sebastian Hesselbarth
  2015-04-15  9:52     ` Jacek Anaszewski
  2015-04-20 18:23   ` Bryan Wu
  1 sibling, 1 reply; 5+ messages in thread
From: Sebastian Hesselbarth @ 2015-04-15  9:29 UTC (permalink / raw)
  To: Jacek Anaszewski; +Cc: Bryan Wu, Richard Purdie, linux-leds, linux-kernel

On 04/15/2015 11:11 AM, Jacek Anaszewski wrote:
> On 04/14/2015 11:23 PM, Sebastian Hesselbarth wrote:
>> In gpio_leds_create(), when devm_get_gpiod_from_child() fails with
>> -EPROBE_DEFER on the second gpio led to be created, the first already
>> registered led is not torn down properly. This causes create_gpio_led()
>> to fail for the first led on re-probe().
>>
>> Fix this misbehaviour by incrementing num_leds only if all
>> potentially failing calls completed successfully.
>>
>> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
>> ---
>> Cc: Bryan Wu <cooloney@gmail.com>
>> Cc: Richard Purdie <rpurdie@rpsys.net>
>> Cc: linux-leds@vger.kernel.org
>> Cc: linux-kernel@vger.kernel.org
>> ---
>>   drivers/leds/leds-gpio.c | 5 +++--
>>   1 file changed, 3 insertions(+), 2 deletions(-)
>
> For this patch:
>
> Acked-by: Jacek Anaszewski <j.anaszewski@samsung.com>

Jacek, Thanks!

> I have a question regarding the sequence above on line 201:
>
> if (!led.name)
>      return ERR_PTR(-EINVAL);
>
> Shouldn't this be also 'goto err"?

Yes, every error within the loop has to goto the err label.
Mind to send a patch fixing it?

Sebastian


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] leds: gpio: Fix device teardown on probe deferral
  2015-04-15  9:29   ` Sebastian Hesselbarth
@ 2015-04-15  9:52     ` Jacek Anaszewski
  0 siblings, 0 replies; 5+ messages in thread
From: Jacek Anaszewski @ 2015-04-15  9:52 UTC (permalink / raw)
  To: Sebastian Hesselbarth; +Cc: Bryan Wu, Richard Purdie, linux-leds, linux-kernel

On 04/15/2015 11:29 AM, Sebastian Hesselbarth wrote:
> On 04/15/2015 11:11 AM, Jacek Anaszewski wrote:
>> On 04/14/2015 11:23 PM, Sebastian Hesselbarth wrote:
>>> In gpio_leds_create(), when devm_get_gpiod_from_child() fails with
>>> -EPROBE_DEFER on the second gpio led to be created, the first already
>>> registered led is not torn down properly. This causes create_gpio_led()
>>> to fail for the first led on re-probe().
>>>
>>> Fix this misbehaviour by incrementing num_leds only if all
>>> potentially failing calls completed successfully.
>>>
>>> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
>>> ---
>>> Cc: Bryan Wu <cooloney@gmail.com>
>>> Cc: Richard Purdie <rpurdie@rpsys.net>
>>> Cc: linux-leds@vger.kernel.org
>>> Cc: linux-kernel@vger.kernel.org
>>> ---
>>>   drivers/leds/leds-gpio.c | 5 +++--
>>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> For this patch:
>>
>> Acked-by: Jacek Anaszewski <j.anaszewski@samsung.com>
>
> Jacek, Thanks!
>
>> I have a question regarding the sequence above on line 201:
>>
>> if (!led.name)
>>      return ERR_PTR(-EINVAL);
>>
>> Shouldn't this be also 'goto err"?
>
> Yes, every error within the loop has to goto the err label.
> Mind to send a patch fixing it?

OK, I'll take care of it.

-- 
Best Regards,
Jacek Anaszewski

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] leds: gpio: Fix device teardown on probe deferral
  2015-04-15  9:11 ` Jacek Anaszewski
  2015-04-15  9:29   ` Sebastian Hesselbarth
@ 2015-04-20 18:23   ` Bryan Wu
  1 sibling, 0 replies; 5+ messages in thread
From: Bryan Wu @ 2015-04-20 18:23 UTC (permalink / raw)
  To: Jacek Anaszewski
  Cc: Sebastian Hesselbarth, Richard Purdie, Linux LED Subsystem, lkml

On Wed, Apr 15, 2015 at 2:11 AM, Jacek Anaszewski
<j.anaszewski@samsung.com> wrote:
> Hi Sebastian,
>
> On 04/14/2015 11:23 PM, Sebastian Hesselbarth wrote:
>>
>> In gpio_leds_create(), when devm_get_gpiod_from_child() fails with
>> -EPROBE_DEFER on the second gpio led to be created, the first already
>> registered led is not torn down properly. This causes create_gpio_led()
>> to fail for the first led on re-probe().
>>
>> Fix this misbehaviour by incrementing num_leds only if all
>> potentially failing calls completed successfully.
>>
>> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
>> ---
>> Cc: Bryan Wu <cooloney@gmail.com>
>> Cc: Richard Purdie <rpurdie@rpsys.net>
>> Cc: linux-leds@vger.kernel.org
>> Cc: linux-kernel@vger.kernel.org
>> ---
>>   drivers/leds/leds-gpio.c | 5 +++--
>>   1 file changed, 3 insertions(+), 2 deletions(-)
>
>
> For this patch:
>
> Acked-by: Jacek Anaszewski <j.anaszewski@samsung.com>
>

Thanks, I merged it.
-Bryan

> I have a question regarding the sequence above on line 201:
>
> if (!led.name)
>         return ERR_PTR(-EINVAL);
>
> Shouldn't this be also 'goto err"?
>
> --
> Best Regards,
> Jacek Anaszewski

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-04-20 18:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-14 21:23 [PATCH] leds: gpio: Fix device teardown on probe deferral Sebastian Hesselbarth
2015-04-15  9:11 ` Jacek Anaszewski
2015-04-15  9:29   ` Sebastian Hesselbarth
2015-04-15  9:52     ` Jacek Anaszewski
2015-04-20 18:23   ` Bryan Wu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox