Commit 95138e01 authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Pavel Machek

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: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: default avatarPavel Machek <pavel@ucw.cz>
parent d33e98a1
...@@ -101,7 +101,7 @@ static int led_pwm_create_fwnode(struct device *dev, struct led_pwm_priv *priv) ...@@ -101,7 +101,7 @@ static int led_pwm_create_fwnode(struct device *dev, struct led_pwm_priv *priv)
{ {
struct fwnode_handle *fwnode; struct fwnode_handle *fwnode;
struct led_pwm led; struct led_pwm led;
int ret = 0; int ret;
memset(&led, 0, sizeof(led)); memset(&led, 0, sizeof(led));
...@@ -111,8 +111,8 @@ static int led_pwm_create_fwnode(struct device *dev, struct led_pwm_priv *priv) ...@@ -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; led.name = to_of_node(fwnode)->name;
if (!led.name) { if (!led.name) {
fwnode_handle_put(fwnode); ret = EINVAL;
return -EINVAL; goto err_child_out;
} }
led.active_low = fwnode_property_read_bool(fwnode, 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) ...@@ -121,12 +121,14 @@ static int led_pwm_create_fwnode(struct device *dev, struct led_pwm_priv *priv)
&led.max_brightness); &led.max_brightness);
ret = led_pwm_add(dev, priv, &led, fwnode); ret = led_pwm_add(dev, priv, &led, fwnode);
if (ret) { if (ret)
fwnode_handle_put(fwnode); goto err_child_out;
break;
}
} }
return 0;
err_child_out:
fwnode_handle_put(fwnode);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment