Skip to content

Commit aa1a6d6

Browse files
Peter Ujfalusicooloney
authored andcommitted
leds: pwm: Fix for deferred probe in DT booted mode
We need to make sure that the error code from devm_of_pwm_get() is the one the module returns in case of failure. Restructure the code to make this possible for DT booted case. With this patch the driver can ask for deferred probing when the board is booted with DT. Fixes for example omap4-sdp board's keyboard backlight led. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com> Signed-off-by: Bryan Wu <cooloney@gmail.com>
1 parent dc1ccc4 commit aa1a6d6

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

drivers/leds/leds-pwm.c

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,12 @@ static inline size_t sizeof_pwm_leds_priv(int num_leds)
8282
(sizeof(struct led_pwm_data) * num_leds);
8383
}
8484

85-
static struct led_pwm_priv *led_pwm_create_of(struct platform_device *pdev)
85+
static int led_pwm_create_of(struct platform_device *pdev,
86+
struct led_pwm_priv *priv)
8687
{
8788
struct device_node *node = pdev->dev.of_node;
8889
struct device_node *child;
89-
struct led_pwm_priv *priv;
90-
int count, ret;
91-
92-
/* count LEDs in this device, so we know how much to allocate */
93-
count = of_get_child_count(node);
94-
if (!count)
95-
return NULL;
96-
97-
priv = devm_kzalloc(&pdev->dev, sizeof_pwm_leds_priv(count),
98-
GFP_KERNEL);
99-
if (!priv)
100-
return NULL;
90+
int ret;
10191

10292
for_each_child_of_node(node, child) {
10393
struct led_pwm_data *led_dat = &priv->leds[priv->num_leds];
@@ -109,6 +99,7 @@ static struct led_pwm_priv *led_pwm_create_of(struct platform_device *pdev)
10999
if (IS_ERR(led_dat->pwm)) {
110100
dev_err(&pdev->dev, "unable to request PWM for %s\n",
111101
led_dat->cdev.name);
102+
ret = PTR_ERR(led_dat->pwm);
112103
goto err;
113104
}
114105
/* Get the period from PWM core when n*/
@@ -137,28 +128,36 @@ static struct led_pwm_priv *led_pwm_create_of(struct platform_device *pdev)
137128
priv->num_leds++;
138129
}
139130

140-
return priv;
131+
return 0;
141132
err:
142133
while (priv->num_leds--)
143134
led_classdev_unregister(&priv->leds[priv->num_leds].cdev);
144135

145-
return NULL;
136+
return ret;
146137
}
147138

148139
static int led_pwm_probe(struct platform_device *pdev)
149140
{
150141
struct led_pwm_platform_data *pdata = dev_get_platdata(&pdev->dev);
151142
struct led_pwm_priv *priv;
152-
int i, ret = 0;
143+
int count, i;
144+
int ret = 0;
145+
146+
if (pdata)
147+
count = pdata->num_leds;
148+
else
149+
count = of_get_child_count(pdev->dev.of_node);
150+
151+
if (!count)
152+
return -EINVAL;
153153

154-
if (pdata && pdata->num_leds) {
155-
priv = devm_kzalloc(&pdev->dev,
156-
sizeof_pwm_leds_priv(pdata->num_leds),
157-
GFP_KERNEL);
158-
if (!priv)
159-
return -ENOMEM;
154+
priv = devm_kzalloc(&pdev->dev, sizeof_pwm_leds_priv(count),
155+
GFP_KERNEL);
156+
if (!priv)
157+
return -ENOMEM;
160158

161-
for (i = 0; i < pdata->num_leds; i++) {
159+
if (pdata) {
160+
for (i = 0; i < count; i++) {
162161
struct led_pwm *cur_led = &pdata->leds[i];
163162
struct led_pwm_data *led_dat = &priv->leds[i];
164163

@@ -188,11 +187,11 @@ static int led_pwm_probe(struct platform_device *pdev)
188187
if (ret < 0)
189188
goto err;
190189
}
191-
priv->num_leds = pdata->num_leds;
190+
priv->num_leds = count;
192191
} else {
193-
priv = led_pwm_create_of(pdev);
194-
if (!priv)
195-
return -ENODEV;
192+
ret = led_pwm_create_of(pdev, priv);
193+
if (ret)
194+
return ret;
196195
}
197196

198197
platform_set_drvdata(pdev, priv);

0 commit comments

Comments
 (0)