Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3197486ybl; Mon, 19 Aug 2019 14:01:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqw4Z13ClMZTGFwxVGlAe0x+m1OY/6uywAjflKqrVCEdz6Wu/qGfkCGCZLAv9TJpsWj0o33c X-Received: by 2002:a17:902:e510:: with SMTP id ck16mr16005902plb.334.1566248481426; Mon, 19 Aug 2019 14:01:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566248481; cv=none; d=google.com; s=arc-20160816; b=oKkkENoSZd3l8E4IpzWk/y5rv1eX7wJv5/n/FNyrmgD+MX+pm/VPAdezrPmlSRfMeJ HT0Bzk+R6GaBvyxjGGMe8kXSTb2IU+jvh5/hpHQtWA2YjWOubGtRBRTwJeq20HieE/6n +urfoVnJ2denK1NApKnk70zZNG+jxNyqfNUkg8gvbtqw9pWIsI81t/QSO89Rd4IsjeAO YafICgvD2jDT4PimI8Gs05gMb6kLA3uagOxHWLtg6IItlLNSMlhsmws2Zqv9zLGGfKd9 7z11vitc7zQz8/J9pH0neWxSJ/qhou6wDgNFqJ+bUiGJONKxsnOEHs95HKg6GSd/ka35 pU/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=qvztveGCP8rAVOCE3TihtUu+wJQiIJmbl19Afmtoalk=; b=D0AFyiYyDmrJlmUTZpsOOjcTxD0w7ix5GXm6icWrKIVaHO9cFnm52qzTV5tClU1Nxt ErTbqegmQ8doRzwd257v0Vtg4P37G8Jg1H9X+6ecI1mtCvgpecQnMY+RE9kV9Qu0GBo9 bwaO33pmIMQIO6+Bo8Q1Qs3HtwnmQrY1/Hy5OLs93cAKfl5RwzXOWv1aME8SGkfIjxC3 +egCs4owAladDWOSuxNW/3oSYFjfjOnyr2hX63jaJvdOpdsfZ/eMkOsk2sPu4fB4tQ+S 2Zk6ghpaNlo6mBX7A2pNM6bHSWRQIMpPdOokpCZjxcA1wprpKxrb5Y1Gg+Ju8Bv6omFu 8PbQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r200si10355031pgr.518.2019.08.19.14.01.05; Mon, 19 Aug 2019 14:01:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728387AbfHSVAI (ORCPT + 99 others); Mon, 19 Aug 2019 17:00:08 -0400 Received: from mail-yw1-f66.google.com ([209.85.161.66]:40221 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727769AbfHSVAI (ORCPT ); Mon, 19 Aug 2019 17:00:08 -0400 Received: by mail-yw1-f66.google.com with SMTP id z64so1378945ywe.7; Mon, 19 Aug 2019 14:00:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=qvztveGCP8rAVOCE3TihtUu+wJQiIJmbl19Afmtoalk=; b=IGOn9j5Q+EOSySGrJfPW5GUAA964uMzTzOIFs/eR5NnC3Scz7O+4CGJgXF48zvvVqE G/tkbFjQX0PcNnjsqGZ0SJAR6C2cD7pW7iAGeGh8ydRjVybGs3kvPIOA6CGqJlX2n6sL N/1zet0hGuyYuP21EygKJaCrjVdajqnrpRnEIAaD29r+7mynGUItc9pI+ZbYvB8DbVRF mofj+spVyV6co80tm8UNWRkhIIFRA2IRar1ajOH1A597Phk3339I+MKgPahr9oi9TTui w99YoD8iyq+wyrtIPPpzexS+5UcZULmqM/hCzDhX7O3xMCUT4FR+kdKnya6uN75/G4up GX7w== X-Gm-Message-State: APjAAAUM1xX2lgAd1eUcL9ZL3LKnJIL1V4JmlSocMJ5+lhG8jx/E1u1d rHRP3LDjSWNjz8QO0qBEDAoDyEjOgMuCFA== X-Received: by 2002:a81:918c:: with SMTP id i134mr8802953ywg.65.1566248407313; Mon, 19 Aug 2019 14:00:07 -0700 (PDT) Received: from localhost.localdomain (24-158-240-219.dhcp.smyr.ga.charter.com. [24.158.240.219]) by smtp.gmail.com with ESMTPSA id l71sm1564543ywl.39.2019.08.19.14.00.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Aug 2019 14:00:06 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Cc: Fenghua Yu , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org (open list:CORETEMP HARDWARE MONITORING DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] hwmon/coretemp: Fix a memory leak bug Date: Mon, 19 Aug 2019 16:00:02 -0500 Message-Id: <1566248402-6538-1-git-send-email-wenwen@cs.uga.edu> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In coretemp_init(), 'zone_devices' is allocated through kcalloc(). However, it is not deallocated in the following execution if platform_driver_register() fails, leading to a memory leak. To fix this issue, introduce the 'outzone' label to free 'zone_devices' before returning the error. Signed-off-by: Wenwen Wang --- drivers/hwmon/coretemp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index fe6618e..d855c78 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -736,7 +736,7 @@ static int __init coretemp_init(void) err = platform_driver_register(&coretemp_driver); if (err) - return err; + goto outzone; err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "hwmon/coretemp:online", coretemp_cpu_online, coretemp_cpu_offline); @@ -747,6 +747,7 @@ static int __init coretemp_init(void) outdrv: platform_driver_unregister(&coretemp_driver); +outzone: kfree(zone_devices); return err; } -- 2.7.4