net: airoha: fix ARRAY_SIZE() division by zero on UP builds
Subsystems (4)
Lorenzo Bianconi
maintainerPATCH 1/1 net: airoha: fix ARRAY_SIZE() division by zero on UP builds
airoha_alloc_gdm_device() initializes the txq_lock[] array iterating over ARRAY_SIZE(dev->txq_lock). ARRAY_SIZE() expands to sizeof(dev->txq_lock) / sizeof((dev->txq_lock)[0]), but on UP builds (CONFIG_SMP unset, CONFIG_DEBUG_SPINLOCK unset) arch_spinlock_t is an empty struct, so sizeof(spinlock_t) is zero and the expression is a compile-time division by zero (undefined behavior), reported by clang as "division by zero is undefined [-Wdivision-by-zero]".
Since the array is statically sized with AIROHA_NUM_NETDEV_TX_RINGS, use the named constant as loop bound instead of ARRAY_SIZE().
--- drivers/net/ethernet/airoha/airoha_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/airoha/airoha_eth.c +1 -1
@@ -3467,7 +3467,7 @@ static int airoha_alloc_gdm_device(struct airoha_eth *eth, netdev->dev.of_node =of_node_get (np); dev =netdev_priv (netdev);u64_stats_init (&dev->stats.syncp); -for (i =0 ; i <ARRAY_SIZE (dev->txq_lock); i++) +for (i =0 ; i <AIROHA_NUM_NETDEV_TX_RINGS ; i++)spin_lock_init (&dev->txq_lock[i]); dev->port = port; dev->eth = eth;
---
base-commit: 2fbade66245059c78daeaccfce13ecf499fffb51
change-id: 20260731-airoha-spinlock-array-fix-d239f7841cb8
Best regards,
Signature · 1 line
Lorenzo Bianconi <[email protected]>
Quoted 9 lines · Lorenzo Bianconi
airoha_alloc_gdm_device()initializes the txq_lock[] array iterating overARRAY_SIZE(dev->txq_lock).ARRAY_SIZE()expands tosizeof(dev->txq_lock)/ sizeof((dev->txq_lock)[0]), but on UP builds (CONFIG_SMPunset,CONFIG_DEBUG_SPINLOCKunset)arch_spinlock_tis an empty struct, sosizeof(spinlock_t)is zero and the expression is a compile-time division by zero (undefined behavior), reported by clang as "division by zero is undefined [-Wdivision-by-zero]".
Quoted 7 lines
Since the array is statically sized with
AIROHA_NUM_NETDEV_TX_RINGS, use the named constant as loop bound instead ofARRAY_SIZE().Fixes 78a35725e533 ("net: airoha: defer GDM3/GDM4 WAN mode and GDM2 loopback to QoS offload")Reported-by kernel test robot <[email protected]>Signed-off-by Lorenzo Bianconi <[email protected]>
Quoted 26 lines
--- drivers/net/ethernet/airoha/airoha_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ethernet/airoha/airoha_eth.c +1
-2@@ -3467,7 +3467,7 @@ static int airoha_alloc_gdm_device(struct airoha_eth *eth, netdev->dev.of_node =of_node_get (np); dev =netdev_priv (netdev);u64_stats_init (&dev->stats.syncp); -for (i =0 ; i <ARRAY_SIZE (dev->txq_lock); i++) +for (i =0 ; i <AIROHA_NUM_NETDEV_TX_RINGS ; i++)spin_lock_init (&dev->txq_lock[i]); dev->port = port; dev->eth = eth; ---base-commit:
2fbade66245059c78daeaccfce13ecf499fffb51
change-id: 20260731-airoha-spinlock-array-fix-d239f7841cb8Best regards,
--
Lorenzo Bianconi <[email protected]>
Signature · 2 lines
Thanks, ~Nick Desaulniers
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Fri, 31 Jul 2026 17:47:38 +0200 you wrote:
airoha_alloc_gdm_device()initializes the txq_lock[] array iterating overARRAY_SIZE(dev->txq_lock).ARRAY_SIZE()expands tosizeof(dev->txq_lock)/ sizeof((dev->txq_lock)[0]), but on UP builds (CONFIG_SMPunset,CONFIG_DEBUG_SPINLOCKunset)arch_spinlock_tis an empty struct, sosizeof(spinlock_t)is zero and the expression is a compile-time division by zero (undefined behavior), reported by clang as "division by zero is undefined [-Wdivision-by-zero]".[...]
Here is the summary with links:
- [net-next] net: airoha: fix ARRAY_SIZE() division by zero on UP builds
https://git.kernel.org/netdev/net-next/c/c509971352a6
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html