linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhang Rui <rui.zhang@intel.com>
To: Wei Yongjun <weiyj.lk@gmail.com>
Cc: eduardo.valentin@ti.com, yongjun_wei@trendmicro.com.cn,
	linux-pm@vger.kernel.org,
	Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Subject: Re: [PATCH -next] Thermal: x86_pkg_temp: fix krealloc() misuse in in pkg_temp_thermal_device_add()
Date: Fri, 21 Jun 2013 16:07:42 +0800	[thread overview]
Message-ID: <1371802062.2170.6.camel@rzhang1-mobl4> (raw)
In-Reply-To: <CAPgLHd_d5DHn==OFdBsLi_Kkekd5h44Cx6m9Hj5EM_yOGJXKPQ@mail.gmail.com>

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?

> 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?

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);
>  
> 



  reply	other threads:[~2013-06-21  8:07 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 [this message]
2013-06-21  8:49   ` Wei Yongjun
2013-06-21 16:36     ` Srinivas Pandruvada
2013-07-12  0:36     ` Srinivas Pandruvada
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=1371802062.2170.6.camel@rzhang1-mobl4 \
    --to=rui.zhang@intel.com \
    --cc=eduardo.valentin@ti.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=srinivas.pandruvada@linux.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).