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


Groups > linux.kernel > #1742418

Re: [PATCH] net: hns3: fix null pointer dereference before null check

From Yunsheng Lin <linyunsheng@huawei.com>
Newsgroups linux.kernel
Subject Re: [PATCH] net: hns3: fix null pointer dereference before null check
Date 2017-09-30 02:50 +0200
Message-ID <uve8G-581-13@gated-at.bofh.it> (permalink)
References <uv9C1-28R-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Hi, Colin

On 2017/9/30 3:51, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> 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 <colin.king@canonical.com>
> ---
>  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;
> 

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


Thread

[PATCH] net: hns3: fix null pointer dereference before null check Colin King <colin.king@canonical.com> - 2017-09-29 22:00 +0200
  Re: [PATCH] net: hns3: fix null pointer dereference before null check Yunsheng Lin <linyunsheng@huawei.com> - 2017-09-30 02:50 +0200
  Re: [PATCH] net: hns3: fix null pointer dereference before null  check David Miller <davem@davemloft.net> - 2017-10-01 05:20 +0200

csiph-web