From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: ZhaoJinming <zhaojinming@uniontech.com>
Cc: srinivas.pandruvada@linux.intel.com,
Hans de Goede <hansg@kernel.org>,
platform-driver-x86@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>,
stable@vger.kernel.org
Subject: Re: [PATCH] platform/x86/intel/tpmi: Fix memory leak in mem_write() error path
Date: Tue, 19 May 2026 17:32:19 +0300 (EEST) [thread overview]
Message-ID: <b1006ce4-f596-b2aa-421a-518fe3cfe1f0@linux.intel.com> (raw)
In-Reply-To: <20260519082136.2999917-1-zhaojinming@uniontech.com>
On Tue, 19 May 2026, ZhaoJinming wrote:
> 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;
Hi,
Thanks for finding this problem. This function looks a prime candidate for
cleanup.h conversion.
Please do this with a 2 patch series. The first patch converts kfree() to
__free() and moves array declaration next to parse_int_array_user() (as
instructed by the long comment in cleanup.h) and has fixes tag. The second
patch should converyt the mutex lock/unlock to guard and doesn't need
fixes tag. This way, we get rid of all gotos here.
--
i.
next prev parent reply other threads:[~2026-05-19 14:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-19 8:21 ZhaoJinming
2026-05-19 14:32 ` Ilpo Järvinen [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b1006ce4-f596-b2aa-421a-518fe3cfe1f0@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=hansg@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
--cc=srinivas.pandruvada@linux.intel.com \
--cc=stable@vger.kernel.org \
--cc=zhaojinming@uniontech.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox