From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752111AbdHXItW (ORCPT ); Thu, 24 Aug 2017 04:49:22 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:5014 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751790AbdHXItR (ORCPT ); Thu, 24 Aug 2017 04:49:17 -0400 Subject: Re: [PATCH][next] net: hinic: fix comparison of a uint16_t type with -1 To: Colin King , CC: , References: <20170823153936.22857-1-colin.king@canonical.com> From: Aviad Krawczyk Message-ID: <58f312cc-5f24-83b6-d12d-c66e4fd4dad2@huawei.com> Date: Thu, 24 Aug 2017 11:48:32 +0300 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170823153936.22857-1-colin.king@canonical.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.206.50.78] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090204.599E9305.0079,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: a019b974cbe7823f39cac7cbf3a23ef1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/23/2017 6:39 PM, Colin King wrote: > From: Colin Ian King > > 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 > --- > 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); > Many thanks, Colin. I prefer to avoid casting when possible, what do you think about replacing the condition by: if (rx_buf_sz_table[i].sz != HINIC_RX_BUF_SZ) return -EINVAL;