From ab9b85b199534f4610e582bc861358ae8d4c64f0 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Tue, 21 Jan 2025 10:55:46 +0200 Subject: [PATCH] net: Build assert issue with llvm Remove the build assert from NET_L3_REGISTER() macro as that is causing an issue with llvm. Add runtime check of the handler pointer value. subsys/net/l2/ethernet/arp.c:1044:1: error: static_assert expression is not an integral constant expression ETH_NET_L3_REGISTER(ARP, NET_ETH_PTYPE_ARP, arp_recv); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/zephyr/net/ethernet.h:1272:2: note: expanded from macro 'ETH_NET_L3_REGISTER' NET_L3_REGISTER(&NET_L2_GET_NAME(ETHERNET), name, ptype, handler) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/zephyr/net/net_core.h:190:2: note: expanded from macro 'NET_L3_REGISTER' BUILD_ASSERT((_handler) != NULL, "Handler is not defined") ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/zephyr/toolchain/gcc.h:87:51: note: expanded from macro 'BUILD_ASSERT' define BUILD_ASSERT(EXPR, MSG...) _Static_assert((EXPR), "" MSG) ^~~~~~ subsys/net/l2/ethernet/arp.c:1044:1: note: cast from 'void *' is not allowed in a constant expression include/zephyr/net/ethernet.h:1272:2: note: expanded from macro 'ETH_NET_L3_REGISTER' NET_L3_REGISTER(&NET_L2_GET_NAME(ETHERNET), name, ptype, handler) ^ include/zephyr/net/net_core.h:190:29: note: expanded from macro 'NET_L3_REGISTER' BUILD_ASSERT((_handler) != NULL, "Handler is not defined") ^ /usr/lib/llvm-14/lib/clang/14.0.0/include/stddef.h:89:16: note: expanded from macro 'NULL' define NULL ((void*)0) Signed-off-by: Jukka Rissanen --- include/zephyr/net/net_core.h | 3 +-- subsys/net/l2/ethernet/ethernet.c | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/zephyr/net/net_core.h b/include/zephyr/net/net_core.h index 1b4bf0479bd..5c017a9780e 100644 --- a/include/zephyr/net/net_core.h +++ b/include/zephyr/net/net_core.h @@ -186,8 +186,7 @@ struct net_l3_register { .handler = _handler, \ .name = STRINGIFY(_name), \ .l2 = _l2_type, \ - }; \ - BUILD_ASSERT((_handler) != NULL, "Handler is not defined") + }; /* @endcond */ diff --git a/subsys/net/l2/ethernet/ethernet.c b/subsys/net/l2/ethernet/ethernet.c index ab7add695b1..c93705bc11a 100644 --- a/subsys/net/l2/ethernet/ethernet.c +++ b/subsys/net/l2/ethernet/ethernet.c @@ -353,7 +353,8 @@ static enum net_verdict ethernet_recv(struct net_if *iface, net_buf_pull(pkt->frags, hdr_len); STRUCT_SECTION_FOREACH(net_l3_register, l3) { - if (l3->ptype != type || l3->l2 != &NET_L2_GET_NAME(ETHERNET)) { + if (l3->ptype != type || l3->l2 != &NET_L2_GET_NAME(ETHERNET) || + l3->handler == NULL) { continue; }