From patchwork Tue Jun 18 13:09:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yongjun X-Patchwork-Id: 2742311 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CA510C0AB1 for ; Tue, 18 Jun 2013 13:09:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 03FB220402 for ; Tue, 18 Jun 2013 13:09:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AD85A20410 for ; Tue, 18 Jun 2013 13:09:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752964Ab3FRNJP (ORCPT ); Tue, 18 Jun 2013 09:09:15 -0400 Received: from mail-bk0-f50.google.com ([209.85.214.50]:55794 "EHLO mail-bk0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752106Ab3FRNJO (ORCPT ); Tue, 18 Jun 2013 09:09:14 -0400 Received: by mail-bk0-f50.google.com with SMTP id ik8so1785972bkc.9 for ; Tue, 18 Jun 2013 06:09:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type; bh=Zp4qZXI3XoXJesU4oyoD57PY5Z0atDaxRGm0tveGQ+w=; b=faq37pcNfXLltGP85gcA1Sa3FJQd9S0hm2uywRPZXRQ6e8X7bdwcv6oalcQpDlgO3/ MzP5GS/CmvuKMgYfuPGiFFo7rDdHlWF/KL5QlxlT9xoB/Y0DY3O4uIBV+FhudvAuF0gn pW48zbqgNCKqcKC7VhUARkKbiOn/nCnqZuwdS0WTwfVFk2pV03ojmf144UPsLRgofJlO 5oJCxNTP6hF3ZT26kUTXBTapwbDPHZarJuOKcdH45V1wHbo0vhR8jDUHnP9kBDrqVtyx HJSH9s4XuldtW1RGOMmw7j46CsB1znptzZi8tzfWRDGjfmW0nOLeYKznE+3OS/8NfUzL zwGA== MIME-Version: 1.0 X-Received: by 10.204.191.72 with SMTP id dl8mr2635849bkb.56.1371560953077; Tue, 18 Jun 2013 06:09:13 -0700 (PDT) Received: by 10.204.39.1 with HTTP; Tue, 18 Jun 2013 06:09:12 -0700 (PDT) Date: Tue, 18 Jun 2013 21:09:12 +0800 Message-ID: Subject: [PATCH -next] Thermal: x86_pkg_temp: fix krealloc() misuse in in pkg_temp_thermal_device_add() From: Wei Yongjun To: rui.zhang@intel.com, eduardo.valentin@ti.com Cc: yongjun_wei@trendmicro.com.cn, linux-pm@vger.kernel.org Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wei Yongjun If krealloc() returns NULL, it doesn't free the original. So any code of the form 'foo = krealloc(foo, ...);' is almost certainly a bug. Signed-off-by: Wei Yongjun --- drivers/thermal/x86_pkg_temp_thermal.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) -- 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 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) { 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);