[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250618111212.GI1699@horms.kernel.org>
Date: Wed, 18 Jun 2025 12:12:12 +0100
From: Simon Horman <horms@...nel.org>
To: Jijie Shao <shaojijie@...wei.com>
Cc: davem@...emloft.net, edumazet@...gle.com, kuba@...nel.org,
pabeni@...hat.com, andrew+netdev@...n.ch, shenjian15@...wei.com,
wangpeiyang1@...wei.com, liuyonglong@...wei.com,
chenhao418@...wei.com, jonathan.cameron@...wei.com,
shameerali.kolothum.thodi@...wei.com, salil.mehta@...wei.com,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
michal.swiatkowski@...ux.intel.com
Subject: Re: [PATCH V2 net-next 5/8] net: hns3: set the freed pointers to
NULL when lifetime is not end
On Tue, Jun 17, 2025 at 09:02:52AM +0800, Jijie Shao wrote:
> From: Jian Shen <shenjian15@...wei.com>
>
> There are several pointers are freed but not set to NULL,
> and their lifetime is not end immediately. To avoid misusing
> there wild pointers, set them to NULL.
>
> Signed-off-by: Jian Shen <shenjian15@...wei.com>
> Signed-off-by: Jijie Shao <shaojijie@...wei.com>
> ---
> drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 1 +
> drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 4 ++++
> drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 4 ++++
> 3 files changed, 9 insertions(+)
>
> diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
> index 6a244ba5e051..0d6db46db5ed 100644
> --- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
> @@ -276,6 +276,7 @@ static int hns3_lp_run_test(struct net_device *ndev, enum hnae3_loop mode)
> good_cnt++;
> } else {
> kfree_skb(skb);
> + skb = NULL;
I am sceptical about the merit of setting local variables to NULL like this.
In general defensive coding is not the preferred approach in the Kernel.
And in this case, won't this result in a NULL dereference when
skb_get(skb) is called if the loop this code resides in iterates again?
> netdev_err(ndev, "hns3_lb_run_test xmit failed: %d\n",
> tx_ret);
> }
...
Powered by blists - more mailing lists