Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1719602

Re: [PATCH][next] net: hinic: fix comparison of a uint16_t type with -1

From David Miller <davem@davemloft.net>
Newsgroups linux.kernel
Subject Re: [PATCH][next] net: hinic: fix comparison of a uint16_t type with -1
Date 2017-08-24 23:40 +0200
Message-ID <ui813-3xK-9@gated-at.bofh.it> (permalink)
References <uhFV7-2iZ-17@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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.

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH][next] net: hinic: fix comparison of a uint16_t type with -1 Colin King <colin.king@canonical.com> - 2017-08-23 17:40 +0200
  Re: [PATCH][next] net: hinic: fix comparison of a uint16_t type with  -1 Aviad Krawczyk <aviad.krawczyk@huawei.com> - 2017-08-24 10:50 +0200
    Re: [PATCH][next] net: hinic: fix comparison of a uint16_t type with  -1 Colin Ian King <colin.king@canonical.com> - 2017-08-24 11:00 +0200
      Re: [PATCH][next] net: hinic: fix comparison of a uint16_t type with  -1 Dan Carpenter <dan.carpenter@oracle.com> - 2017-08-24 11:40 +0200
        Re: [PATCH][next] net: hinic: fix comparison of a uint16_t type with  -1 Aviad Krawczyk <aviad.krawczyk@huawei.com> - 2017-08-24 11:40 +0200
  Re: [PATCH][next] net: hinic: fix comparison of a uint16_t type  with -1 David Miller <davem@davemloft.net> - 2017-08-24 23:40 +0200

csiph-web