From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752051AbdHHIic (ORCPT ); Tue, 8 Aug 2017 04:38:32 -0400 Received: from mga11.intel.com ([192.55.52.93]:61941 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750818AbdHHIia (ORCPT ); Tue, 8 Aug 2017 04:38:30 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,342,1498546800"; d="scan'208";a="116831941" Message-ID: <1502181504.4296.17.camel@intel.com> Subject: Re: [PATCH 1/3] thermal: core: Fix a memory leak in 'thermal_zone_device_register()' error handling path From: Zhang Rui To: Christophe JAILLET , edubezval@gmail.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Date: Tue, 08 Aug 2017 16:38:24 +0800 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.18.5.2-0ubuntu3 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 2017-07-16 at 08:59 +0200, Christophe JAILLET wrote: > 'tz' is freed in some error handling paths but not in the main one. > So free it also here to avoid a memory leak. > After device registered, tz is freed in thermal_release(). thanks, rui > Signed-off-by: Christophe JAILLET > --- >  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 5a51c740e372..9743f3e65eb0 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -1296,6 +1296,7 @@ thermal_zone_device_register(const char *type, > int trips, int mask, >  unregister: >   ida_simple_remove(&thermal_tz_ida, tz->id); >   device_unregister(&tz->device); > + kfree(tz); >   return ERR_PTR(result); >  } >  EXPORT_SYMBOL_GPL(thermal_zone_device_register);