All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] reset: Miscellaneous improvements
@ 2019-11-20 14:59 Geert Uytterhoeven
  2019-11-20 14:59 ` [PATCH v2 1/2] reset: Do not register resource data for missing resets Geert Uytterhoeven
  2019-11-20 14:59 ` [PATCH v2 2/2] reset: Align logic and flow in managed helpers Geert Uytterhoeven
  0 siblings, 2 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2019-11-20 14:59 UTC (permalink / raw)
  To: Philipp Zabel; +Cc: linux-kernel, Geert Uytterhoeven

	Hi Philipp,

This patch series contains a resource optimization for the managed
helpers, and an enhancement to make the reset controller code more
uniform.

Changes compared to v1:
  - Use IS_ERR_OR_NULL(),
  - Drop accepted patch.

Thanks!

Geert Uytterhoeven (2):
  reset: Do not register resource data for missing resets
  reset: Align logic and flow in managed helpers

 drivers/reset/core.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

-- 
2.17.1

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 1/2] reset: Do not register resource data for missing resets
  2019-11-20 14:59 [PATCH v2 0/2] reset: Miscellaneous improvements Geert Uytterhoeven
@ 2019-11-20 14:59 ` Geert Uytterhoeven
  2019-11-20 14:59 ` [PATCH v2 2/2] reset: Align logic and flow in managed helpers Geert Uytterhoeven
  1 sibling, 0 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2019-11-20 14:59 UTC (permalink / raw)
  To: Philipp Zabel; +Cc: linux-kernel, Geert Uytterhoeven

When an optional reset is not present, __devm_reset_control_get() and
devm_reset_control_array_get() still register resource data to release
the non-existing reset on cleanup, which is futile.

Fix this by skipping NULL reset control pointers.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - Use IS_ERR_OR_NULL().
---
 drivers/reset/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index c8cc8cacdade0391..7597c70e04d5b42b 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -787,7 +787,7 @@ 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(rstc)) {
+	if (!IS_ERR_OR_NULL(rstc)) {
 		*ptr = rstc;
 		devres_add(dev, ptr);
 	} else {
@@ -928,7 +928,7 @@ devm_reset_control_array_get(struct device *dev, bool shared, bool optional)
 		return ERR_PTR(-ENOMEM);
 
 	rstc = of_reset_control_array_get(dev->of_node, shared, optional, true);
-	if (IS_ERR(rstc)) {
+	if (IS_ERR_OR_NULL(rstc)) {
 		devres_free(devres);
 		return rstc;
 	}
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2 2/2] reset: Align logic and flow in managed helpers
  2019-11-20 14:59 [PATCH v2 0/2] reset: Miscellaneous improvements Geert Uytterhoeven
  2019-11-20 14:59 ` [PATCH v2 1/2] reset: Do not register resource data for missing resets Geert Uytterhoeven
@ 2019-11-20 14:59 ` Geert Uytterhoeven
  1 sibling, 0 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2019-11-20 14:59 UTC (permalink / raw)
  To: Philipp Zabel; +Cc: linux-kernel, Geert Uytterhoeven

__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>
---
v2:
  - Use IS_ERR_OR_NULL().
---
 drivers/reset/core.c | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 7597c70e04d5b42b..01c0c7aa835cbfe2 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -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);
@@ -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);
@@ -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;
 }
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-11-20 14:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-20 14:59 [PATCH v2 0/2] reset: Miscellaneous improvements Geert Uytterhoeven
2019-11-20 14:59 ` [PATCH v2 1/2] reset: Do not register resource data for missing resets Geert Uytterhoeven
2019-11-20 14:59 ` [PATCH v2 2/2] reset: Align logic and flow in managed helpers Geert Uytterhoeven

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.