Skip to content

Commit

Permalink
reset: Align logic and flow in managed helpers
Browse files Browse the repository at this point in the history
__devm_reset_control_get() and devm_reset_control_array_get() are very
similar, but they do not look similar, due to inverted logic.
Make them more similar, following the "bail out early" paradigm.

Adjust the logic and flow in devm_reset_controller_register() to match
the two other functions.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
  • Loading branch information
Geert Uytterhoeven authored and Philipp Zabel committed Jan 2, 2020
1 parent 9c81b2c commit a9457ed
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions drivers/reset/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,14 @@ int devm_reset_controller_register(struct device *dev,
return -ENOMEM;

ret = reset_controller_register(rcdev);
if (!ret) {
*rcdevp = rcdev;
devres_add(dev, rcdevp);
} else {
if (ret) {
devres_free(rcdevp);
return ret;
}

*rcdevp = rcdev;
devres_add(dev, rcdevp);

return ret;
}
EXPORT_SYMBOL_GPL(devm_reset_controller_register);
Expand Down Expand Up @@ -787,13 +788,14 @@ struct reset_control *__devm_reset_control_get(struct device *dev,
return ERR_PTR(-ENOMEM);

rstc = __reset_control_get(dev, id, index, shared, optional, acquired);
if (!IS_ERR_OR_NULL(rstc)) {
*ptr = rstc;
devres_add(dev, ptr);
} else {
if (IS_ERR_OR_NULL(rstc)) {
devres_free(ptr);
return rstc;
}

*ptr = rstc;
devres_add(dev, ptr);

return rstc;
}
EXPORT_SYMBOL_GPL(__devm_reset_control_get);
Expand Down Expand Up @@ -919,22 +921,21 @@ EXPORT_SYMBOL_GPL(of_reset_control_array_get);
struct reset_control *
devm_reset_control_array_get(struct device *dev, bool shared, bool optional)
{
struct reset_control **devres;
struct reset_control *rstc;
struct reset_control **ptr, *rstc;

devres = devres_alloc(devm_reset_control_release, sizeof(*devres),
GFP_KERNEL);
if (!devres)
ptr = devres_alloc(devm_reset_control_release, sizeof(*ptr),
GFP_KERNEL);
if (!ptr)
return ERR_PTR(-ENOMEM);

rstc = of_reset_control_array_get(dev->of_node, shared, optional, true);
if (IS_ERR_OR_NULL(rstc)) {
devres_free(devres);
devres_free(ptr);
return rstc;
}

*devres = rstc;
devres_add(dev, devres);
*ptr = rstc;
devres_add(dev, ptr);

return rstc;
}
Expand Down

0 comments on commit a9457ed

Please sign in to comment.