linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
To: Wei Yongjun <weiyj.lk@gmail.com>
Cc: rui.zhang@intel.com, eduardo.valentin@ti.com,
	yongjun_wei@trendmicro.com.cn, linux-pm@vger.kernel.org
Subject: Re: [PATCH -next] Thermal: x86_pkg_temp: fix krealloc() misuse in in pkg_temp_thermal_device_add()
Date: Thu, 11 Jul 2013 17:36:12 -0700	[thread overview]
Message-ID: <51DF4F7C.10906@linux.intel.com> (raw)
In-Reply-To: <CAPgLHd_T+ez7_fifC9sY33EKcuAa_A+P6w6gK72nn=4hjzp87Q@mail.gmail.com>

Tested this patch and it works fine.

Thanks,
Srinivas

On 06/21/2013 01:49 AM, Wei Yongjun wrote:
> On 06/21/2013 04:07 PM, Zhang Rui wrote:
>> On Tue, 2013-06-18 at 21:09 +0800, Wei Yongjun wrote:
>>> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
>>>
>>> If krealloc() returns NULL, it doesn't free the original. So any code
>>> of the form 'foo = krealloc(foo, ...);' is almost certainly a bug.
>>>
>> you mean this would probably cause a memory leak, right?
> Yes.
>
>>> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
>>> ---
>>>   drivers/thermal/x86_pkg_temp_thermal.c | 8 +++++---
>>>   1 file changed, 5 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/thermal/x86_pkg_temp_thermal.c b/drivers/thermal/x86_pkg_temp_thermal.c
>>> index 5de56f6..b90e84b 100644
>>> --- a/drivers/thermal/x86_pkg_temp_thermal.c
>>> +++ b/drivers/thermal/x86_pkg_temp_thermal.c
>>> @@ -394,6 +394,7 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
>>>   	char buffer[30];
>>>   	int thres_count;
>>>   	u32 eax, ebx, ecx, edx;
>>> +	u8 *temp;
>>>   
>>>   	cpuid(6, &eax, &ebx, &ecx, &edx);
>>>   	thres_count = ebx & 0x07;
>>> @@ -417,13 +418,14 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
>>>   	spin_lock(&pkg_work_lock);
>>>   	if (topology_physical_package_id(cpu) > max_phy_id)
>>>   		max_phy_id = topology_physical_package_id(cpu);
>>> -	pkg_work_scheduled = krealloc(pkg_work_scheduled,
>>> -				(max_phy_id+1) * sizeof(u8), GFP_ATOMIC);
>>> -	if (!pkg_work_scheduled) {
>>> +	temp = krealloc(pkg_work_scheduled,
>>> +			(max_phy_id+1) * sizeof(u8), GFP_ATOMIC);
>>> +	if (!temp) {
>> without this patch, this function will quite if krealloc returns NULL,
>> but with the previous pkg_work_scheduled unfreed, right?
> Yes, without patch, previous pkg_work_scheduled will unfreed if krealloc
> return NULL.
>
>> thanks,
>> rui
>>>   		spin_unlock(&pkg_work_lock);
>>>   		err = -ENOMEM;
>>>   		goto err_ret_free;
>>>   	}
>>> +	pkg_work_scheduled = temp;
>>>   	pkg_work_scheduled[topology_physical_package_id(cpu)] = 0;
>>>   	spin_unlock(&pkg_work_lock);
>>>   
>>>
>>
>>
>
>


  parent reply	other threads:[~2013-07-12  0:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-18 13:09 [PATCH -next] Thermal: x86_pkg_temp: fix krealloc() misuse in in pkg_temp_thermal_device_add() Wei Yongjun
2013-06-21  8:07 ` Zhang Rui
2013-06-21  8:49   ` Wei Yongjun
2013-06-21 16:36     ` Srinivas Pandruvada
2013-07-12  0:36     ` Srinivas Pandruvada [this message]
2013-07-15  8:19       ` Zhang Rui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51DF4F7C.10906@linux.intel.com \
    --to=srinivas.pandruvada@linux.intel.com \
    --cc=eduardo.valentin@ti.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=weiyj.lk@gmail.com \
    --cc=yongjun_wei@trendmicro.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).