Skip to content

Commit

Permalink
leds: leds-gpio: Defer probing in case of deferred gpio probing
Browse files Browse the repository at this point in the history
This patch makes leds-gpio's probe() return -EPROBE_DEFER if any of the gpios
to register are deferred themselves. This makes a change of
gpio_leds_create_of()'s return value necessary: Instead of returning NULL on
error, we now use ERR_PTR() error coding.

Signed-off-by: Roland Stigge <[email protected]>
Signed-off-by: Bryan Wu <[email protected]>
  • Loading branch information
stigge authored and cooloney committed Nov 26, 2012
1 parent e894192 commit 04553e9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions drivers/leds/leds-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <linux/workqueue.h>
#include <linux/module.h>
#include <linux/pinctrl/consumer.h>
#include <linux/err.h>

struct gpio_led_data {
struct led_classdev cdev;
Expand Down Expand Up @@ -174,12 +175,16 @@ static struct gpio_leds_priv * __devinit gpio_leds_create_of(struct platform_dev
/* count LEDs in this device, so we know how much to allocate */
count = of_get_child_count(np);
if (!count)
return NULL;
return ERR_PTR(-ENODEV);

for_each_child_of_node(np, child)
if (of_get_gpio(child, 0) == -EPROBE_DEFER)
return ERR_PTR(-EPROBE_DEFER);

priv = devm_kzalloc(&pdev->dev, sizeof_gpio_leds_priv(count),
GFP_KERNEL);
if (!priv)
return NULL;
return ERR_PTR(-ENOMEM);

for_each_child_of_node(np, child) {
struct gpio_led led = {};
Expand Down Expand Up @@ -214,7 +219,7 @@ static struct gpio_leds_priv * __devinit gpio_leds_create_of(struct platform_dev
err:
for (count = priv->num_leds - 2; count >= 0; count--)
delete_gpio_led(&priv->leds[count]);
return NULL;
return ERR_PTR(-ENODEV);
}

static const struct of_device_id of_gpio_leds_match[] = {
Expand All @@ -224,7 +229,7 @@ static const struct of_device_id of_gpio_leds_match[] = {
#else /* CONFIG_OF_GPIO */
static struct gpio_leds_priv * __devinit gpio_leds_create_of(struct platform_device *pdev)
{
return NULL;
return ERR_PTR(-ENODEV);
}
#endif /* CONFIG_OF_GPIO */

Expand Down Expand Up @@ -262,8 +267,8 @@ static int __devinit gpio_led_probe(struct platform_device *pdev)
}
} else {
priv = gpio_leds_create_of(pdev);
if (!priv)
return -ENODEV;
if (IS_ERR(priv))
return PTR_ERR(priv);
}

platform_set_drvdata(pdev, priv);
Expand Down

0 comments on commit 04553e9

Please sign in to comment.