linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joakim Zhang <qiangqing.zhang@nxp.com>
To: "menglong8.dong@gmail.com" <menglong8.dong@gmail.com>,
	"davem@davemloft.net" <davem@davemloft.net>
Cc: "peppe.cavallaro@st.com" <peppe.cavallaro@st.com>,
	"alexandre.torgue@foss.st.com" <alexandre.torgue@foss.st.com>,
	"joabreu@synopsys.com" <joabreu@synopsys.com>,
	"kuba@kernel.org" <kuba@kernel.org>,
	"mcoquelin.stm32@gmail.com" <mcoquelin.stm32@gmail.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-stm32@st-md-mailman.stormreply.com" 
	<linux-stm32@st-md-mailman.stormreply.com>,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Zhang Yunkai <zhang.yunkai@zte.com.cn>,
	Zeal Robot <zealci@zte.com.cn>
Subject: RE: [PATCH linux-next] net:stmmac: Fix the unsigned expression compared with zero
Date: Thu, 15 Jul 2021 10:12:04 +0000	[thread overview]
Message-ID: <DB8PR04MB679513459A42E7A7982CE91EE6129@DB8PR04MB6795.eurprd04.prod.outlook.com> (raw)
In-Reply-To: <20210715074539.226600-1-zhang.yunkai@zte.com.cn>


> -----Original Message-----
> From: menglong8.dong@gmail.com <menglong8.dong@gmail.com>
> Sent: 2021年7月15日 15:46
> To: davem@davemloft.net
> Cc: peppe.cavallaro@st.com; alexandre.torgue@foss.st.com;
> joabreu@synopsys.com; kuba@kernel.org; mcoquelin.stm32@gmail.com;
> netdev@vger.kernel.org; linux-stm32@st-md-mailman.stormreply.com;
> linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org; Zhang
> Yunkai <zhang.yunkai@zte.com.cn>; Zeal Robot <zealci@zte.com.cn>
> Subject: [PATCH linux-next] net:stmmac: Fix the unsigned expression compared
> with zero
> 
> From: Zhang Yunkai <zhang.yunkai@zte.com.cn>
> 
> WARNING:  Unsigned expression "queue" compared with zero.
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Zhang Yunkai <zhang.yunkai@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


  reply	other threads:[~2021-07-15 10:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-15  7:45 [PATCH linux-next] net:stmmac: Fix the unsigned expression compared with zero menglong8.dong
2021-07-15 10:12 ` Joakim Zhang [this message]
2021-07-16  0:54   ` Wong Vee Khee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DB8PR04MB679513459A42E7A7982CE91EE6129@DB8PR04MB6795.eurprd04.prod.outlook.com \
    --to=qiangqing.zhang@nxp.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=davem@davemloft.net \
    --cc=joabreu@synopsys.com \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=menglong8.dong@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=peppe.cavallaro@st.com \
    --cc=zealci@zte.com.cn \
    --cc=zhang.yunkai@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).