Skip to contentSkip to conversation

PCI: hv: Use kfree(hbus) in hv_pci_probe()'s error handling path

PATCH In review Dexuan Cui 3 participants 4 messages Jan 6, 2020 – Feb 21, 2020

Subsystems (4)
lore
Share & tools
lore

Dexuan Cui

author maintainer
#0 lore raw

PATCH 1/1 PCI: hv: Use kfree(hbus) in hv_pci_probe()'s error handling path

Now that we use kzalloc() to allocate the hbus buffer, we should use kfree() in the error path as well.

Also remove the type casting, since it's unnecessary in C.

Fixes 877b911a5ba0 ("PCI: hv: Avoid a kmemleak false positive caused by the hbus buffer")

---

Sorry for missing the error handling path.

 drivers/pci/controller/pci-hyperv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/controller/pci-hyperv.c +2 -2
index 9977abff92fc..15011a349520 100644
@@ -2922,7 +2922,7 @@ static int hv_pci_probe(struct hv_device *hdev,
 	 * positive by using kmemleak_alloc() and kmemleak_free() to ask
 	 * kmemleak to track and scan the hbus buffer.
 	 */
-	hbus = (struct hv_pcibus_device *)kzalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL);
+	hbus = kzalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL);
 	if (!hbus)
 		return -ENOMEM;
 	hbus->state = hv_pcibus_init;
@@ -3058,7 +3058,7 @@ static int hv_pci_probe(struct hv_device *hdev,
 free_dom:
 	hv_put_dom_num(hbus->sysdata.domain);
 free_bus:
-	free_page((unsigned long)hbus);
+	kfree(hbus);
 	return ret;
 }
 
Signature · 1 line
2.19.1
Reviewed-by on v1 1/1
#1 lore raw

From: Dexuan Cui <[email protected]> Sent: Monday, January 6, 2020 2:39 PM

Quoted 38 lines

Now that we use kzalloc() to allocate the hbus buffer, we should use kfree() in the error path as well.

Also remove the type casting, since it's unnecessary in C.

Fixes 877b911a5ba0 ("PCI: hv: Avoid a kmemleak false positive caused by the hbus buffer")

---

Sorry for missing the error handling path.

 drivers/pci/controller/pci-hyperv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/controller/pci-hyperv.c +2 -3
index 9977abff92fc..15011a349520 100644
@@ -2922,7 +2922,7 @@ static int hv_pci_probe(struct hv_device *hdev,
 	 * positive by using kmemleak_alloc() and kmemleak_free() to ask
 	 * kmemleak to track and scan the hbus buffer.
 	 */
-	hbus = (struct hv_pcibus_device *)kzalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL);
+	hbus = kzalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL);
 	if (!hbus)
 		return -ENOMEM;
 	hbus->state = hv_pcibus_init;
@@ -3058,7 +3058,7 @@ static int hv_pci_probe(struct hv_device *hdev,
 free_dom:
 	hv_put_dom_num(hbus->sysdata.domain);
 free_bus:
-	free_page((unsigned long)hbus);
+	kfree(hbus);
 	return ret;
 }
 
--
Quoted 1 line

2.19.1

#2 lore raw
In reply to Dexuan Cui
Quoted 4 lines · Dexuan Cui

Now that we use kzalloc() to allocate the hbus buffer, we should use kfree() in the error path as well.

Also remove the type casting, since it's unnecessary in C.

Two unrelated logical changes -> two patches please, I know it is tempting but it is important to split logical changes into separate patches.

Thanks,
Lorenzo

Quoted 34 lines
Fixes 877b911a5ba0 ("PCI: hv: Avoid a kmemleak false positive caused by the hbus buffer")

---

Sorry for missing the error handling path.

 drivers/pci/controller/pci-hyperv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/controller/pci-hyperv.c +2 -2
index 9977abff92fc..15011a349520 100644
@@ -2922,7 +2922,7 @@ static int hv_pci_probe(struct hv_device *hdev,
 	 * positive by using kmemleak_alloc() and kmemleak_free() to ask
 	 * kmemleak to track and scan the hbus buffer.
 	 */
-	hbus = (struct hv_pcibus_device *)kzalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL);
+	hbus = kzalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL);
 	if (!hbus)
 		return -ENOMEM;
 	hbus->state = hv_pcibus_init;
@@ -3058,7 +3058,7 @@ static int hv_pci_probe(struct hv_device *hdev,
 free_dom:
 	hv_put_dom_num(hbus->sysdata.domain);
 free_bus:
-	free_page((unsigned long)hbus);
+	kfree(hbus);
 	return ret;
 }
 
Signature · 1 line
2.19.1
author maintainer
#3 lore raw
Quoted 8 lines

From: [email protected] <[email protected]> On Behalf Of Lorenzo Pieralisi
Sent: Friday, February 21, 2020 6:40 AM

Quoted 3 lines · Dexuan Cui

Now that we use kzalloc() to allocate the hbus buffer, we should use kfree() in the error path as well.

Quoted 8 lines
Quoted 1 line

Also remove the type casting, since it's unnecessary in C.

Two unrelated logical changes -> two patches please, I know it is tempting but it is important to split logical changes into separate patches.

Thanks,
Lorenzo

Ok, will post 2 separate patches shortly.

Thanks,
-- Dexuan