Commit a9457ed2 authored by Geert Uytterhoeven's avatar Geert Uytterhoeven Committed by Philipp Zabel

reset: Align logic and flow in managed helpers

__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: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
parent 9c81b2cc
...@@ -150,13 +150,14 @@ int devm_reset_controller_register(struct device *dev, ...@@ -150,13 +150,14 @@ int devm_reset_controller_register(struct device *dev,
return -ENOMEM; return -ENOMEM;
ret = reset_controller_register(rcdev); ret = reset_controller_register(rcdev);
if (!ret) { if (ret) {
*rcdevp = rcdev;
devres_add(dev, rcdevp);
} else {
devres_free(rcdevp); devres_free(rcdevp);
return ret;
} }
*rcdevp = rcdev;
devres_add(dev, rcdevp);
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(devm_reset_controller_register); EXPORT_SYMBOL_GPL(devm_reset_controller_register);
...@@ -787,13 +788,14 @@ struct reset_control *__devm_reset_control_get(struct device *dev, ...@@ -787,13 +788,14 @@ struct reset_control *__devm_reset_control_get(struct device *dev,
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
rstc = __reset_control_get(dev, id, index, shared, optional, acquired); rstc = __reset_control_get(dev, id, index, shared, optional, acquired);
if (!IS_ERR_OR_NULL(rstc)) { if (IS_ERR_OR_NULL(rstc)) {
*ptr = rstc;
devres_add(dev, ptr);
} else {
devres_free(ptr); devres_free(ptr);
return rstc;
} }
*ptr = rstc;
devres_add(dev, ptr);
return rstc; return rstc;
} }
EXPORT_SYMBOL_GPL(__devm_reset_control_get); EXPORT_SYMBOL_GPL(__devm_reset_control_get);
...@@ -919,22 +921,21 @@ EXPORT_SYMBOL_GPL(of_reset_control_array_get); ...@@ -919,22 +921,21 @@ EXPORT_SYMBOL_GPL(of_reset_control_array_get);
struct reset_control * struct reset_control *
devm_reset_control_array_get(struct device *dev, bool shared, bool optional) devm_reset_control_array_get(struct device *dev, bool shared, bool optional)
{ {
struct reset_control **devres; struct reset_control **ptr, *rstc;
struct reset_control *rstc;
devres = devres_alloc(devm_reset_control_release, sizeof(*devres), ptr = devres_alloc(devm_reset_control_release, sizeof(*ptr),
GFP_KERNEL); GFP_KERNEL);
if (!devres) if (!ptr)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
rstc = of_reset_control_array_get(dev->of_node, shared, optional, true); rstc = of_reset_control_array_get(dev->of_node, shared, optional, true);
if (IS_ERR_OR_NULL(rstc)) { if (IS_ERR_OR_NULL(rstc)) {
devres_free(devres); devres_free(ptr);
return rstc; return rstc;
} }
*devres = rstc; *ptr = rstc;
devres_add(dev, devres); devres_add(dev, ptr);
return rstc; return rstc;
} }
......
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