mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 01:55:51 +02:00
platform/x86/intel/tpmi: use cleanup helpers in mem_write()
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.
Fixes: 8e0a2fc68e ("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>
Link: https://patch.msgid.link/20260521130848.2860219-1-zhaojinming@uniontech.com
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
This commit is contained in:
parent
0b6573e23a
commit
a221557958
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user