mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] watchdog: Fix error path
@ 2020-01-21 11:02 Christian Eggers
  2020-01-22  8:23 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Eggers @ 2020-01-21 11:02 UTC (permalink / raw)
  To: barebox; +Cc: Christian Eggers, ceggers

In case of an error (e.g. dev_add_param_tristate_ro() returns -ENOSYS),
device registration must be reverted.

Signed-off-by: Christian Eggers <ceggers@arri.de>
---
 drivers/watchdog/wd_core.c | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/drivers/watchdog/wd_core.c b/drivers/watchdog/wd_core.c
index b6e2a37b1..34040408f 100644
--- a/drivers/watchdog/wd_core.c
+++ b/drivers/watchdog/wd_core.c
@@ -171,8 +171,10 @@ int watchdog_register(struct watchdog *wd)
 		return ret;
 
 	p = dev_add_param_tristate_ro(&wd->dev, "running", &wd->running);
-	if (IS_ERR(p))
-		return PTR_ERR(p);
+	if (IS_ERR(p)) {
+		ret = PTR_ERR(p);
+		goto error_unregister;
+	}
 
 	if (!wd->priority)
 		wd->priority = dev_get_watchdog_priority(wd->hwdev);
@@ -180,8 +182,10 @@ int watchdog_register(struct watchdog *wd)
 	p = dev_add_param_uint32(&wd->dev, "priority",
 				 watchdog_set_priority, NULL,
 				 &wd->priority, "%u", wd);
-	if (IS_ERR(p))
-		return PTR_ERR(p);
+	if (IS_ERR(p)) {
+		ret = PTR_ERR(p);
+		goto error_unregister;
+	}
 
 	/* set some default sane value */
 	if (!wd->timeout_max)
@@ -189,8 +193,10 @@ int watchdog_register(struct watchdog *wd)
 
 	p = dev_add_param_uint32_ro(&wd->dev, "timeout_max",
 			&wd->timeout_max, "%u");
-	if (IS_ERR(p))
-		return PTR_ERR(p);
+	if (IS_ERR(p)) {
+		ret = PTR_ERR(p);
+		goto error_unregister;
+	}
 
 	if (IS_ENABLED(CONFIG_WATCHDOG_POLLER)) {
 		if (!wd->poller_timeout_cur ||
@@ -199,12 +205,14 @@ int watchdog_register(struct watchdog *wd)
 
 		p = dev_add_param_uint32(&wd->dev, "timeout_cur", watchdog_set_cur,
 				NULL, &wd->poller_timeout_cur, "%u", wd);
-		if (IS_ERR(p))
-			return PTR_ERR(p);
+		if (IS_ERR(p)) {
+			ret = PTR_ERR(p);
+			goto error_unregister;
+		}
 
 		ret = watchdog_register_poller(wd);
 		if (ret)
-			return ret;
+			goto error_unregister;
 	}
 
 	list_add_tail(&wd->list, &watchdog_list);
@@ -213,6 +221,10 @@ int watchdog_register(struct watchdog *wd)
 			wd->priority);
 
 	return 0;
+
+error_unregister:
+	unregister_device(&wd->dev);
+	return ret;
 }
 EXPORT_SYMBOL(watchdog_register);
 
-- 
Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] watchdog: Fix error path
  2020-01-21 11:02 [PATCH] watchdog: Fix error path Christian Eggers
@ 2020-01-22  8:23 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2020-01-22  8:23 UTC (permalink / raw)
  To: Christian Eggers; +Cc: barebox, ceggers

On Tue, Jan 21, 2020 at 12:02:41PM +0100, Christian Eggers wrote:
> In case of an error (e.g. dev_add_param_tristate_ro() returns -ENOSYS),
> device registration must be reverted.
> 
> Signed-off-by: Christian Eggers <ceggers@arri.de>
> ---
>  drivers/watchdog/wd_core.c | 30 +++++++++++++++++++++---------
>  1 file changed, 21 insertions(+), 9 deletions(-)

Applied, thanks

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2020-01-22  8:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-21 11:02 [PATCH] watchdog: Fix error path Christian Eggers
2020-01-22  8:23 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox