mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] platform/x86/intel/tpmi: Fix memory leak in mem_write() error path
@ 2026-05-19  8:21 ZhaoJinming
  2026-05-19 14:32 ` Ilpo Järvinen
  2026-05-19 16:35 ` [PATCH] platform/x86/intel/tpmi: Fix memory leak in mem_write() error path srinivas pandruvada
  0 siblings, 2 replies; 14+ messages in thread
From: ZhaoJinming @ 2026-05-19  8:21 UTC (permalink / raw)
  To: srinivas.pandruvada, hansg, ilpo.jarvinen
  Cc: platform-driver-x86, linux-kernel, ZhaoJinming, stable

In mem_write(), when the IS_ALIGNED() check fails, the function returns
-EINVAL directly without freeing the 'array' allocated by
parse_int_array_user(). This causes a memory leak.

Other error paths in the same function correctly use 'goto exit_write'
to free the array before returning. Fix this inconsistency by using
the same pattern for the alignment check.

Fixes: 8e0a2fc68ec3 ("platform/x86/intel/tpmi: Use 32 bit aligned address for debugfs mem write")
Cc: stable@vger.kernel.org
Signed-off-by: ZhaoJinming <zhaojinming@uniontech.com>
---
 drivers/platform/x86/intel/vsec_tpmi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/intel/vsec_tpmi.c b/drivers/platform/x86/intel/vsec_tpmi.c
index 16fd7aa41f20..2a428bfcb209 100644
--- a/drivers/platform/x86/intel/vsec_tpmi.c
+++ b/drivers/platform/x86/intel/vsec_tpmi.c
@@ -495,8 +495,10 @@ static ssize_t mem_write(struct file *file, const char __user *userbuf, size_t l
 	addr = array[2];
 	value = array[3];
 
-	if (!IS_ALIGNED(addr, sizeof(u32)))
-		return -EINVAL;
+	if (!IS_ALIGNED(addr, sizeof(u32))) {
+		ret = -EINVAL;
+		goto exit_write;
+	}
 
 	if (punit >= pfs->pfs_header.num_entries) {
 		ret = -EINVAL;
-- 
2.20.1


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

end of thread, other threads:[~2026-05-21 13:13 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-19  8:21 [PATCH] platform/x86/intel/tpmi: Fix memory leak in mem_write() error path ZhaoJinming
2026-05-19 14:32 ` Ilpo Järvinen
2026-05-20  5:41   ` ZhaoJinming
2026-05-20  5:41     ` [PATCH 1/2] platform/x86/intel/tpmi: use cleanup helpers in mem_write() ZhaoJinming
2026-05-20 10:37       ` Ilpo Järvinen
2026-05-21  3:56         ` [PATCH] platform/x86/intel/tpmi: Fix memory leak in mem_write() error path ZhaoJinming
2026-05-21  3:56           ` [PATCH 1/2] platform/x86/intel/tpmi: use cleanup helpers in mem_write() ZhaoJinming
2026-05-21 12:58             ` Ilpo Järvinen
2026-05-21 13:13               ` 赵金明
2026-05-21  3:56           ` [PATCH 2/2] platform/x86/intel/tpmi: convert mutex in mem_write() to guard ZhaoJinming
2026-05-20  5:41     ` [PATCH 2/2] platform/x86/intel/tpmi: convert mutex lock/unlock " ZhaoJinming
2026-05-20  5:54   ` [PATCH 1/2] platform/x86/intel/tpmi: use cleanup helpers in mem_write() ZhaoJinming
2026-05-20  5:54     ` [PATCH 2/2] platform/x86/intel/tpmi: convert mutex lock/unlock in mem_write() to guard ZhaoJinming
2026-05-19 16:35 ` [PATCH] platform/x86/intel/tpmi: Fix memory leak in mem_write() error path srinivas pandruvada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox