mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 3/4] watchdog: remove needless error checking for device parameter
Date: Tue, 16 Jul 2024 13:57:10 +0200	[thread overview]
Message-ID: <20240716115711.1956907-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240716115711.1956907-1-a.fatoum@pengutronix.de>

Poller and device parameter are attached to the class device, either
directly or by name. It's thus not really possible for them to fail,
because of a naming conflict, which only leaves the -ENOMEM case as
possible failure.

So far, we failed the watchdog registration, but ultimately device
parameters are optional: If barebox can still limp along in this
low-memory situation, the user is better served by a barebox that can
control the watchdog via the wd command than one that has no watchdog at
all.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/watchdog/wd_core.c | 54 +++++++-------------------------------
 1 file changed, 10 insertions(+), 44 deletions(-)

diff --git a/drivers/watchdog/wd_core.c b/drivers/watchdog/wd_core.c
index 90ae233b0f9e..44f2b6da8cf2 100644
--- a/drivers/watchdog/wd_core.c
+++ b/drivers/watchdog/wd_core.c
@@ -111,19 +111,12 @@ static int watchdog_set_poller(struct param_d *param, void *priv)
 	return 0;
 }
 
-static int watchdog_register_poller(struct watchdog *wd)
+static void watchdog_register_poller(struct watchdog *wd)
 {
-	struct param_d *p;
-	int ret;
+	poller_async_register(&wd->poller, dev_name(&wd->dev));
 
-	ret = poller_async_register(&wd->poller, dev_name(&wd->dev));
-	if (ret)
-		return ret;
-
-	p = dev_add_param_bool(&wd->dev, "autoping", watchdog_set_poller,
-			NULL, &wd->poller_enable, wd);
-
-	return PTR_ERR_OR_ZERO(p);
+	dev_add_param_bool(&wd->dev, "autoping", watchdog_set_poller,
+			   NULL, &wd->poller_enable, wd);
 }
 
 static int watchdog_register_dev(struct watchdog *wd, const char *name, int id)
@@ -194,7 +187,6 @@ static struct restart_handler restart_handler = {
 
 int watchdog_register(struct watchdog *wd)
 {
-	struct param_d *p;
 	const char *alias = NULL;
 	int ret = 0;
 
@@ -210,57 +202,35 @@ int watchdog_register(struct watchdog *wd)
 	if (ret)
 		return ret;
 
-	p = dev_add_param_tristate_ro(&wd->dev, "running", &wd->running);
-	if (IS_ERR(p)) {
-		ret = PTR_ERR(p);
-		goto error_unregister;
-	}
+	dev_add_param_tristate_ro(&wd->dev, "running", &wd->running);
 
 	if (!wd->priority)
 		wd->priority = dev_get_watchdog_priority(wd->hwdev);
 
-	p = dev_add_param_uint32(&wd->dev, "priority",
+	dev_add_param_uint32(&wd->dev, "priority",
 				 watchdog_set_priority, NULL,
 				 &wd->priority, "%u", wd);
-	if (IS_ERR(p)) {
-		ret = PTR_ERR(p);
-		goto error_unregister;
-	}
 
 	/* set some default sane value */
 	if (!wd->timeout_max)
 		wd->timeout_max = 60 * 60 * 24;
 
-	p = dev_add_param_uint32_ro(&wd->dev, "timeout_max",
+	dev_add_param_uint32_ro(&wd->dev, "timeout_max",
 			&wd->timeout_max, "%u");
-	if (IS_ERR(p)) {
-		ret = PTR_ERR(p);
-		goto error_unregister;
-	}
 
 	if (IS_ENABLED(CONFIG_WATCHDOG_POLLER)) {
 		if (!wd->poller_timeout_cur ||
 		    wd->poller_timeout_cur > wd->timeout_max)
 			wd->poller_timeout_cur = wd->timeout_max;
 
-		p = dev_add_param_uint32(&wd->dev, "timeout_cur", watchdog_set_cur,
+		dev_add_param_uint32(&wd->dev, "timeout_cur", watchdog_set_cur,
 				NULL, &wd->poller_timeout_cur, "%u", wd);
-		if (IS_ERR(p)) {
-			ret = PTR_ERR(p);
-			goto error_unregister;
-		}
 
-		ret = watchdog_register_poller(wd);
-		if (ret)
-			goto error_unregister;
+		watchdog_register_poller(wd);
 	}
 
-	p = dev_add_param_uint32(&wd->dev, "seconds_to_expire", param_set_readonly,
+	dev_add_param_uint32(&wd->dev, "seconds_to_expire", param_set_readonly,
 			seconds_to_expire_get, &wd->seconds_to_expire, "%d", wd);
-	if (IS_ERR(p)) {
-		ret = PTR_ERR(p);
-		goto error_unregister;
-	}
 
 	if (!restart_handler.priority) {
 		restart_handler.priority = 10; /* don't override others */
@@ -275,10 +245,6 @@ int watchdog_register(struct watchdog *wd)
 			wd->priority);
 
 	return 0;
-
-error_unregister:
-	unregister_device(&wd->dev);
-	return ret;
 }
 EXPORT_SYMBOL(watchdog_register);
 
-- 
2.39.2




  parent reply	other threads:[~2024-07-16 11:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-16 11:57 [PATCH 1/4] init: mark initcalls const Ahmad Fatoum
2024-07-16 11:57 ` [PATCH 2/4] base: use initcalls instead of linker lists to register classes Ahmad Fatoum
2024-07-16 11:57 ` Ahmad Fatoum [this message]
2024-07-16 11:57 ` [PATCH 4/4] watchdog: factor out device registration into common class code Ahmad Fatoum
2024-07-19  6:26 ` [PATCH 1/4] init: mark initcalls const 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=20240716115711.1956907-3-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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