* ab3100-otp: fix memory leak in ab3100_otp_probe
@ 2010-05-25 6:49 Axel Lin
2010-05-25 7:02 ` Linus WALLEIJ
2010-06-18 18:17 ` Samuel Ortiz
0 siblings, 2 replies; 3+ messages in thread
From: Axel Lin @ 2010-05-25 6:49 UTC (permalink / raw)
To: linux-kernel; +Cc: Linus Walleij, Samuel Ortiz
In current implementation, there is a memory leak if ab3100_otp_read fail.
And in the case of ab3100_otp_init_debugfs fail, it does not properly remove
sysfs entries.
This patch properly handle above failure cases.
Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
drivers/mfd/ab3100-otp.c | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/mfd/ab3100-otp.c b/drivers/mfd/ab3100-otp.c
index 2d14655..939b876 100644
--- a/drivers/mfd/ab3100-otp.c
+++ b/drivers/mfd/ab3100-otp.c
@@ -202,7 +202,7 @@ static int __init ab3100_otp_probe(struct platform_device *pdev)
err = ab3100_otp_read(otp);
if (err)
- return err;
+ goto err_otp_read;
dev_info(&pdev->dev, "AB3100 OTP readout registered\n");
@@ -211,21 +211,21 @@ static int __init ab3100_otp_probe(struct platform_device *pdev)
err = device_create_file(&pdev->dev,
&ab3100_otp_attrs[i]);
if (err)
- goto out_no_sysfs;
+ goto err_create_file;
}
/* debugfs entries */
err = ab3100_otp_init_debugfs(&pdev->dev, otp);
if (err)
- goto out_no_debugfs;
+ goto err_init_debugfs;
return 0;
-out_no_sysfs:
- for (i = 0; i < ARRAY_SIZE(ab3100_otp_attrs); i++)
- device_remove_file(&pdev->dev,
- &ab3100_otp_attrs[i]);
-out_no_debugfs:
+err_init_debugfs:
+err_create_file:
+ while (--i >= 0)
+ device_remove_file(&pdev->dev, &ab3100_otp_attrs[i]);
+err_otp_read:
kfree(otp);
return err;
}
--
1.5.4.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: ab3100-otp: fix memory leak in ab3100_otp_probe
2010-05-25 6:49 ab3100-otp: fix memory leak in ab3100_otp_probe Axel Lin
@ 2010-05-25 7:02 ` Linus WALLEIJ
2010-06-18 18:17 ` Samuel Ortiz
1 sibling, 0 replies; 3+ messages in thread
From: Linus WALLEIJ @ 2010-05-25 7:02 UTC (permalink / raw)
To: Axel Lin, linux-kernel; +Cc: Samuel Ortiz
[Axel]
> In current implementation, there is a memory leak if ab3100_otp_read fail.
> And in the case of ab3100_otp_init_debugfs fail, it does not properly
> remove
> sysfs entries.
> This patch properly handle above failure cases.
>
> Signed-off-by: Axel Lin <axel.lin@gmail.com>
Acked-by: Linus Walleij <linus.walleij@stericsson.com>
Thanks for fixing this!
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: ab3100-otp: fix memory leak in ab3100_otp_probe
2010-05-25 6:49 ab3100-otp: fix memory leak in ab3100_otp_probe Axel Lin
2010-05-25 7:02 ` Linus WALLEIJ
@ 2010-06-18 18:17 ` Samuel Ortiz
1 sibling, 0 replies; 3+ messages in thread
From: Samuel Ortiz @ 2010-06-18 18:17 UTC (permalink / raw)
To: Axel Lin; +Cc: linux-kernel, Linus Walleij
Hi Axel,
On Tue, May 25, 2010 at 02:49:51PM +0800, Axel Lin wrote:
> In current implementation, there is a memory leak if ab3100_otp_read fail.
> And in the case of ab3100_otp_init_debugfs fail, it does not properly remove
> sysfs entries.
> This patch properly handle above failure cases.
Patch applied, thanks a lot.
Cheers,
Samuel.
> Signed-off-by: Axel Lin <axel.lin@gmail.com>
> ---
> drivers/mfd/ab3100-otp.c | 16 ++++++++--------
> 1 files changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/mfd/ab3100-otp.c b/drivers/mfd/ab3100-otp.c
> index 2d14655..939b876 100644
> --- a/drivers/mfd/ab3100-otp.c
> +++ b/drivers/mfd/ab3100-otp.c
> @@ -202,7 +202,7 @@ static int __init ab3100_otp_probe(struct platform_device *pdev)
>
> err = ab3100_otp_read(otp);
> if (err)
> - return err;
> + goto err_otp_read;
>
> dev_info(&pdev->dev, "AB3100 OTP readout registered\n");
>
> @@ -211,21 +211,21 @@ static int __init ab3100_otp_probe(struct platform_device *pdev)
> err = device_create_file(&pdev->dev,
> &ab3100_otp_attrs[i]);
> if (err)
> - goto out_no_sysfs;
> + goto err_create_file;
> }
>
> /* debugfs entries */
> err = ab3100_otp_init_debugfs(&pdev->dev, otp);
> if (err)
> - goto out_no_debugfs;
> + goto err_init_debugfs;
>
> return 0;
>
> -out_no_sysfs:
> - for (i = 0; i < ARRAY_SIZE(ab3100_otp_attrs); i++)
> - device_remove_file(&pdev->dev,
> - &ab3100_otp_attrs[i]);
> -out_no_debugfs:
> +err_init_debugfs:
> +err_create_file:
> + while (--i >= 0)
> + device_remove_file(&pdev->dev, &ab3100_otp_attrs[i]);
> +err_otp_read:
> kfree(otp);
> return err;
> }
> --
> 1.5.4.3
>
>
>
--
Intel Open Source Technology Centre
http://oss.intel.com/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-06-18 18:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-25 6:49 ab3100-otp: fix memory leak in ab3100_otp_probe Axel Lin
2010-05-25 7:02 ` Linus WALLEIJ
2010-06-18 18:17 ` Samuel Ortiz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox