Skip to content

Commit

Permalink
leds: el15203000: Make error handling more robust
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Andy Shevchenko authored and Pavel Machek committed May 28, 2021
1 parent 95138e0 commit e101216
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions drivers/leds/leds-el15203000.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,13 @@ static int el15203000_probe_dt(struct el15203000 *priv)
ret = fwnode_property_read_u32(child, "reg", &led->reg);
if (ret) {
dev_err(priv->dev, "LED without ID number");
fwnode_handle_put(child);

break;
goto err_child_out;
}

if (led->reg > U8_MAX) {
dev_err(priv->dev, "LED value %d is invalid", led->reg);
fwnode_handle_put(child);

return -EINVAL;
ret = -EINVAL;
goto err_child_out;
}

led->priv = priv;
Expand All @@ -276,14 +273,16 @@ static int el15203000_probe_dt(struct el15203000 *priv)
dev_err(priv->dev,
"failed to register LED device %s, err %d",
led->ldev.name, ret);
fwnode_handle_put(child);

break;
goto err_child_out;
}

led++;
}

return 0;

err_child_out:
fwnode_handle_put(child);
return ret;
}

Expand Down

0 comments on commit e101216

Please sign in to comment.