2014-10-20 08:28:10

by Yao Dongdong

[permalink] [raw]
Subject: [PATCH 1/2] Thermal:Fix memory leak if occur goto unregister

Signed-off-by:[email protected]

---
drivers/thermal/thermal_core.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 71b0ec0..5b7d466 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1574,6 +1574,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
unregister:
release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
device_unregister(&tz->device);
+ kfree(tz);
return ERR_PTR(result);
}
EXPORT_SYMBOL_GPL(thermal_zone_device_register);
--
1.8.0.1


2014-10-20 12:31:53

by Eduardo Valentin

[permalink] [raw]
Subject: Re: [PATCH 1/2] Thermal:Fix memory leak if occur goto unregister

Hello,

On Mon, Oct 20, 2014 at 04:27:36PM +0800, Yao Dongdong wrote:
> Signed-off-by:[email protected]

Acked-by: Eduardo Valentin <[email protected]>

Rui, would you take care of this?

>
> ---
> drivers/thermal/thermal_core.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> index 71b0ec0..5b7d466 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -1574,6 +1574,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
> unregister:
> release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
> device_unregister(&tz->device);
> + kfree(tz);
> return ERR_PTR(result);
> }
> EXPORT_SYMBOL_GPL(thermal_zone_device_register);
> --
> 1.8.0.1
>
>


Attachments:
(No filename) (810.00 B)
signature.asc (473.00 B)
Digital signature
Download all attachments

2014-11-03 18:17:44

by R, Durgadoss

[permalink] [raw]
Subject: RE: [PATCH 1/2] Thermal:Fix memory leak if occur goto unregister

>-----Original Message-----
>From: [email protected] [mailto:linux-pm-
>[email protected]] On Behalf Of Eduardo Valentin
>Sent: Monday, October 20, 2014 6:04 PM
>To: Yao Dongdong
>Cc: Zhang, Rui; [email protected]; LKML
>Subject: Re: [PATCH 1/2] Thermal:Fix memory leak if occur goto unregister
>
>Hello,
>
>On Mon, Oct 20, 2014 at 04:27:36PM +0800, Yao Dongdong wrote:
>> Signed-off-by:[email protected]
>
>Acked-by: Eduardo Valentin <[email protected]>
>
>Rui, would you take care of this?
>

If I remember it right, this 'tz' is freed in the thermal_release()
function, during device_unregister().

It is similar in all other functions in thermal_core.c

So, Yao, Did you really test this patch ?
And did not see any crashes ?

Thanks,
Durga

>>
>> ---
>> drivers/thermal/thermal_core.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
>> index 71b0ec0..5b7d466 100644
>> --- a/drivers/thermal/thermal_core.c
>> +++ b/drivers/thermal/thermal_core.c
>> @@ -1574,6 +1574,7 @@ struct thermal_zone_device
>*thermal_zone_device_register(const char *type,
>> unregister:
>> release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
>> device_unregister(&tz->device);
>> + kfree(tz);
>> return ERR_PTR(result);
>> }
>> EXPORT_SYMBOL_GPL(thermal_zone_device_register);
>> --
>> 1.8.0.1
>>
>>

2014-11-03 22:59:32

by Eduardo Valentin

[permalink] [raw]
Subject: Re: [PATCH 1/2] Thermal:Fix memory leak if occur goto unregister

Hello,

On Mon, Nov 03, 2014 at 06:17:37PM +0000, R, Durgadoss wrote:
> >-----Original Message-----
> >From: [email protected] [mailto:linux-pm-
> >[email protected]] On Behalf Of Eduardo Valentin
> >Sent: Monday, October 20, 2014 6:04 PM
> >To: Yao Dongdong
> >Cc: Zhang, Rui; [email protected]; LKML
> >Subject: Re: [PATCH 1/2] Thermal:Fix memory leak if occur goto unregister
> >
> >Hello,
> >
> >On Mon, Oct 20, 2014 at 04:27:36PM +0800, Yao Dongdong wrote:
> >> Signed-off-by:[email protected]
> >
> >Acked-by: Eduardo Valentin <[email protected]>
> >
> >Rui, would you take care of this?
> >
>
> If I remember it right, this 'tz' is freed in the thermal_release()
> function, during device_unregister().
>
> It is similar in all other functions in thermal_core.c
>
> So, Yao, Did you really test this patch ?
> And did not see any crashes ?
>

