linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PCI: hv: Use kfree(hbus) in hv_pci_probe()'s error handling path
@ 2020-01-06 22:39 Dexuan Cui
  2020-01-18 16:51 ` Michael Kelley
  2020-02-21 14:40 ` Lorenzo Pieralisi
  0 siblings, 2 replies; 4+ messages in thread
From: Dexuan Cui @ 2020-01-06 22:39 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, sashal, lorenzo.pieralisi, bhelgaas,
	linux-hyperv, linux-pci, linux-kernel, mikelley, Alexander.Levin
  Cc: 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.

Fixes: 877b911a5ba0 ("PCI: hv: Avoid a kmemleak false positive caused by the hbus buffer")
Signed-off-by: Dexuan Cui <decui@microsoft.com>
---

Sorry for missing the error handling path.

 drivers/pci/controller/pci-hyperv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
index 9977abff92fc..15011a349520 100644
--- a/drivers/pci/controller/pci-hyperv.c
+++ b/drivers/pci/controller/pci-hyperv.c
@@ -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;
 }
 
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [PATCH] PCI: hv: Use kfree(hbus) in hv_pci_probe()'s error handling path
  2020-01-06 22:39 [PATCH] PCI: hv: Use kfree(hbus) in hv_pci_probe()'s error handling path Dexuan Cui
@ 2020-01-18 16:51 ` Michael Kelley
  2020-02-21 14:40 ` Lorenzo Pieralisi
  1 sibling, 0 replies; 4+ messages in thread
From: Michael Kelley @ 2020-01-18 16:51 UTC (permalink / raw)
  To: Dexuan Cui, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
	sashal, lorenzo.pieralisi, bhelgaas, linux-hyperv, linux-pci,
	linux-kernel, Sasha Levin

From: Dexuan Cui <decui@microsoft.com> Sent: Monday, January 6, 2020 2:39 PM
> 
> 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")
> Signed-off-by: Dexuan Cui <decui@microsoft.com>
> ---
> 
> Sorry for missing the error handling path.
> 
>  drivers/pci/controller/pci-hyperv.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
> index 9977abff92fc..15011a349520 100644
> --- a/drivers/pci/controller/pci-hyperv.c
> +++ b/drivers/pci/controller/pci-hyperv.c
> @@ -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;
>  }
> 
> --
> 2.19.1

Reviewed-by: Michael Kelley <mikelley@microsoft.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] PCI: hv: Use kfree(hbus) in hv_pci_probe()'s error handling path
  2020-01-06 22:39 [PATCH] PCI: hv: Use kfree(hbus) in hv_pci_probe()'s error handling path Dexuan Cui
  2020-01-18 16:51 ` Michael Kelley
@ 2020-02-21 14:40 ` Lorenzo Pieralisi
  2020-02-21 20:17   ` Dexuan Cui
  1 sibling, 1 reply; 4+ messages in thread
From: Lorenzo Pieralisi @ 2020-02-21 14:40 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: kys, haiyangz, sthemmin, sashal, bhelgaas, linux-hyperv,
	linux-pci, linux-kernel, mikelley, Alexander.Levin

On Mon, Jan 06, 2020 at 02:39:11PM -0800, Dexuan Cui wrote:
> 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

> Fixes: 877b911a5ba0 ("PCI: hv: Avoid a kmemleak false positive caused by the hbus buffer")
> Signed-off-by: Dexuan Cui <decui@microsoft.com>
> ---
> 
> Sorry for missing the error handling path.
> 
>  drivers/pci/controller/pci-hyperv.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
> index 9977abff92fc..15011a349520 100644
> --- a/drivers/pci/controller/pci-hyperv.c
> +++ b/drivers/pci/controller/pci-hyperv.c
> @@ -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;
>  }
>  
> -- 
> 2.19.1
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] PCI: hv: Use kfree(hbus) in hv_pci_probe()'s error handling path
  2020-02-21 14:40 ` Lorenzo Pieralisi
@ 2020-02-21 20:17   ` Dexuan Cui
  0 siblings, 0 replies; 4+ messages in thread
From: Dexuan Cui @ 2020-02-21 20:17 UTC (permalink / raw)
  To: Lorenzo Pieralisi
  Cc: KY Srinivasan, Haiyang Zhang, Stephen Hemminger, sashal,
	bhelgaas, linux-hyperv, linux-pci, linux-kernel, Michael Kelley,
	Sasha Levin

> From: linux-hyperv-owner@vger.kernel.org
> <linux-hyperv-owner@vger.kernel.org> On Behalf Of Lorenzo Pieralisi
> Sent: Friday, February 21, 2020 6:40 AM
> 
> On Mon, Jan 06, 2020 at 02:39:11PM -0800, Dexuan Cui wrote:
> > 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

Ok, will post 2 separate patches shortly.

Thanks,
-- Dexuan

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-02-21 20:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-06 22:39 [PATCH] PCI: hv: Use kfree(hbus) in hv_pci_probe()'s error handling path Dexuan Cui
2020-01-18 16:51 ` Michael Kelley
2020-02-21 14:40 ` Lorenzo Pieralisi
2020-02-21 20:17   ` Dexuan Cui

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).