[PATCH] platform/x86: think-lmi: Fix memory leak when showing current settings

From: Armin Wolf
Date: Fri Mar 31 2023 - 14:03:37 EST


When retriving a item string with tlmi_setting(), the result has to be
freed using kfree(). In current_value_show() however, malformed
item strings are not freed, causing a memory leak.
Fix this by eliminating the early return responsible for this.

Fixes: a40cd7ef22fb ("platform/x86: think-lmi: Add WMI interface support on Lenovo platforms")
Signed-off-by: Armin Wolf <W_Armin@xxxxxx>
---
drivers/platform/x86/think-lmi.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
index cc66f7cbccf2..8cafb9d4016c 100644
--- a/drivers/platform/x86/think-lmi.c
+++ b/drivers/platform/x86/think-lmi.c
@@ -930,10 +930,12 @@ static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *a
/* validate and split from `item,value` -> `value` */
value = strpbrk(item, ",");
if (!value || value == item || !strlen(value + 1))
- return -EINVAL;
+ ret = -EINVAL;
+ else
+ ret = sysfs_emit(buf, "%s\n", value + 1);

- ret = sysfs_emit(buf, "%s\n", value + 1);
kfree(item);
+
return ret;
}

--
2.30.2