summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorArmin Wolf <W_Armin@gmx.de>2023-04-01 00:33:19 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-04-13 17:55:22 +0300
commit9071525bfcb1f5674117dbed3eca0cd7b122813b (patch)
tree86fae1678cafb541a4d566f537aa6b29beaf377a /drivers
parent2c9cefc142c1dc2759e19a92d3b2b3715e985beb (diff)
downloadlinux-9071525bfcb1f5674117dbed3eca0cd7b122813b.tar.xz
platform/x86: think-lmi: Fix memory leak when showing current settings
[ Upstream commit a3c4c053014585dcf20f4df954791b74d8a8afcd ] 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. Reported-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr> Link: https://lore.kernel.org/platform-driver-x86/01e920bc-5882-ba0c-dd15-868bf0eca0b8@alu.unizg.hr/T/#t Tested-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr> Fixes: 0fdf10e5fc96 ("platform/x86: think-lmi: Split current_value to reflect only the value") Signed-off-by: Armin Wolf <W_Armin@gmx.de> Link: https://lore.kernel.org/r/20230331213319.41040-1-W_Armin@gmx.de Tested-by: Mario Limonciello <mario.limonciello@amd.com> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/platform/x86/think-lmi.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
index 74af3e593b2c..4e738ec5e6fb 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;
}