mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 1/2] platform/x86/intel/tpmi: use cleanup helpers in mem_write()
Date: Thu, 21 May 2026 15:58:48 +0300 (EEST)	[thread overview]
Message-ID: <35a143db-461b-7d2a-2641-4d526bcb4af4@linux.intel.com> (raw)
In-Reply-To: <20260521035623.1426374-2-zhaojinming@uniontech.com>

On Thu, 21 May 2026, ZhaoJinming wrote:

> In mem_write(), the temporary array returned by
> parse_int_array_user() must be released on all exit paths.
> Convert the array variable to use cleanup.h scope-based
> cleanup so it is freed automatically on return.
> 
> This also moves the array declaration next to
> parse_int_array_user() as required by cleanup.h usage
> guidelines.

Now you made these much shorter than 72 chars. :-(

> 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 | 25 +++++++++----------------
>  1 file changed, 9 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/platform/x86/intel/vsec_tpmi.c b/drivers/platform/x86/intel/vsec_tpmi.c
> index 16fd7aa41f20..88f14d0ad410 100644
> --- a/drivers/platform/x86/intel/vsec_tpmi.c
> +++ b/drivers/platform/x86/intel/vsec_tpmi.c
> @@ -50,6 +50,7 @@
>  #include <linux/auxiliary_bus.h>
>  #include <linux/bitfield.h>
>  #include <linux/debugfs.h>
> +#include <linux/cleanup.h>
>  #include <linux/delay.h>
>  #include <linux/intel_tpmi.h>
>  #include <linux/intel_vsec.h>
> @@ -473,7 +474,7 @@ static ssize_t mem_write(struct file *file, const char __user *userbuf, size_t l
>  	struct seq_file *m = file->private_data;
>  	struct intel_tpmi_pm_feature *pfs = m->private;
>  	u32 addr, value, punit, size;
> -	u32 num_elems, *array;
> +	u32 num_elems;
>  	void __iomem *mem;
>  	int ret;
>  
> @@ -481,15 +482,14 @@ static ssize_t mem_write(struct file *file, const char __user *userbuf, size_t l
>  	if (!size)
>  		return -EIO;
>  
> +	u32 *array __free(kfree) = NULL;
>  	ret = parse_int_array_user(userbuf, len, (int **)&array);
>  	if (ret < 0)
>  		return ret;
>  
>  	num_elems = *array;
> -	if (num_elems != 3) {
> -		ret = -EINVAL;
> -		goto exit_write;
> -	}
> +	if (num_elems != 3)
> +		return -EINVAL;
>  
>  	punit = array[1];
>  	addr = array[2];
> @@ -498,15 +498,11 @@ static ssize_t mem_write(struct file *file, const char __user *userbuf, size_t l
>  	if (!IS_ALIGNED(addr, sizeof(u32)))
>  		return -EINVAL;
>  
> -	if (punit >= pfs->pfs_header.num_entries) {
> -		ret = -EINVAL;
> -		goto exit_write;
> -	}
> +	if (punit >= pfs->pfs_header.num_entries)
> +		return -EINVAL;
>  
> -	if (addr >= size) {
> -		ret = -EINVAL;
> -		goto exit_write;
> -	}
> +	if (addr >= size)
> +		return -EINVAL;
>  
>  	mutex_lock(&tpmi_dev_lock);
>  
> @@ -525,9 +521,6 @@ static ssize_t mem_write(struct file *file, const char __user *userbuf, size_t l
>  unlock_mem_write:
>  	mutex_unlock(&tpmi_dev_lock);
>  
> -exit_write:
> -	kfree(array);
> -
>  	return ret;
>  }
>  
> 

The code change looks okay now.

BUT, please send the next version properly versioned (it "v4" or so in 
it's subject, I think) and in a fresh thread. As is, b4 gets confused 
which patches are the latest version so I cannot apply these with my 
maintainer tools.

-- 
 i.


  reply	other threads:[~2026-05-21 12:58 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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=35a143db-461b-7d2a-2641-4d526bcb4af4@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

Powered by JetHome