All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] EDAC: highbank: Fix memory leak in highbank_mc_probe
@ 2022-12-29  5:48 Miaoqian Lin
  2023-01-03 12:25 ` Andre Przywara
  2023-01-03 16:41 ` Borislav Petkov
  0 siblings, 2 replies; 3+ messages in thread
From: Miaoqian Lin @ 2022-12-29  5:48 UTC (permalink / raw)
  To: Andre Przywara, Borislav Petkov, Tony Luck, James Morse,
	Mauro Carvalho Chehab, Robert Richter, Rob Herring, linux-edac,
	linux-kernel
  Cc: linmq006

edac_mc_alloc() allocates memory. The memory are not released
when devres_open_group() fails, which causes memory leak.
Call edac_mc_free() in the error handling to fix this.

Fixes: a1b01edb2745 ("edac: add support for Calxeda highbank memory controller")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
altr_sdram_probe() performs similar operations,
I take it as reference.
---
 drivers/edac/highbank_mc_edac.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/edac/highbank_mc_edac.c b/drivers/edac/highbank_mc_edac.c
index 61b76ec226af..19fba258ae10 100644
--- a/drivers/edac/highbank_mc_edac.c
+++ b/drivers/edac/highbank_mc_edac.c
@@ -174,8 +174,10 @@ static int highbank_mc_probe(struct platform_device *pdev)
 	drvdata = mci->pvt_info;
 	platform_set_drvdata(pdev, mci);
 
-	if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL))
-		return -ENOMEM;
+	if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) {
+		res = -ENOMEM;
+		goto free;
+	}
 
 	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!r) {
@@ -243,6 +245,7 @@ static int highbank_mc_probe(struct platform_device *pdev)
 	edac_mc_del_mc(&pdev->dev);
 err:
 	devres_release_group(&pdev->dev, NULL);
+free:
 	edac_mc_free(mci);
 	return res;
 }
-- 
2.25.1


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

* Re: [PATCH] EDAC: highbank: Fix memory leak in highbank_mc_probe
  2022-12-29  5:48 [PATCH] EDAC: highbank: Fix memory leak in highbank_mc_probe Miaoqian Lin
@ 2023-01-03 12:25 ` Andre Przywara
  2023-01-03 16:41 ` Borislav Petkov
  1 sibling, 0 replies; 3+ messages in thread
From: Andre Przywara @ 2023-01-03 12:25 UTC (permalink / raw)
  To: Miaoqian Lin
  Cc: Borislav Petkov, Tony Luck, James Morse, Mauro Carvalho Chehab,
	Robert Richter, Rob Herring, linux-edac, linux-kernel

On Thu, 29 Dec 2022 09:48:24 +0400
Miaoqian Lin <linmq006@gmail.com> wrote:

Hi,

> edac_mc_alloc() allocates memory. The memory are not released
> when devres_open_group() fails, which causes memory leak.
> Call edac_mc_free() in the error handling to fix this.

Yes, this looks correct.

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

Cheers,
Andre

> Fixes: a1b01edb2745 ("edac: add support for Calxeda highbank memory controller")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
> altr_sdram_probe() performs similar operations,
> I take it as reference.
> ---
>  drivers/edac/highbank_mc_edac.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/edac/highbank_mc_edac.c b/drivers/edac/highbank_mc_edac.c
> index 61b76ec226af..19fba258ae10 100644
> --- a/drivers/edac/highbank_mc_edac.c
> +++ b/drivers/edac/highbank_mc_edac.c
> @@ -174,8 +174,10 @@ static int highbank_mc_probe(struct platform_device *pdev)
>  	drvdata = mci->pvt_info;
>  	platform_set_drvdata(pdev, mci);
>  
> -	if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL))
> -		return -ENOMEM;
> +	if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) {
> +		res = -ENOMEM;
> +		goto free;
> +	}
>  
>  	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>  	if (!r) {
> @@ -243,6 +245,7 @@ static int highbank_mc_probe(struct platform_device *pdev)
>  	edac_mc_del_mc(&pdev->dev);
>  err:
>  	devres_release_group(&pdev->dev, NULL);
> +free:
>  	edac_mc_free(mci);
>  	return res;
>  }


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

* Re: [PATCH] EDAC: highbank: Fix memory leak in highbank_mc_probe
  2022-12-29  5:48 [PATCH] EDAC: highbank: Fix memory leak in highbank_mc_probe Miaoqian Lin
  2023-01-03 12:25 ` Andre Przywara
@ 2023-01-03 16:41 ` Borislav Petkov
  1 sibling, 0 replies; 3+ messages in thread
From: Borislav Petkov @ 2023-01-03 16:41 UTC (permalink / raw)
  To: Miaoqian Lin
  Cc: Andre Przywara, Tony Luck, James Morse, Mauro Carvalho Chehab,
	Robert Richter, Rob Herring, linux-edac, linux-kernel

On Thu, Dec 29, 2022 at 09:48:24AM +0400, Miaoqian Lin wrote:
> edac_mc_alloc() allocates memory. The memory are not released
> when devres_open_group() fails, which causes memory leak.
> Call edac_mc_free() in the error handling to fix this.
> 
> Fixes: a1b01edb2745 ("edac: add support for Calxeda highbank memory controller")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
> altr_sdram_probe() performs similar operations,
> I take it as reference.
> ---
>  drivers/edac/highbank_mc_edac.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)

Applied, thanks.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

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

end of thread, other threads:[~2023-01-03 16:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-29  5:48 [PATCH] EDAC: highbank: Fix memory leak in highbank_mc_probe Miaoqian Lin
2023-01-03 12:25 ` Andre Przywara
2023-01-03 16:41 ` Borislav Petkov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.