All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] of: Build warn for missing fn() in _OF_DECLARE
@ 2025-04-17 13:23 Liya Huang
  2025-04-22 12:48 ` Rob Herring (Arm)
  2025-04-23 12:18 ` Robin Murphy
  0 siblings, 2 replies; 5+ messages in thread
From: Liya Huang @ 2025-04-17 13:23 UTC (permalink / raw)
  To: Rob Herring, Saravana Kannan; +Cc: devicetree, linux-kernel, Liya Huang

The function pointer fn() in _OF_DECLARE macro might be NULL. For example,
in __reserved_mem_init_node(), only non-NULL cases are handled, and NULL
function pointers are ignored.

This patch introduces a check to handle cases where fn() is NULL. If fn()
is found to be NULL, a warning is issued during compilation to notify
developers about the missing function pointer.

---
The function pointer fn() in _OF_DECLARE macro might be NULL. For example,
in __reserved_mem_init_node(), only non-NULL cases are handled, and NULL
function pointers are ignored.

This patch introduces a check to handle cases where fn() is NULL. If fn()
is found to be NULL, a warning is issued during compilation to notify 
developers about the missing function pointer.

Link: https://lore.kernel.org/all/CAL_JsqK733Q9bbxC0Wz5uxyZ9m7bs+bci5kUJF9GJMv73-dO4w@mail.gmail.com/

Signed-off-by: Liya Huang <1425075683@qq.com>
---
 include/linux/of.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/of.h b/include/linux/of.h
index a62154aeda1b6a600c2b155ac486c0e0b56e0bf2..99d1d553e65b7970a3ecb5158774ca5185f297a0 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -1523,6 +1523,7 @@ static inline int of_get_available_child_count(const struct device_node *np)
 }
 
 #define _OF_DECLARE_STUB(table, name, compat, fn, fn_type)		\
+	static_assert((fn) != NULL);	\
 	static const struct of_device_id __of_table_##name		\
 		__attribute__((unused))					\
 		 = { .compatible = compat,				\
@@ -1530,6 +1531,7 @@ static inline int of_get_available_child_count(const struct device_node *np)
 
 #if defined(CONFIG_OF) && !defined(MODULE)
 #define _OF_DECLARE(table, name, compat, fn, fn_type)			\
+	static_assert((fn) != NULL);	\
 	static const struct of_device_id __of_table_##name		\
 		__used __section("__" #table "_of_table")		\
 		__aligned(__alignof__(struct of_device_id))		\

---
base-commit: 8ffd015db85fea3e15a77027fda6c02ced4d2444
change-id: 20250417-_of_declare-ac80b59d952d

Best regards,
-- 
Liya Huang <1425075683@qq.com>


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

end of thread, other threads:[~2025-04-23 22:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-17 13:23 [PATCH] of: Build warn for missing fn() in _OF_DECLARE Liya Huang
2025-04-22 12:48 ` Rob Herring (Arm)
2025-04-23 12:18 ` Robin Murphy
2025-04-23 14:48   ` 1425075683
2025-04-23 22:10   ` Rob Herring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.