[PATCH linux-next] net:stmmac: Fix the unsigned expression compared with zero
Joakim Zhang
qiangqing.zhang at nxp.com
Thu Jul 15 03:12:04 PDT 2021
> -----Original Message-----
> From: menglong8.dong at gmail.com <menglong8.dong at gmail.com>
> Sent: 2021年7月15日 15:46
> To: davem at davemloft.net
> Cc: peppe.cavallaro at st.com; alexandre.torgue at foss.st.com;
> joabreu at synopsys.com; kuba at kernel.org; mcoquelin.stm32 at gmail.com;
> netdev at vger.kernel.org; linux-stm32 at st-md-mailman.stormreply.com;
> linux-arm-kernel at lists.infradead.org; linux-kernel at vger.kernel.org; Zhang
> Yunkai <zhang.yunkai at zte.com.cn>; Zeal Robot <zealci at zte.com.cn>
> Subject: [PATCH linux-next] net:stmmac: Fix the unsigned expression compared
> with zero
>
> From: Zhang Yunkai <zhang.yunkai at zte.com.cn>
>
> WARNING: Unsigned expression "queue" compared with zero.
> Reported-by: Zeal Robot <zealci at zte.com.cn>
> Signed-off-by: Zhang Yunkai <zhang.yunkai at zte.com.cn>
> ---
> drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 8 ++------
> 1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index 7b8404a21544..a4cf2c640531 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -1699,7 +1699,7 @@ static int init_dma_rx_desc_rings(struct net_device
> *dev, gfp_t flags)
> return 0;
>
> err_init_rx_buffers:
> - while (queue >= 0) {
> + do {
> struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue];
>
> if (rx_q->xsk_pool)
> @@ -1710,11 +1710,7 @@ 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--;
> - }
> + } while (queue--);
>
> return ret;
> }
This is a real Coverity issue since queue variable is defined as u32, but there is no breakage from logic, it will break while loop when queue equal 0, and queue[0] actually need be handled.
After your code change, queue[0] will not be handled, right? It will break the logic. If you want to fix the this issue, I think the easiest way is to define queue variable to int.
Best Regards,
Joakim Zhang
> --
> 2.25.1
More information about the linux-arm-kernel
mailing list