netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: colin.king@canonical.com
Cc: aviad.krawczyk@huawei.com, netdev@vger.kernel.org,
	kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] net: hinic: fix comparison of a uint16_t type with -1
Date: Thu, 24 Aug 2017 14:32:30 -0700 (PDT)	[thread overview]
Message-ID: <20170824.143230.1441873385968459116.davem@davemloft.net> (raw)
In-Reply-To: <20170823153936.22857-1-colin.king@canonical.com>

From: Colin King <colin.king@canonical.com>
Date: Wed, 23 Aug 2017 16:39:36 +0100

> From: Colin Ian King <colin.king@canonical.com>
> 
> The comparison of hw_ioctxt.rx_buf_sz_idx == -1 is always false because
> rx_buf_sz_idx is a uint16_t. Fix this by explicitly casting -1 to uint16_t.
> 
> Detected by CoverityScan, CID#1454559 ("Operands don't affect result")
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/net/ethernet/huawei/hinic/hinic_hw_dev.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/huawei/hinic/hinic_hw_dev.c b/drivers/net/ethernet/huawei/hinic/hinic_hw_dev.c
> index 09dec6de8dd5..71e26070fb7f 100644
> --- a/drivers/net/ethernet/huawei/hinic/hinic_hw_dev.c
> +++ b/drivers/net/ethernet/huawei/hinic/hinic_hw_dev.c
> @@ -352,7 +352,7 @@ static int set_hw_ioctxt(struct hinic_hwdev *hwdev, unsigned int rq_depth,
>  		}
>  	}
>  
> -	if (hw_ioctxt.rx_buf_sz_idx == -1)
> +	if (hw_ioctxt.rx_buf_sz_idx == (uint16_t)-1)
>  		return -EINVAL;
>  
>  	hw_ioctxt.sq_depth  = ilog2(sq_depth);

This is really silly.

The code in question is trying to convert a size (HINIC_RX_BUF_SZ)
into a table index, using a loop.

It should just compute this at compile time and do away with this
overly confusing code.

Even a switch statement would be much better and the compiler
would optimize the whole away into a single assignment in
the generated code.

      parent reply	other threads:[~2017-08-24 21:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-23 15:39 [PATCH][next] net: hinic: fix comparison of a uint16_t type with -1 Colin King
2017-08-24  8:48 ` Aviad Krawczyk
2017-08-24  8:54   ` Colin Ian King
2017-08-24  9:29     ` Dan Carpenter
2017-08-24  9:38       ` Aviad Krawczyk
2017-08-24 21:32 ` David Miller [this message]

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=20170824.143230.1441873385968459116.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=aviad.krawczyk@huawei.com \
    --cc=colin.king@canonical.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /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).