* [PATCH net-next] net: stmmac: clean up impossible condition
@ 2022-03-16 8:37 Dan Carpenter
2022-03-17 13:00 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2022-03-16 8:37 UTC (permalink / raw)
To: Giuseppe Cavallaro, Ong Boon Leong
Cc: Alexandre Torgue, Jose Abreu, David S. Miller, Jakub Kicinski,
Maxime Coquelin, netdev, linux-stm32, kernel-janitors
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>
---
This code is old so the patch could apply to net, but it's a cleanup and
not a bugfix.
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index cf4e077d21ff..932f444d0d68 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -1668,7 +1668,7 @@ static int init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags)
{
struct stmmac_priv *priv = netdev_priv(dev);
u32 rx_count = priv->plat->rx_queues_to_use;
- u32 queue;
+ int queue;
int ret;
/* RX INITIALIZATION */
@@ -1695,9 +1695,6 @@ static int init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags)
rx_q->buf_alloc_num = 0;
rx_q->xsk_pool = NULL;
- if (queue == 0)
- break;
-
queue--;
}
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next] net: stmmac: clean up impossible condition
2022-03-16 8:37 [PATCH net-next] net: stmmac: clean up impossible condition Dan Carpenter
@ 2022-03-17 13:00 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-03-17 13:00 UTC (permalink / raw)
To: Dan Carpenter
Cc: peppe.cavallaro, boon.leong.ong, alexandre.torgue, joabreu, davem,
kuba, mcoquelin.stm32, netdev, linux-stm32, kernel-janitors
Hello:
This patch was applied to netdev/net-next.git (master)
by Paolo Abeni <pabeni@redhat.com>:
On Wed, 16 Mar 2022 11:37:44 +0300 you wrote:
> 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).
>
> [...]
Here is the summary with links:
- [net-next] net: stmmac: clean up impossible condition
https://git.kernel.org/netdev/net-next/c/58e06d05d43a
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-03-17 13:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-16 8:37 [PATCH net-next] net: stmmac: clean up impossible condition Dan Carpenter
2022-03-17 13:00 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).