of: Build warn for missing fn() in _OF_DECLARE
PATCH 1/1 of: Build warn for missing fn() in _OF_DECLARE
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.
--- include/linux/of.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/of.h +2 -0
@@ -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,
Signature · 1 line
Liya Huang <[email protected]>
Quoted 17 lines · Liya Huang
The function pointer
fn()in_OF_DECLAREmacro 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. Iffn()is found to be NULL, a warning is issued during compilation to notify developers about the missing function pointer.---
The function pointerfn()in_OF_DECLAREmacro 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. Iffn()is found to be NULL, a warning is issued during compilation to notify developers about the missing function pointer.
Quoted 7 lines
Signed-off-by Liya Huang <[email protected]>--- include/linux/of.h | 2 ++ 1 file changed, 2 insertions(+)
Applied, thanks!
Quoted 8 lines · Liya Huang
The function pointer
fn()in_OF_DECLAREmacro 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. Iffn()is found to be NULL, a warning is issued during compilation to notify developers about the missing function pointer.
Quoted 8 lines
---
The function pointerfn()in_OF_DECLAREmacro 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. Iffn()is found to be NULL, a warning is issued during compilation to notify developers about the missing function pointer.
This patch in -next appears to be responsible for syzbot complaining about build errors for some configs:
"kernel/dma/coherent.c:410:1: error: static assertion expression is not an integral constant expression kernel/dma/contiguous.c:497:1: error: static assertion expression is not an integral constant expression "
https://lore.kernel.org/linux-iommu/[email protected]/
Also on closer inspection, just outside the diff context we still seem to be explicitly anticipating fn being NULL with:
.data = (fn == (fn_type)NULL) ? fn : fn
so something doesn't seem quite right...
Thanks,
Robin.
Quoted 33 lines
Signed-off-by Liya Huang <[email protected]>--- include/linux/of.h | 2 ++ 1 file changed, 2 insertions(+)include/linux/of.h +2
-1@@ -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-ac80b59d952dBest regards,
Quoted 33 lines · Liya Huang
Quoted 8 lines
The function pointer
fn()in_OF_DECLAREmacro 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. Iffn()is found to be NULL, a warning is issued during compilation to notify developers about the missing function pointer.Quoted 8 lines
---
The function pointerfn()in_OF_DECLAREmacro 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. Iffn()is found to be NULL, a warning is issued during compilation to notify developers about the missing function pointer.This patch in -next appears to be responsible for syzbot complaining about build errors for some configs:
"
kernel/dma/coherent.c:410:1: error: static assertion expression is not an integral constant expressionkernel/dma/contiguous.c:497:1: error: static assertion expression is not an integral constant expression
"https://lore.kernel.org/linux-iommu/[email protected]/
Also on closer inspection, just outside the diff context we still seem to be explicitly anticipating fn being NULL with:
Quoted 6 lines
.data = (fn == (fn_type)NULL) ? fn : fnso something doesn't seem quite right...
Thanks,
Robin.
I tested this patch, and it compiled successfully with GCC but failed with Clang.I couldn't find a better way to consistently check for null function pointers during compilation across these two compilers.
I even tried using the method of preventing negative array indexing, but it failed to compile with GCC instead.
Perhaps it would be better to abandon this patch. :(
--
Thanks,
Liya Huang <[email protected]>
Rob Herring
maintainerQuoted 22 lines · Robin Murphy
Quoted 8 lines · Liya Huang
The function pointer
fn()in_OF_DECLAREmacro 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. Iffn()is found to be NULL, a warning is issued during compilation to notify developers about the missing function pointer.Quoted 8 lines
---
The function pointerfn()in_OF_DECLAREmacro 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. Iffn()is found to be NULL, a warning is issued during compilation to notify developers about the missing function pointer.This patch in -next appears to be responsible for syzbot complaining about build errors for some configs:
Quoted 8 lines
"
kernel/dma/coherent.c:410:1: error: static assertion expression is not an integral constant expressionkernel/dma/contiguous.c:497:1: error: static assertion expression is not an integral constant expression
"
Humm, doesn't seem to repro for me with clang-19.
Quoted 5 lines
Also on closer inspection, just outside the diff context we still seem to be explicitly anticipating fn being NULL with:
.data = (fn == (fn_type)NULL) ? fn : fn
No, that is checking that the function parameters match the defined type. If fn's type doesn't match fn_type, then you get a compiler error.
Anyway, dropping it for now.
Rob