Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
* [PATCH net-next] net: airoha: fix ARRAY_SIZE() division by zero on UP builds
@ 2026-07-31 15:47 Lorenzo Bianconi
  2026-07-31 21:42 ` Nick Desaulniers
  0 siblings, 1 reply; 2+ messages in thread
From: Lorenzo Bianconi @ 2026-07-31 15:47 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Nathan Chancellor, Nick Desaulniers, Bill Wendling,
	Justin Stitt, Simon Horman, Alexander Lobakin
  Cc: linux-arm-kernel, linux-mediatek, netdev, llvm, Miguel Ojeda,
	kernel test robot, Lorenzo Bianconi

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().

Fixes: 78a35725e533 ("net: airoha: defer GDM3/GDM4 WAN mode and GDM2 loopback to QoS offload")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202607311850.6p0ZUVq4-lkp@intel.com/
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/net/ethernet/airoha/airoha_eth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
index dba7c52c0896..64619e9a704d 100644
--- a/drivers/net/ethernet/airoha/airoha_eth.c
+++ b/drivers/net/ethernet/airoha/airoha_eth.c
@@ -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,
-- 
Lorenzo Bianconi <lorenzo@kernel.org>


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

* Re: [PATCH net-next] net: airoha: fix ARRAY_SIZE() division by zero on UP builds
  2026-07-31 15:47 [PATCH net-next] net: airoha: fix ARRAY_SIZE() division by zero on UP builds Lorenzo Bianconi
@ 2026-07-31 21:42 ` Nick Desaulniers
  0 siblings, 0 replies; 2+ messages in thread
From: Nick Desaulniers @ 2026-07-31 21:42 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Nathan Chancellor, Bill Wendling, Justin Stitt,
	Simon Horman, Alexander Lobakin, linux-arm-kernel, linux-mediatek,
	netdev, llvm, Miguel Ojeda, kernel test robot

On Fri, Jul 31, 2026 at 8:48 AM Lorenzo Bianconi <lorenzo@kernel.org> wrote:
>
> 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().
>
> Fixes: 78a35725e533 ("net: airoha: defer GDM3/GDM4 WAN mode and GDM2 loopback to QoS offload")
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202607311850.6p0ZUVq4-lkp@intel.com/
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>

Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
>  drivers/net/ethernet/airoha/airoha_eth.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
> index dba7c52c0896..64619e9a704d 100644
> --- a/drivers/net/ethernet/airoha/airoha_eth.c
> +++ b/drivers/net/ethernet/airoha/airoha_eth.c
> @@ -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,
> --
> Lorenzo Bianconi <lorenzo@kernel.org>
>


-- 
Thanks,
~Nick Desaulniers

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

end of thread, other threads:[~2026-07-31 21:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-31 15:47 [PATCH net-next] net: airoha: fix ARRAY_SIZE() division by zero on UP builds Lorenzo Bianconi
2026-07-31 21:42 ` Nick Desaulniers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox