summaryrefslogtreecommitdiff
path: root/drivers/leds
diff options
context:
space:
mode:
authorAndy Shevchenko <andy.shevchenko@gmail.com>2021-05-10 12:50:43 +0300
committerPavel Machek <pavel@ucw.cz>2021-05-28 13:00:16 +0300
commit95138e01275e1af3f1fc2780fe1d9c6138b29c7a (patch)
tree7a83ae4e08ad3ba0f8b80b0ffe7522bd49483052 /drivers/leds
parentd33e98a1f3ee76f38668304f9ffce49af07da77a (diff)
downloadlinux-95138e01275e1af3f1fc2780fe1d9c6138b29c7a.tar.xz
leds: pwm: Make error handling more robust
It's easy to miss necessary clean up, e.g. firmware node reference counting, during error path in ->probe(). Make it more robust by moving to a single point of return. Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Pavel Machek <pavel@ucw.cz>
Diffstat (limited to 'drivers/leds')
-rw-r--r--drivers/leds/leds-pwm.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c
index f53f9309ca6c..d71e9fa5c8de 100644
--- a/drivers/leds/leds-pwm.c
+++ b/drivers/leds/leds-pwm.c
@@ -101,7 +101,7 @@ static int led_pwm_create_fwnode(struct device *dev, struct led_pwm_priv *priv)
{
struct fwnode_handle *fwnode;
struct led_pwm led;
- int ret = 0;
+ int ret;
memset(&led, 0, sizeof(led));
@@ -111,8 +111,8 @@ static int led_pwm_create_fwnode(struct device *dev, struct led_pwm_priv *priv)
led.name = to_of_node(fwnode)->name;
if (!led.name) {
- fwnode_handle_put(fwnode);
- return -EINVAL;
+ ret = EINVAL;
+ goto err_child_out;
}
led.active_low = fwnode_property_read_bool(fwnode,
@@ -121,12 +121,14 @@ static int led_pwm_create_fwnode(struct device *dev, struct led_pwm_priv *priv)
&led.max_brightness);
ret = led_pwm_add(dev, priv, &led, fwnode);
- if (ret) {
- fwnode_handle_put(fwnode);
- break;
- }
+ if (ret)
+ goto err_child_out;
}
+ return 0;
+
+err_child_out:
+ fwnode_handle_put(fwnode);
return ret;
}