Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: stmmac: clean up impossible condition

This code works but it has a static checker warning:

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:1687 init_dma_rx_desc_rings()
warn: always true condition '(queue >= 0) => (0-u32max >= 0)'

Obviously, it makes no sense to check if an unsigned int is >= 0. What
prevents this code from being a forever loop is that later there is a
separate check for if (queue == 0).

The "queue" variable is less than MTL_MAX_RX_QUEUES (8) so it can easily
fit in an int type. Any larger value for "queue" would lead to an array
overflow when we assign "rx_q = &priv->rx_queue[queue]".

Fixes: de0b90e52a11 ("net: stmmac: rearrange RX and TX desc init into per-queue basis")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/20220316083744.GB30941@kili
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Dan Carpenter and committed by
Paolo Abeni
58e06d05 435fe1c0

+1 -4
+1 -4
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
··· 1668 1668 { 1669 1669 struct stmmac_priv *priv = netdev_priv(dev); 1670 1670 u32 rx_count = priv->plat->rx_queues_to_use; 1671 - u32 queue; 1671 + int queue; 1672 1672 int ret; 1673 1673 1674 1674 /* RX INITIALIZATION */ ··· 1694 1694 1695 1695 rx_q->buf_alloc_num = 0; 1696 1696 rx_q->xsk_pool = NULL; 1697 - 1698 - if (queue == 0) 1699 - break; 1700 1697 1701 1698 queue--; 1702 1699 }