linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 5.2 01/63] drivers: thermal: qcom: tsens: Fix memory leak from qfprom read
@ 2019-10-01 16:40 Sasha Levin
  2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 02/63] ima: always return negative code for error Sasha Levin
                   ` (61 more replies)
  0 siblings, 62 replies; 63+ messages in thread
From: Sasha Levin @ 2019-10-01 16:40 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Srinivas Kandagatla, Amit Kucheria, Zhang Rui, Sasha Levin,
	linux-arm-msm, linux-pm

From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>

[ 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
   [<ffffff80088b7658>] kmemleak_alloc+0x50/0x84
    [<ffffff80081df120>] __kmalloc+0xe8/0x168
    [<ffffff80086db350>] nvmem_cell_read+0x30/0x80
    [<ffffff8008632790>] qfprom_read+0x4c/0x7c
    [<ffffff80086335a4>] calibrate_v1+0x34/0x204
    [<ffffff8008632518>] tsens_probe+0x164/0x258
    [<ffffff80084e0a1c>] platform_drv_probe+0x80/0xa0
    [<ffffff80084de4f4>] really_probe+0x208/0x248
    [<ffffff80084de2c4>] driver_probe_device+0x98/0xc0
    [<ffffff80084dec54>] __device_attach_driver+0x9c/0xac
    [<ffffff80084dca74>] bus_for_each_drv+0x60/0x8c
    [<ffffff80084de634>] __device_attach+0x8c/0x100
    [<ffffff80084de6c8>] device_initial_probe+0x20/0x28
    [<ffffff80084dcbb8>] bus_probe_device+0x34/0x7c
    [<ffffff80084deb08>] deferred_probe_work_func+0x6c/0x98
    [<ffffff80080c3da8>] process_one_work+0x160/0x2f8

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Acked-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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 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 <linux/thermal.h>
 #include <linux/regmap.h>
+#include <linux/slab.h>
 
 struct tsens_priv;
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 63+ messages in thread

end of thread, other threads:[~2019-10-01 16:59 UTC | newest]

Thread overview: 63+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-01 16:40 [PATCH AUTOSEL 5.2 01/63] drivers: thermal: qcom: tsens: Fix memory leak from qfprom read Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 02/63] ima: always return negative code for error Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 03/63] ima: fix freeing ongoing ahash_request Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 04/63] fs: nfs: Fix possible null-pointer dereferences in encode_attrs() Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 05/63] xprtrdma: Send Queue size grows after a reconnect Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 06/63] 9p: Transport error uninitialized Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 07/63] 9p: avoid attaching writeback_fid on mmap with type PRIVATE Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 08/63] 9p/cache.c: Fix memory leak in v9fs_cache_session_get_cookie Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 09/63] xen/pci: reserve MCFG areas earlier Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 10/63] fuse: fix request limit Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 11/63] ceph: fix directories inode i_blkbits initialization Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 12/63] ceph: fetch cap_gen under spinlock in ceph_add_cap Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 13/63] ceph: reconnect connection if session hang in opening state Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 14/63] rbd: fix response length parameter for encoded strings Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 15/63] SUNRPC: RPC level errors should always set task->tk_rpc_status Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 16/63] watchdog: aspeed: Add support for AST2600 Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 17/63] netfilter: nf_tables: allow lookups in dynamic sets Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 18/63] drm/amdgpu: Fix KFD-related kernel oops on Hawaii Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 19/63] drm/amdgpu: Check for valid number of registers to read Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 20/63] pNFS: Ensure we do clear the return-on-close layout stateid on fatal errors Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 21/63] SUNRPC: Don't try to parse incomplete RPC messages Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 22/63] net/sched: act_sample: don't push mac header on ip6gre ingress Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 23/63] pwm: stm32-lp: Add check in case requested period cannot be achieved Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 24/63] cdc_ncm: fix divide-by-zero caused by invalid wMaxPacketSize Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 25/63] usbnet: ignore endpoints with " Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 26/63] net/phy: fix DP83865 10 Mbps HDX loopback disable function Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 27/63] net_sched: add max len check for TCA_KIND Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 28/63] x86/purgatory: Disable the stackleak GCC plugin for the purgatory Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 29/63] ntb: point to right memory window index Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 30/63] thermal: Fix use-after-free when unregistering thermal zone device Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 31/63] thermal_hwmon: Sanitize thermal_zone type Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 32/63] iommu/amd: Fix downgrading default page-sizes in alloc_pte() Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 33/63] libnvdimm/region: Initialize bad block for volatile namespaces Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 34/63] net/mlx5e: Fix traffic duplication in ethtool steering Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 35/63] KVM: hyperv: Fix Direct Synthetic timers assert an interrupt w/o lapic_in_kernel Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 36/63] libnvdimm: Fix endian conversion issues Sasha Levin
2019-10-01 16:40 ` [PATCH AUTOSEL 5.2 37/63] fuse: fix memleak in cuse_channel_open Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 38/63] arcnet: provide a buffer big enough to actually receive packets Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 39/63] libnvdimm/nfit_test: Fix acpi_handle redefinition Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 40/63] ppp: Fix memory leak in ppp_write Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 41/63] sched/membarrier: Call sync_core only before usermode for same mm Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 42/63] sched/membarrier: Fix private expedited registration check Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 43/63] sched/core: Fix migration to invalid CPU in __set_cpus_allowed_ptr() Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 44/63] perf build: Add detection of java-11-openjdk-devel package Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 45/63] include/trace/events/writeback.h: fix -Wstringop-truncation warnings Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 46/63] kernel/elfcore.c: include proper prototypes Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 47/63] kexec: bail out upon SIGKILL when allocating memory Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 48/63] blk-mq: move lockdep_assert_held() into elevator_exit Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 49/63] bpf: Fix bpf_event_output re-entry issue Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 50/63] macsec: drop skb sk before calling gro_cells_receive Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 51/63] i2c: qcom-geni: Disable DMA processing on the Lenovo Yoga C630 Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 52/63] perf unwind: Fix libunwind build failure on i386 systems Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 53/63] nfp: flower: fix memory leak in nfp_flower_spawn_vnic_reprs Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 54/63] net: phy: micrel: add Asym Pause workaround for KSZ9021 Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 55/63] mlxsw: spectrum_flower: Fail in case user specifies multiple mirror actions Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 56/63] vrf: Do not attempt to create IPv6 mcast rule if IPv6 is disabled Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 57/63] nfp: flower: prevent memory leak in nfp_flower_spawn_phy_reprs Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 58/63] nfp: abm: fix memory leak in nfp_abm_u32_knode_replace Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 59/63] fuse: fix deadlock with aio poll and fuse_iqueue::waitq.lock Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 60/63] drm/radeon: Bail earlier when radeon.cik_/si_support=0 is passed Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 61/63] usbnet: sanity checking of packet sizes and device mtu Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 62/63] sch_netem: fix a divide by zero in tabledist() Sasha Levin
2019-10-01 16:41 ` [PATCH AUTOSEL 5.2 63/63] Btrfs: fix selftests failure due to uninitialized i_mode in test inodes Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).