From patchwork Fri Aug 23 09:38:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 172098 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp398239ily; Fri, 23 Aug 2019 02:38:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxaXnYvsdCEs9Sd6eLC3758v5SofsGuegrt+z2y3d9V+IUBScMl/vqJXCZV/WwQUX2cipS7 X-Received: by 2002:a63:7887:: with SMTP id t129mr3136157pgc.309.1566553123219; Fri, 23 Aug 2019 02:38:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566553123; cv=none; d=google.com; s=arc-20160816; b=tr5U3zIp6mHYav7oMd9n9d+HXDSD4WLWT9dRpfHGs7iUiXpE/sT32QfJQYjGcz2BCp +4LcKDiNtz6DbaplY9RAneQBpdpdZVUQEVSP2rg5a7zmzrE42Ne2N6+QdegmdjWG8xei dDN7xP3cskJraPJaTMOp/SpPQ/o3IFB/xRg7l8TWCEKaV3Ct/2j2QIfpug2z5Sb4Ojpr Hv3Iv2TTdYMoaPLyk88PTLoGD2aBm3pvzzWNAiD3tqb/iSi7IAA1xRN2C5enzQcJ/ITW vXz3L51E4zuXid7N8VBsYh/2/Lyt4wi559ylZlGM4nRMPzFPPe9W9W2I5orsdvhuxOOb ovvg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=kSm+naO1TQ4hxm8sdmnltc6wBBt1pT3kTvijAemrFOg=; b=qeNh++LaxwrZ3x0jrKS4CBwhMS4kWBTabb2/PAomBFOfkkCfdHOMmuSGhhvvupJTxJ hemceJy406oYJm/OVvAwI2kVBeb/YUyTOMXx8FStjRKirztN5TrUDkpCWdGJSWMIygo8 xik1O7aTrJR6BD8XoQlRjhGzBB82DKk5uEMPyd/KXFINRCpIoiDb3+mTKiZ1S2KJDd0p /50x1AdjYBnyB5KS8FyHqe246b4LGSwTJ6IU/m2C+eRwXN1LO6/UHYr8WPhTaeq7ndYX Qw5CENM8ZdsMjve1xt5eqVHqikOBA9VN7gut1STzb9Jn4bLTxucA4hmDvGDnE6y9+tw7 DeuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CqaEWp9v; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o7si1501835pgi.127.2019.08.23.02.38.42; Fri, 23 Aug 2019 02:38:43 -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; dkim=pass header.i=@linaro.org header.s=google header.b=CqaEWp9v; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387589AbfHWJil (ORCPT + 28 others); Fri, 23 Aug 2019 05:38:41 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:54179 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731845AbfHWJik (ORCPT ); Fri, 23 Aug 2019 05:38:40 -0400 Received: by mail-wm1-f67.google.com with SMTP id 10so8283569wmp.3 for ; Fri, 23 Aug 2019 02:38:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=kSm+naO1TQ4hxm8sdmnltc6wBBt1pT3kTvijAemrFOg=; b=CqaEWp9vXrcgx71U1LQb55TsRuPNoG8rmkrXQ8X5sHwFcnSxPwoCg9lXBaaH+0tw1k CMM5rb4PA5nwWraz+RDI8T+eL8eVbVFoz6ZJW9jJ1fhrKZN5/WGWyqN3KC+QUX6gdLw4 5Faavj9nT61sdyvb/advtCjwLry7p0AWI7h2lKC1ikUL5qxJN5SelVmUoJObBqXaLYD+ 0hST1EHHus44eznVF5mxXoXJedZTIfIYEznEfpzXRbax+8iBBHZCm6KgsZYGYcKjjTCr uWH4Yv12Q/bOO3a7oVsdZNAdfKoU31sQ/u4jok0rFFoEdGIqejk6bmD495hdxFC9XnyV nWzw== 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:mime-version :content-transfer-encoding; bh=kSm+naO1TQ4hxm8sdmnltc6wBBt1pT3kTvijAemrFOg=; b=QjNwvH4hazJCkYcnHWs0xc75Ai+FUXUh3utcO1T0c1PKI13MABc+7NVmOjep8bhl4X AcZdEU5EcEf/5UKauK9u8BIasy6wMixz4OH6OA6ln9X7QE/Ii0b+NGuhtoTNmtIz7iyU 3OosSPJxTssy4QXYK8Dj1bo/O+CrfHe+cwhIA8u02fsKat9iwMhC8ObfsRwIzzeGUCTV 5t5eshlyzKxX8fQDjWrcMHdTsuqCnM7r4HrJZXKHEr/1iYb9mzkcjhUlhb8teujNTGtw /3VNFlzj6Sf3WNVQH0Vk+HcV3f4sb0lDUw0x6NKMIbp2rctsumlg297YDByC/JGUbCNG DR5g== X-Gm-Message-State: APjAAAUXyDC8VllAJ7do66r9B6O10ZO8k+8M5yIt1KajqnPeGsUO9PnK puH9j5z/h7EjPskCksfGsAeykw== X-Received: by 2002:a1c:721a:: with SMTP id n26mr3984740wmc.88.1566553118783; Fri, 23 Aug 2019 02:38:38 -0700 (PDT) Received: from srini-hackbox.lan (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.gmail.com with ESMTPSA id s64sm2860089wmf.16.2019.08.23.02.38.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2019 02:38:37 -0700 (PDT) From: Srinivas Kandagatla To: amit.kucheria@linaro.org, linux-pm@vger.kernel.org, edubezval@gmail.com Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH] drivers: thermal: qcom: tsens: Fix memory leak from qfprom read Date: Fri, 23 Aug 2019 10:38:35 +0100 Message-Id: <20190823093835.32655-1-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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(-) -- 2.21.0 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;