From patchwork Thu Oct 10 08:35:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 175714 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1978711ill; Thu, 10 Oct 2019 01:43:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVM3f89V279P7QeP+ECCRM0hOys1GjjWAdHowpJrNzwnCxoIU3zIqVN7RgQG2tGM8N6ves X-Received: by 2002:a17:906:af8e:: with SMTP id mj14mr7199031ejb.45.1570697011239; Thu, 10 Oct 2019 01:43:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570697011; cv=none; d=google.com; s=arc-20160816; b=wmQDynnn1o97Fp07+IwOc9FWCdgHtNySaS1tHzXAVpf/EOsiod2F/prhmS6c1liV/c oetZ70KsdmijbQKHtcZtqMsQnQxNlKzOfG1x4NBFAUO7TlMzlfWHCUbErN/MtBm35+ch 8C3hN1tu8tttDPUro92cU0n+Q/pt/wR7rYOwh1/WVajU4TyJCuJ3TeV/a+48z10ACpRP tEFDsYRtjP3a8Bje3KtmB/AThZg/5Ok3+2TTrNROF0Ferdy34D1dFJfu72LSSY8Zg9w3 7Bk8R4bp5Q21GJBsTzAkUDbNvg4bMkGfgYbGI6bkZl7oCqkwhLmXCvWPpsmWyZEslPW9 98vw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AaDFtTKEn/rBJ83PgiKyNFFIys0nJ0TrsD77J2is9vI=; b=tafuuya8Y7B5FNciiHd0DLBox9e/f8bg7HAjw+/LufiYQwv9Qe4YwGIJ3UGujFSbxS QX0R6Ppnc+FlcJWjHEViPMPaN7n84X33BS370N/y8knhnNM2ZGyVUQBT2g0WxDJfl1M5 KGUoL0tJoQaZxiHsuJSypnRB551J6abntmq3PDwP4mbayqAPOUa2OLTonwassFXOdi5U sFzpQ+hWpT3swNOBhyW8mGpRRqsQCWmW1tY9mJJzNqSDs20/pPw4dbRHoACEyHySMjXm MDjkr0ajD4RSHZpF/+HqmN0tl3o/o7v92HcSWvYM+b69xURdcjJgn5w7xzkBwhAX538A NM+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oYzKSRa3; 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 u8si3234134edb.57.2019.10.10.01.43.31; Thu, 10 Oct 2019 01:43:31 -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=@kernel.org header.s=default header.b=oYzKSRa3; 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 S2388740AbfJJIn2 (ORCPT + 26 others); Thu, 10 Oct 2019 04:43:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:48242 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388001AbfJJIn0 (ORCPT ); Thu, 10 Oct 2019 04:43:26 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3DF602190F; Thu, 10 Oct 2019 08:43:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570697004; bh=sdWjKc7950Ix1oAlzn3Bdm8pbL63ww+3W/0cLP/FqRI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oYzKSRa3MMRLJgHq8dHKJ9HOypNhv8l8D9tuAfET54JVsR5NeVcsCIwzsH5Vtqby8 3Run2qM0p3qYF8x3QrlwPDmJfwUFyD8OO25fOrnR2lxerQmoZW0iK1/9wmEAND0on1 MR2UrSuZbincpYMyRkujTs9Hor43oxf8izOi8ct0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Srinivas Kandagatla , Amit Kucheria , Zhang Rui , Sasha Levin Subject: [PATCH 5.3 088/148] drivers: thermal: qcom: tsens: Fix memory leak from qfprom read Date: Thu, 10 Oct 2019 10:35:49 +0200 Message-Id: <20191010083616.685532154@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010083609.660878383@linuxfoundation.org> References: <20191010083609.660878383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Srinivas Kandagatla [ Upstream commit 6b8249abb093551ef173d13a25ed0044d5dd33e0 ] 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 Signed-off-by: Zhang Rui Signed-off-by: Sasha Levin --- 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.20.1 diff --git a/drivers/thermal/qcom/tsens-8960.c b/drivers/thermal/qcom/tsens-8960.c index 8d9b721dadb65..e46a4e3f25c42 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 6f26fadf4c279..055647bcee67d 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 10b595d4f6199..870f502f2cb6c 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 2fd94997245bf..b89083b61c383 100644 --- a/drivers/thermal/qcom/tsens.h +++ b/drivers/thermal/qcom/tsens.h @@ -17,6 +17,7 @@ #include #include +#include struct tsens_priv;