Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp834518ybl; Wed, 28 Aug 2019 06:07:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZRHUiiQhldxYsOaQAMokOdBSg+uw6NSS7RAuWQ8c4lI3oZ/u9Mbr3C7gcATZCCeANA51U X-Received: by 2002:a17:902:6a:: with SMTP id 97mr4337394pla.5.1566997628780; Wed, 28 Aug 2019 06:07:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566997628; cv=none; d=google.com; s=arc-20160816; b=txPH4phkKXFi/GlVh4AkZev3FJIORRn3pQSuW+LLtVJ9I+aoDv5yhcyThLqdzNYcsA HyAa2sXyK2IOnsx8HxhGuXM1PKI2vH+di6mx5oJs+NtFhmA5fS2taOc3f5lJs6IjFGUP gvBfTrYjffnuQBRbF39fT/KouUvrpzLq5N91R4sjJSJARhm4+sLRnUBR3B5l0Zbx65WH Kz1cN8B9zpMxBOKDTDJ8kFOK4qNmE4hx9tyCwKaHcA3vezDG7CIg5PBNYrxJW/1dt5nM XqY27j7LBHwqWPP5jo9F43JteEXiqthGySSDzptSRWDjMKjHlWmAq0j7qs2eNT9g20t/ Ppgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=553UnxS5nJMWfegw6pNnYtXOIuTie1CyXnwEFe6q9i0=; b=Q53VFIIhFDpD8rWm9rmfgE4hT3hdCGUMjPtndd7UodpEGunmt4NFjCje5aLJ/aoQHb QHyi4uB7wyDRnnNK5S2itCZ90oNrji5+VVX77Kpq3YhHE9U0bU9PLcqBCulsG47Ttvz2 SzjomcBl/p8ZMYAuQbpo3xQbIfhpa9cD/6lkh4cadXvbPl7EuJvYOQm0ZuUgdYye7rVN AfrUzO6xwdS05M/X4BuHs8olsWu/o6M3pnXFM9S56b5r1zoBblaJca2PEevTlmA8tpTG zAZc22OMPuS2eNpfO4DWiT3ML7I6sMZMLW2ZHgZtELTcGf4LEilAXqgfpfBTgudJ1dgC vJMQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 15si2130062pgu.98.2019.08.28.06.06.52; Wed, 28 Aug 2019 06:07:08 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726508AbfH1NFp (ORCPT + 99 others); Wed, 28 Aug 2019 09:05:45 -0400 Received: from mga02.intel.com ([134.134.136.20]:60001 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726293AbfH1NFo (ORCPT ); Wed, 28 Aug 2019 09:05:44 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Aug 2019 06:05:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,441,1559545200"; d="scan'208";a="197552902" Received: from deyangko-mobl.ccr.corp.intel.com ([10.249.168.35]) by fmsmga001.fm.intel.com with ESMTP; 28 Aug 2019 06:05:41 -0700 Message-ID: <961b814b345ee765408b85861ec3c37d01857c0a.camel@intel.com> Subject: Re: [PATCH] drivers: thermal: qcom: tsens: Fix memory leak from qfprom read From: Zhang Rui To: Amit Kucheria , Srinivas Kandagatla Cc: Linux PM list , Eduardo Valentin , linux-arm-msm , Linux Kernel Mailing List Date: Wed, 28 Aug 2019 21:05:51 +0800 In-Reply-To: References: <20190823093835.32655-1-srinivas.kandagatla@linaro.org> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2019-08-23 at 17:29 +0530, Amit Kucheria wrote: > On Fri, Aug 23, 2019 at 3:08 PM Srinivas Kandagatla > wrote: > > > > memory returned as part of nvmem_read via qfprom_read should be > > freed by the consumer once done. > > Existing code is not doing it so fix it. > > > > Below memory leak detected by kmemleak > > [] kmemleak_alloc+0x50/0x84 > > [] __kmalloc+0xe8/0x168 > > [] nvmem_cell_read+0x30/0x80 > > [] qfprom_read+0x4c/0x7c > > [] calibrate_v1+0x34/0x204 > > [] tsens_probe+0x164/0x258 > > [] platform_drv_probe+0x80/0xa0 > > [] really_probe+0x208/0x248 > > [] driver_probe_device+0x98/0xc0 > > [] __device_attach_driver+0x9c/0xac > > [] bus_for_each_drv+0x60/0x8c > > [] __device_attach+0x8c/0x100 > > [] device_initial_probe+0x20/0x28 > > [] bus_probe_device+0x34/0x7c > > [] deferred_probe_work_func+0x6c/0x98 > > [] process_one_work+0x160/0x2f8 > > > > Signed-off-by: Srinivas Kandagatla > > Acked-by: Amit Kucheria patch applied. thanks, rui > > > --- > > drivers/thermal/qcom/tsens-8960.c | 2 ++ > > drivers/thermal/qcom/tsens-v0_1.c | 12 ++++++++++-- > > drivers/thermal/qcom/tsens-v1.c | 1 + > > drivers/thermal/qcom/tsens.h | 1 + > > 4 files changed, 14 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/thermal/qcom/tsens-8960.c > > b/drivers/thermal/qcom/tsens-8960.c > > index 8d9b721dadb6..e46a4e3f25c4 100644 > > --- a/drivers/thermal/qcom/tsens-8960.c > > +++ b/drivers/thermal/qcom/tsens-8960.c > > @@ -229,6 +229,8 @@ static int calibrate_8960(struct tsens_priv > > *priv) > > for (i = 0; i < num_read; i++, s++) > > s->offset = data[i]; > > > > + kfree(data); > > + > > return 0; > > } > > > > diff --git a/drivers/thermal/qcom/tsens-v0_1.c > > b/drivers/thermal/qcom/tsens-v0_1.c > > index 6f26fadf4c27..055647bcee67 100644 > > --- a/drivers/thermal/qcom/tsens-v0_1.c > > +++ b/drivers/thermal/qcom/tsens-v0_1.c > > @@ -145,8 +145,10 @@ static int calibrate_8916(struct tsens_priv > > *priv) > > return PTR_ERR(qfprom_cdata); > > > > qfprom_csel = (u32 *)qfprom_read(priv->dev, "calib_sel"); > > - if (IS_ERR(qfprom_csel)) > > + if (IS_ERR(qfprom_csel)) { > > + kfree(qfprom_cdata); > > return PTR_ERR(qfprom_csel); > > + } > > > > mode = (qfprom_csel[0] & MSM8916_CAL_SEL_MASK) >> > > MSM8916_CAL_SEL_SHIFT; > > dev_dbg(priv->dev, "calibration mode is %d\n", mode); > > @@ -181,6 +183,8 @@ static int calibrate_8916(struct tsens_priv > > *priv) > > } > > > > compute_intercept_slope(priv, p1, p2, mode); > > + kfree(qfprom_cdata); > > + kfree(qfprom_csel); > > > > return 0; > > } > > @@ -198,8 +202,10 @@ static int calibrate_8974(struct tsens_priv > > *priv) > > return PTR_ERR(calib); > > > > bkp = (u32 *)qfprom_read(priv->dev, "calib_backup"); > > - if (IS_ERR(bkp)) > > + if (IS_ERR(bkp)) { > > + kfree(calib); > > return PTR_ERR(bkp); > > + } > > > > calib_redun_sel = bkp[1] & BKP_REDUN_SEL; > > calib_redun_sel >>= BKP_REDUN_SHIFT; > > @@ -313,6 +319,8 @@ static int calibrate_8974(struct tsens_priv > > *priv) > > } > > > > compute_intercept_slope(priv, p1, p2, mode); > > + kfree(calib); > > + kfree(bkp); > > > > return 0; > > } > > diff --git a/drivers/thermal/qcom/tsens-v1.c > > b/drivers/thermal/qcom/tsens-v1.c > > index 10b595d4f619..870f502f2cb6 100644 > > --- a/drivers/thermal/qcom/tsens-v1.c > > +++ b/drivers/thermal/qcom/tsens-v1.c > > @@ -138,6 +138,7 @@ static int calibrate_v1(struct tsens_priv > > *priv) > > } > > > > compute_intercept_slope(priv, p1, p2, mode); > > + kfree(qfprom_cdata); > > > > return 0; > > } > > diff --git a/drivers/thermal/qcom/tsens.h > > b/drivers/thermal/qcom/tsens.h > > index 2fd94997245b..b89083b61c38 100644 > > --- a/drivers/thermal/qcom/tsens.h > > +++ b/drivers/thermal/qcom/tsens.h > > @@ -17,6 +17,7 @@ > > > > #include > > #include > > +#include > > > > struct tsens_priv; > > > > -- > > 2.21.0 > >