Re: [PATCH 1/2] platform/x86: think-lmi: Fix memory leaks when parsing ThinkStation WMI strings

From: Mario Limonciello
Date: Sun Apr 02 2023 - 10:04:40 EST


On 4/1/23 13:43, Mark Pearson wrote:

My previous commit introduced a memory leak where the item allocated
from tlmi_setting was not freed.
This commit also renames it to avoid confusion with the similarly name
variable in the same function.

Fixes: 8a02d70679fc ("platform/x86: think-lmi: Add possible_values for ThinkStation")
Reported-by: Mirsad Todorovac <mirsad.todorovac@xxxxxxxxxxxx>
Link: https://lore.kernel.org/lkml/df26ff45-8933-f2b3-25f4-6ee51ccda7d8@xxxxxx/T/
Signed-off-by: Mark Pearson <mpearson-lenovo@xxxxxxxxx>
---
This patch series builds on top of the proposed patch from Armin Wolf
"platform/x86: think-lmi: Fix memory leak when showing current settings"

Which version of the patch did you do it from?  I tried to apply v3 of Armin's patch
to Linus' tree and then apply these two.

The first applied, but the second had conflicts.  Here was my base (with patch 1 in
this series applied).

50c77e3211d7 (HEAD -> master) platform/x86: think-lmi: Fix memory leaks when parsing ThinkStation WMI strings
ede629af1e2c platform/x86: think-lmi: Fix memory leak when showing current settings
00c7b5f4ddc5 (origin/master, origin/HEAD) Merge tag 'input-for-v6.3-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input

......

Applying: platform/x86: think-lmi: Clean up display of current_value on Thinkstation
error: patch failed: drivers/platform/x86/think-lmi.c:931
error: drivers/platform/x86/think-lmi.c: patch does not apply

drivers/platform/x86/think-lmi.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
index 88da7bcb6ce9..ad952b49617b 100644
--- a/drivers/platform/x86/think-lmi.c
+++ b/drivers/platform/x86/think-lmi.c
@@ -1459,10 +1459,10 @@ static int tlmi_analyze(void)
* name string.
* Try and pull that out if it's available.
*/
- char *item, *optstart, *optend;
+ char *optitem, *optstart, *optend;
- if (!tlmi_setting(setting->index, &item, LENOVO_BIOS_SETTING_GUID)) {
- optstart = strstr(item, "[Optional:");
+ if (!tlmi_setting(setting->index, &optitem, LENOVO_BIOS_SETTING_GUID)) {
+ optstart = strstr(optitem, "[Optional:");
if (optstart) {
optstart += strlen("[Optional:");
optend = strstr(optstart, "]");
@@ -1471,6 +1471,7 @@ static int tlmi_analyze(void)
kstrndup(optstart, optend - optstart,
GFP_KERNEL);
}
+ kfree(optitem);
}
}
/*