Skip to contentSkip to conversation

PCI: hv: Remove unnecessary type casting from kzalloc

PATCH Applied Dexuan Cui 2 participants 3 messages Feb 22, 2020 – Feb 24, 2020

Subsystems (4)
lore
Share & tools
lore

Dexuan Cui

author maintainer
#0 lore raw

PATCH v2 1/2 PCI: hv: Remove unnecessary type casting from kzalloc

In C, there is no need to cast a void * to any other pointer type.

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

---

Change in v2: this was part of v1.

 drivers/pci/controller/pci-hyperv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/pci-hyperv.c +1 -1
index 9977abff92fc..0fe0283368d2 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;
Signature · 1 line
2.19.1
author maintainer
#1 lore raw

PATCH v2 2/2 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.

Fixes 877b911a5ba0 ("PCI: hv: Avoid a kmemleak false positive caused by the hbus buffer")
---
 drivers/pci/controller/pci-hyperv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Change in v2: this was part of v1.

drivers/pci/controller/pci-hyperv.c +1 -1
index 0fe0283368d2..15011a349520 100644
@@ -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
#2 lore raw
In reply to Dexuan Cui
Quoted 3 lines · Dexuan Cui

In C, there is no need to cast a void * to any other pointer type.

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

This patch fixes nothing, anyway, that's a leftover that I removed.

Applied the series to pci/hv for v5.7.

Thanks,
Lorenzo

Quoted 25 lines

---

Change in v2: this was part of v1.

 drivers/pci/controller/pci-hyperv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/pci-hyperv.c +1 -1
index 9977abff92fc..0fe0283368d2 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;
Signature · 1 line
2.19.1