* [PATCH] thermal: ti-soc-thermal: ti-bandgap.c: Cleaning up memory leak
@ 2014-06-01 11:33 Rickard Strandqvist
2014-06-02 17:08 ` Eduardo Valentin
0 siblings, 1 reply; 3+ messages in thread
From: Rickard Strandqvist @ 2014-06-01 11:33 UTC (permalink / raw)
To: Eduardo Valentin, Zhang Rui
Cc: Rickard Strandqvist, Grant Likely, Rob Herring, linux-pm,
linux-kernel, devicetree
There is a risk for memory leak in when something unexpected happens
and the function returns.
This was largely found by using a static code analysis program called cppcheck.
Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
---
drivers/thermal/ti-soc-thermal/ti-bandgap.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/thermal/ti-soc-thermal/ti-bandgap.c b/drivers/thermal/ti-soc-thermal/ti-bandgap.c
index 3ab12ee..8401d2e 100644
--- a/drivers/thermal/ti-soc-thermal/ti-bandgap.c
+++ b/drivers/thermal/ti-soc-thermal/ti-bandgap.c
@@ -1155,8 +1155,9 @@ static struct ti_bandgap *ti_bandgap_build(struct platform_device *pdev)
/* register shadow for context save and restore */
bgp->regval = devm_kzalloc(&pdev->dev, sizeof(*bgp->regval) *
bgp->conf->sensor_count, GFP_KERNEL);
- if (!bgp) {
+ if (!bgp->regval) {
dev_err(&pdev->dev, "Unable to allocate mem for driver ref\n");
+ devm_kfree(&pdev->dev, bgp);
return ERR_PTR(-ENOMEM);
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] thermal: ti-soc-thermal: ti-bandgap.c: Cleaning up memory leak
2014-06-01 11:33 [PATCH] thermal: ti-soc-thermal: ti-bandgap.c: Cleaning up memory leak Rickard Strandqvist
@ 2014-06-02 17:08 ` Eduardo Valentin
2014-06-02 21:13 ` Rickard Strandqvist
0 siblings, 1 reply; 3+ messages in thread
From: Eduardo Valentin @ 2014-06-02 17:08 UTC (permalink / raw)
To: Rickard Strandqvist
Cc: Eduardo Valentin, Zhang Rui, Grant Likely, Rob Herring, linux-pm,
linux-kernel, devicetree
On Sun, Jun 01, 2014 at 01:33:51PM +0200, Rickard Strandqvist wrote:
> There is a risk for memory leak in when something unexpected happens
> and the function returns.
I don't think there is a risk of memory leak, but wrong address access,
in this case.
>
> This was largely found by using a static code analysis program called cppcheck.
>
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
> ---
> drivers/thermal/ti-soc-thermal/ti-bandgap.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/thermal/ti-soc-thermal/ti-bandgap.c b/drivers/thermal/ti-soc-thermal/ti-bandgap.c
> index 3ab12ee..8401d2e 100644
> --- a/drivers/thermal/ti-soc-thermal/ti-bandgap.c
> +++ b/drivers/thermal/ti-soc-thermal/ti-bandgap.c
> @@ -1155,8 +1155,9 @@ static struct ti_bandgap *ti_bandgap_build(struct platform_device *pdev)
> /* register shadow for context save and restore */
> bgp->regval = devm_kzalloc(&pdev->dev, sizeof(*bgp->regval) *
> bgp->conf->sensor_count, GFP_KERNEL);
> - if (!bgp) {
> + if (!bgp->regval) {
I agree with this fix.
> dev_err(&pdev->dev, "Unable to allocate mem for driver ref\n");
> + devm_kfree(&pdev->dev, bgp);
But I think this is unnecessary, as it has been managed allocated.
Cheers,
Eduardo
> return ERR_PTR(-ENOMEM);
> }
>
> --
> 1.7.10.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-pm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] thermal: ti-soc-thermal: ti-bandgap.c: Cleaning up memory leak
2014-06-02 17:08 ` Eduardo Valentin
@ 2014-06-02 21:13 ` Rickard Strandqvist
0 siblings, 0 replies; 3+ messages in thread
From: Rickard Strandqvist @ 2014-06-02 21:13 UTC (permalink / raw)
To: Eduardo Valentin
Cc: Eduardo Valentin, Zhang Rui, Grant Likely, Rob Herring, linux-pm,
linux-kernel, devicetree
Hi
Okay, then I make a new patch with only the if() part of the code.
Best regards
Rickard Strandqvist
2014-06-02 19:08 GMT+02:00 Eduardo Valentin <edubezval@gmail.com>:
> On Sun, Jun 01, 2014 at 01:33:51PM +0200, Rickard Strandqvist wrote:
>> There is a risk for memory leak in when something unexpected happens
>> and the function returns.
>
> I don't think there is a risk of memory leak, but wrong address access,
> in this case.
>
>>
>> This was largely found by using a static code analysis program called cppcheck.
>>
>> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
>> ---
>> drivers/thermal/ti-soc-thermal/ti-bandgap.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/thermal/ti-soc-thermal/ti-bandgap.c b/drivers/thermal/ti-soc-thermal/ti-bandgap.c
>> index 3ab12ee..8401d2e 100644
>> --- a/drivers/thermal/ti-soc-thermal/ti-bandgap.c
>> +++ b/drivers/thermal/ti-soc-thermal/ti-bandgap.c
>> @@ -1155,8 +1155,9 @@ static struct ti_bandgap *ti_bandgap_build(struct platform_device *pdev)
>> /* register shadow for context save and restore */
>> bgp->regval = devm_kzalloc(&pdev->dev, sizeof(*bgp->regval) *
>> bgp->conf->sensor_count, GFP_KERNEL);
>> - if (!bgp) {
>> + if (!bgp->regval) {
>
> I agree with this fix.
>
>> dev_err(&pdev->dev, "Unable to allocate mem for driver ref\n");
>> + devm_kfree(&pdev->dev, bgp);
>
> But I think this is unnecessary, as it has been managed allocated.
>
> Cheers,
>
> Eduardo
>
>> return ERR_PTR(-ENOMEM);
>> }
>>
>> --
>> 1.7.10.4
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-pm" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-06-02 21:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-01 11:33 [PATCH] thermal: ti-soc-thermal: ti-bandgap.c: Cleaning up memory leak Rickard Strandqvist
2014-06-02 17:08 ` Eduardo Valentin
2014-06-02 21:13 ` Rickard Strandqvist
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).