[PATCH V3 net-next 5/8] net: hns3: set the freed pointers to NULL when lifetime is not end

Jijie Shao posted 8 patches 3 months, 3 weeks ago
There is a newer version of this series
[PATCH V3 net-next 5/8] net: hns3: set the freed pointers to NULL when lifetime is not end
Posted by Jijie Shao 3 months, 3 weeks ago
From: Jian Shen <shenjian15@huawei.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@huawei.com>
Signed-off-by: Jijie Shao <shaojijie@huawei.com>
---
ChangeLog:
v2 -> v3:
  - Remove unnecessary pointer set to NULL operation, suggested by Simon Horman.
  v2: https://lore.kernel.org/all/20250617010255.1183069-1-shaojijie@huawei.com/
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c   | 4 ++++
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index e0a2ca21ee46..9d7c9523c9e1 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -5208,6 +5208,7 @@ static void hclge_fd_free_node(struct hclge_dev *hdev,
 {
 	hlist_del(&rule->rule_node);
 	kfree(rule);
+	rule = NULL;
 	hclge_sync_fd_state(hdev);
 }
 
@@ -5232,6 +5233,7 @@ static void hclge_update_fd_rule_node(struct hclge_dev *hdev,
 		new_rule->rule_node.pprev = old_rule->rule_node.pprev;
 		memcpy(old_rule, new_rule, sizeof(*old_rule));
 		kfree(new_rule);
+		new_rule = NULL;
 		break;
 	case HCLGE_FD_DELETED:
 		hclge_fd_dec_rule_cnt(hdev, old_rule->location);
@@ -8521,6 +8523,7 @@ static void hclge_update_mac_node(struct hclge_mac_node *mac_node,
 		if (mac_node->state == HCLGE_MAC_TO_ADD) {
 			list_del(&mac_node->node);
 			kfree(mac_node);
+			mac_node = NULL;
 		} else {
 			mac_node->state = HCLGE_MAC_TO_DEL;
 		}
@@ -9151,6 +9154,7 @@ static void hclge_uninit_vport_mac_list(struct hclge_vport *vport,
 		case HCLGE_MAC_TO_ADD:
 			list_del(&mac_node->node);
 			kfree(mac_node);
+			mac_node = NULL;
 			break;
 		}
 	}
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index e3f86638540b..3ffd47b30ad3 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -933,6 +933,7 @@ static void hclgevf_update_mac_node(struct hclgevf_mac_addr_node *mac_node,
 		if (mac_node->state == HCLGEVF_MAC_TO_ADD) {
 			list_del(&mac_node->node);
 			kfree(mac_node);
+			mac_node = NULL;
 		} else {
 			mac_node->state = HCLGEVF_MAC_TO_DEL;
 		}
@@ -2395,6 +2396,7 @@ static int hclgevf_init_msi(struct hclgevf_dev *hdev)
 					sizeof(int), GFP_KERNEL);
 	if (!hdev->vector_irq) {
 		devm_kfree(&pdev->dev, hdev->vector_status);
+		hdev->vector_status = NULL;
 		pci_free_irq_vectors(pdev);
 		return -ENOMEM;
 	}
@@ -2408,6 +2410,8 @@ static void hclgevf_uninit_msi(struct hclgevf_dev *hdev)
 
 	devm_kfree(&pdev->dev, hdev->vector_status);
 	devm_kfree(&pdev->dev, hdev->vector_irq);
+	hdev->vector_status = NULL;
+	hdev->vector_irq = NULL;
 	pci_free_irq_vectors(pdev);
 }
 
-- 
2.33.0
Re: [PATCH V3 net-next 5/8] net: hns3: set the freed pointers to NULL when lifetime is not end
Posted by Jakub Kicinski 3 months, 2 weeks ago
On Thu, 19 Jun 2025 22:40:54 +0800 Jijie Shao wrote:
> ChangeLog:
> v2 -> v3:
>   - Remove unnecessary pointer set to NULL operation, suggested by Simon Horman.
>   v2: https://lore.kernel.org/all/20250617010255.1183069-1-shaojijie@huawei.com/

You removed a single case, but I'm pretty sure Simon meant _all_
cases setting local variables to NULL in this patch are pointless.
-- 
pw-bot: cr
Re: [PATCH V3 net-next 5/8] net: hns3: set the freed pointers to NULL when lifetime is not end
Posted by Jijie Shao 3 months, 2 weeks ago
on 2025/6/21 23:33, Jakub Kicinski wrote:
> On Thu, 19 Jun 2025 22:40:54 +0800 Jijie Shao wrote:
>> ChangeLog:
>> v2 -> v3:
>>    - Remove unnecessary pointer set to NULL operation, suggested by Simon Horman.
>>    v2: https://lore.kernel.org/all/20250617010255.1183069-1-shaojijie@huawei.com/
> You removed a single case, but I'm pretty sure Simon meant _all_
> cases setting local variables to NULL in this patch are pointless.

Ok, I will drop this patch in V4

Thanks,
Jijie Shao
Re: [PATCH V3 net-next 5/8] net: hns3: set the freed pointers to NULL when lifetime is not end
Posted by Simon Horman 3 months, 2 weeks ago
On Mon, Jun 23, 2025 at 09:44:45AM +0800, Jijie Shao wrote:
> 
> on 2025/6/21 23:33, Jakub Kicinski wrote:
> > On Thu, 19 Jun 2025 22:40:54 +0800 Jijie Shao wrote:
> > > ChangeLog:
> > > v2 -> v3:
> > >    - Remove unnecessary pointer set to NULL operation, suggested by Simon Horman.
> > >    v2: https://lore.kernel.org/all/20250617010255.1183069-1-shaojijie@huawei.com/
> > You removed a single case, but I'm pretty sure Simon meant _all_
> > cases setting local variables to NULL in this patch are pointless.
> 
> Ok, I will drop this patch in V4

Thanks, much appreciated.