mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Christian Eggers <ceggers@arri.de>
To: barebox@lists.infradead.org
Cc: Christian Eggers <ceggers@arri.de>, ceggers@gmx.de
Subject: [PATCH] watchdog: Fix error path
Date: Tue, 21 Jan 2020 12:02:41 +0100	[thread overview]
Message-ID: <20200121110241.14724-1-ceggers@arri.de> (raw)

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

             reply	other threads:[~2020-01-21 11:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-21 11:02 Christian Eggers [this message]
2020-01-22  8:23 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200121110241.14724-1-ceggers@arri.de \
    --to=ceggers@arri.de \
    --cc=barebox@lists.infradead.org \
    --cc=ceggers@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox