From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752648AbdI3Anw (ORCPT ); Fri, 29 Sep 2017 20:43:52 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:7508 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752571AbdI3Anu (ORCPT ); Fri, 29 Sep 2017 20:43:50 -0400 Subject: Re: [PATCH] net: hns3: fix null pointer dereference before null check To: Colin King , Yisen Zhuang , Salil Mehta , "David S . Miller" , CC: , References: <20170929195123.4189-1-colin.king@canonical.com> From: Yunsheng Lin Message-ID: Date: Sat, 30 Sep 2017 08:43:34 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <20170929195123.4189-1-colin.king@canonical.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.74.191.121] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.59CEE8BB.00AB,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: 6e6ccb55e4b97bff745f62c0933e424f Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Colin On 2017/9/30 3:51, Colin King wrote: > From: Colin Ian King > > pointer ndev is being dereferenced with the call to netif_running > before it is being null checked. Re-order the code to only dereference > ndev after it has been null checked. Thanks for fixing it. > > Detected by CoverityScan, CID#1457206 ("Dereference before null check") > > Fixes: 9df8f79a4d29 ("net: hns3: Add DCB support when interacting with network stack") > Signed-off-by: Colin Ian King > --- > drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c > index 4a0890f98b70..c31506514e5d 100644 > --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c > +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c > @@ -2865,7 +2865,7 @@ static int hns3_client_setup_tc(struct hnae3_handle *handle, u8 tc) > { > struct hnae3_knic_private_info *kinfo = &handle->kinfo; > struct net_device *ndev = kinfo->netdev; > - bool if_running = netif_running(ndev); > + bool if_running; > int ret; > u8 i; > > @@ -2875,6 +2875,8 @@ static int hns3_client_setup_tc(struct hnae3_handle *handle, u8 tc) > if (!ndev) > return -ENODEV; > > + if_running = netif_running(ndev); > + > ret = netdev_set_num_tc(ndev, tc); > if (ret) > return ret; >