From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH v2 4/4] watchdog: register watchdog class
Date: Tue, 11 Jun 2024 07:12:37 +0200 [thread overview]
Message-ID: <20240611051237.4126918-5-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20240611051237.4126918-1-s.hauer@pengutronix.de>
Register watchdog devices as class devices. This allows us to implement
for_each_watchdog() by iterating over the network class devices.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/watchdog/wd_core.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/watchdog/wd_core.c b/drivers/watchdog/wd_core.c
index 42cbd7b72c..90ae233b0f 100644
--- a/drivers/watchdog/wd_core.c
+++ b/drivers/watchdog/wd_core.c
@@ -11,7 +11,9 @@
#include <watchdog.h>
#include <restart.h>
-static LIST_HEAD(watchdog_list);
+#define for_each_watchdog(wd) list_for_each_entry(wd, &watchdog_class.devices, dev.class_list)
+
+DEFINE_DEV_CLASS(watchdog_class, "watchdog");
static const char *watchdog_name(struct watchdog *wd)
{
@@ -267,7 +269,7 @@ int watchdog_register(struct watchdog *wd)
dev_warn(&wd->dev, "failed to register restart handler\n");
}
- list_add_tail(&wd->list, &watchdog_list);
+ class_add_device(&watchdog_class, &wd->dev);
pr_debug("registering watchdog %s with priority %d\n", watchdog_name(wd),
wd->priority);
@@ -287,7 +289,7 @@ int watchdog_deregister(struct watchdog *wd)
poller_async_unregister(&wd->poller);
}
- unregister_device(&wd->dev);
+ class_remove_device(&watchdog_class, &wd->dev);
list_del(&wd->list);
return 0;
@@ -299,7 +301,7 @@ struct watchdog *watchdog_get_default(void)
struct watchdog *tmp, *wd = NULL;
int priority = 0;
- list_for_each_entry(tmp, &watchdog_list, list) {
+ for_each_watchdog(tmp) {
if (tmp->priority > priority) {
priority = tmp->priority;
wd = tmp;
@@ -336,7 +338,7 @@ struct watchdog *watchdog_get_by_name(const char *name)
if (!dev)
return NULL;
- list_for_each_entry(tmp, &watchdog_list, list) {
+ for_each_watchdog(tmp) {
if (dev == tmp->hwdev || dev == &tmp->dev)
return tmp;
}
@@ -350,7 +352,7 @@ int watchdog_inhibit_all(void)
struct watchdog *wd;
int ret = 0;
- list_for_each_entry(wd, &watchdog_list, list) {
+ for_each_watchdog(wd) {
int err;
if (!wd->priority || watchdog_hw_running(wd) == false)
continue;
--
2.39.2
next prev parent reply other threads:[~2024-06-11 5:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-11 5:12 [PATCH v2 0/4] Introduce class devices Sascha Hauer
2024-06-11 5:12 ` [PATCH v2 1/4] net: use for_each_netdev() Sascha Hauer
2024-06-11 5:12 ` [PATCH v2 2/4] base: add class device support Sascha Hauer
2024-06-11 5:12 ` [PATCH v2 3/4] net: register eth class Sascha Hauer
2024-06-11 5:12 ` Sascha Hauer [this message]
2024-06-13 6:41 ` [PATCH v2 0/4] Introduce class devices 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=20240611051237.4126918-5-s.hauer@pengutronix.de \
--to=s.hauer@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