Yao, reading the patch change carefully, now I see that Durga is correct
here.

> Thanks,
> Durga
>
> >>
> >> ---
> >> drivers/thermal/thermal_core.c | 1 +
> >> 1 file changed, 1 insertion(+)
> >>
> >> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> >> index 71b0ec0..5b7d466 100644
> >> --- a/drivers/thermal/thermal_core.c
> >> +++ b/drivers/thermal/thermal_core.c
> >> @@ -1574,6 +1574,7 @@ struct thermal_zone_device
> >*thermal_zone_device_register(const char *type,
> >> unregister:
> >> release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
> >> device_unregister(&tz->device);
> >> + kfree(tz);

The device unregister is called above your kfree call, which will cause
the thermal_release to be called. Did you test the code for double kfree
calls? Your patch probably inserts a memory corruption.

I will revert your patch from my tree until you provide an answer about
your testing.

Thanks,


Eduardo Valentin

> >> return ERR_PTR(result);
> >> }
> >> EXPORT_SYMBOL_GPL(thermal_zone_device_register);
> >> --
> >> 1.8.0.1
> >>
> >>


Attachments:
(No filename) (1.94 kB)
signature.asc (473.00 B)
Digital signature
Download all attachments

2014-11-04 02:01:41

by Yao Dongdong

[permalink] [raw]
Subject: Re: [PATCH 1/2] Thermal:Fix memory leak if occur goto unregister

On 2014/11/4 2:35, Eduardo Valentin wrote:
> Hello,
>
> On Mon, Nov 03, 2014 at 06:17:37PM +0000, R, Durgadoss wrote:
>>> -----Original Message-----
>>> From: [email protected] [mailto:linux-pm-
>>> [email protected]] On Behalf Of Eduardo Valentin
>>> Sent: Monday, October 20, 2014 6:04 PM
>>> To: Yao Dongdong
>>> Cc: Zhang, Rui; [email protected]; LKML
>>> Subject: Re: [PATCH 1/2] Thermal:Fix memory leak if occur goto unregister
>>>
>>> Hello,
>>>
>>> On Mon, Oct 20, 2014 at 04:27:36PM +0800, Yao Dongdong wrote:
>>>> Signed-off-by:[email protected]
>>> Acked-by: Eduardo Valentin <[email protected]>
>>>
>>> Rui, would you take care of this?
>>>
>> If I remember it right, this 'tz' is freed in the thermal_release()
>> function, during device_unregister().
>>
>> It is similar in all other functions in thermal_core.c
>>
>> So, Yao, Did you really test this patch ?
>> And did not see any crashes ?
>>
> Yao, reading the patch change carefully, now I see that Durga is correct
> here.
>
>> Thanks,
>> Durga
>>
>>>> ---
>>>> drivers/thermal/thermal_core.c | 1 +
>>>> 1 file changed, 1 insertion(+)
>>>>
>>>> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
>>>> index 71b0ec0..5b7d466 100644
>>>> --- a/drivers/thermal/thermal_core.c
>>>> +++ b/drivers/thermal/thermal_core.c
>>>> @@ -1574,6 +1574,7 @@ struct thermal_zone_device
>>> *thermal_zone_device_register(const char *type,
>>>> unregister:
>>>> release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
>>>> device_unregister(&tz->device);
>>>> + kfree(tz);
> The device unregister is called above your kfree call, which will cause
> the thermal_release to be called. Did you test the code for double kfree
> calls? Your patch probably inserts a memory corruption.
>
> I will revert your patch from my tree until you provide an answer about
> your testing.

Yes, i have checked it and you are right, the patch will double kfree tz.

Thansks Durga for correcting me.

> Thanks,
>
>
> Eduardo Valentin
>
>>>> return ERR_PTR(result);
>>>> }
>>>> EXPORT_SYMBOL_GPL(thermal_zone_device_register);
>>>> --
>>>> 1.8.0.1
>>>>
>>>>