From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH] include: add support for NOTIFY_BAD
Date: Tue, 22 Apr 2025 09:56:48 +0200 [thread overview]
Message-ID: <20250422075648.220966-1-a.fatoum@pengutronix.de> (raw)
From: Ahmad Fatoum <a.fatoum@barebox.org>
When notified, returning NOTIFY_BAD or NOTIFY_STOP can be used stop
further calls and inform the original notification site.
Provide the same in barebox.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
include/notifier.h | 16 ++++++++++++++++
lib/notifier.c | 10 +++++++---
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/include/notifier.h b/include/notifier.h
index 093fedb0e8e4..822f8a3d6103 100644
--- a/include/notifier.h
+++ b/include/notifier.h
@@ -37,5 +37,21 @@ int clock_notifier_call_chain(void);
#define NOTIFY_DONE 0x0000 /* Don't care */
#define NOTIFY_OK 0x0001 /* Suits me */
+#define NOTIFY_STOP_MASK 0x8000 /* Don't call further */
+#define NOTIFY_BAD (NOTIFY_STOP_MASK|0x0002)
+ /* Bad/Veto action */
+/*
+ * Clean way to return from the notifier and stop further calls.
+ */
+#define NOTIFY_STOP (NOTIFY_OK|NOTIFY_STOP_MASK)
+
+/* Encapsulate (negative) errno value (in particular, NOTIFY_BAD <=> EPERM). */
+static inline int notifier_from_errno(int err)
+{
+ if (err)
+ return NOTIFY_STOP_MASK | (NOTIFY_OK - err);
+
+ return NOTIFY_OK;
+}
#endif /* __NOTIFIER_H */
diff --git a/lib/notifier.c b/lib/notifier.c
index 3ca557f76df2..775619d3c06f 100644
--- a/lib/notifier.c
+++ b/lib/notifier.c
@@ -19,11 +19,15 @@ int notifier_chain_unregister(struct notifier_head *nh, struct notifier_block *n
int notifier_call_chain(struct notifier_head *nh, unsigned long val, void *v)
{
struct notifier_block *entry, *tmp;
+ int ret = NOTIFY_DONE;
- list_for_each_entry_safe(entry, tmp, &nh->blocks, list)
- entry->notifier_call(entry, val, v);
+ list_for_each_entry_safe(entry, tmp, &nh->blocks, list) {
+ ret = entry->notifier_call(entry, val, v);
+ if (ret & NOTIFY_STOP_MASK)
+ break;
+ }
- return 0;
+ return ret;
}
/*
--
2.39.5
next reply other threads:[~2025-04-22 8:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-22 7:56 Ahmad Fatoum [this message]
2025-04-22 9:01 ` 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=20250422075648.220966-1-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