* [PATCH 1/2] platform/x86: think-lmi: Fix memory leaks when parsing ThinkStation WMI strings
@ 2023-04-01 18:43 Mark Pearson
2023-04-01 18:43 ` [PATCH 2/2] platform/x86: think-lmi: Clean up display of current_value on Thinkstation Mark Pearson
2023-04-02 14:04 ` [PATCH 1/2] platform/x86: think-lmi: Fix memory leaks when parsing ThinkStation WMI strings Mario Limonciello
0 siblings, 2 replies; 6+ messages in thread
From: Mark Pearson @ 2023-04-01 18:43 UTC (permalink / raw)
To: mpearson-lenovo
Cc: hdegoede, markgross, W_Armin, mirsad.todorovac, linux,
Mario.Limonciello, platform-driver-x86, linux-kernel
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@alu.unizg.hr>
Link: https://lore.kernel.org/lkml/df26ff45-8933-f2b3-25f4-6ee51ccda7d8@gmx.de/T/
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
This patch series builds on top of the proposed patch from Armin Wolf
"platform/x86: think-lmi: Fix memory leak when showing current settings"
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);
}
}
/*
--
2.39.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] platform/x86: think-lmi: Clean up display of current_value on Thinkstation
2023-04-01 18:43 [PATCH 1/2] platform/x86: think-lmi: Fix memory leaks when parsing ThinkStation WMI strings Mark Pearson
@ 2023-04-01 18:43 ` Mark Pearson
2023-04-02 14:04 ` [PATCH 1/2] platform/x86: think-lmi: Fix memory leaks when parsing ThinkStation WMI strings Mario Limonciello
1 sibling, 0 replies; 6+ messages in thread
From: Mark Pearson @ 2023-04-01 18:43 UTC (permalink / raw)
To: mpearson-lenovo
Cc: hdegoede, markgross, W_Armin, mirsad.todorovac, linux,
Mario.Limonciello, platform-driver-x86, linux-kernel
On ThinkStations on retrieving the attribute value the BIOS appends the
possible values to the string.
Clean up the display in the current_value_show function so the options
part is not displayed.
Fixes: a40cd7ef22fb ("platform/x86: think-lmi: Add WMI interface support on Lenovo platforms")
Reported by Mario Limoncello <Mario.Limonciello@amd.com>
Link: https://github.com/fwupd/fwupd/issues/5077#issuecomment-1488730526
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/think-lmi.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
index ad952b49617b..29e94db03238 100644
--- a/drivers/platform/x86/think-lmi.c
+++ b/drivers/platform/x86/think-lmi.c
@@ -920,7 +920,7 @@ static ssize_t display_name_show(struct kobject *kobj, struct kobj_attribute *at
static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
- char *item, *value;
+ char *item, *value, *p;
int ret;
ret = tlmi_setting(setting->index, &item, LENOVO_BIOS_SETTING_GUID);
@@ -931,11 +931,13 @@ static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *a
value = strpbrk(item, ",");
if (!value || value == item || !strlen(value + 1))
ret = -EINVAL;
- else
- ret = sysfs_emit(buf, "%s\n", value + 1);
-
+ else {
+ /* On Workstations remove the Options part after the value */
+ p = strchrnul(value, ';');
+ *p = '\0';
+ ret = sysfs_emit(buf, "%s\n", value + 1);
+ }
kfree(item);
-
return ret;
}
--
2.39.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] platform/x86: think-lmi: Fix memory leaks when parsing ThinkStation WMI strings
2023-04-01 18:43 [PATCH 1/2] platform/x86: think-lmi: Fix memory leaks when parsing ThinkStation WMI strings Mark Pearson
2023-04-01 18:43 ` [PATCH 2/2] platform/x86: think-lmi: Clean up display of current_value on Thinkstation Mark Pearson
@ 2023-04-02 14:04 ` Mario Limonciello
2023-04-02 19:23 ` Mark Pearson
1 sibling, 1 reply; 6+ messages in thread
From: Mario Limonciello @ 2023-04-02 14:04 UTC (permalink / raw)
To: Mark Pearson
Cc: hdegoede, markgross, W_Armin, mirsad.todorovac, linux,
platform-driver-x86, linux-kernel
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@alu.unizg.hr>
> Link: https://lore.kernel.org/lkml/df26ff45-8933-f2b3-25f4-6ee51ccda7d8@gmx.de/T/
> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> ---
> 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);
> }
> }
> /*
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] platform/x86: think-lmi: Fix memory leaks when parsing ThinkStation WMI strings
2023-04-02 14:04 ` [PATCH 1/2] platform/x86: think-lmi: Fix memory leaks when parsing ThinkStation WMI strings Mario Limonciello
@ 2023-04-02 19:23 ` Mark Pearson
2023-04-02 22:17 ` Limonciello, Mario
0 siblings, 1 reply; 6+ messages in thread
From: Mark Pearson @ 2023-04-02 19:23 UTC (permalink / raw)
To: Limonciello, Mario
Cc: Hans de Goede, markgross, Armin Wolf, Mirsad Goran Todorovac,
Thomas Weißschuh, platform-driver-x86, linux-kernel
Hi Mario
On Sun, Apr 2, 2023, at 10:04 AM, Mario Limonciello wrote:
> 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@alu.unizg.hr>
>> Link: https://lore.kernel.org/lkml/df26ff45-8933-f2b3-25f4-6ee51ccda7d8@gmx.de/T/
>> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>> ---
>> 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).
I was using v2 - but there shouldn't be any code changes between v3 and v2....so I hadn't re-based.
I'm working in the fixes branch from pdx86.git (with the aim of making it easier for Hans to pull in the patches). It's possible I've goofed somehow...though not sure how :(
I'll go double check - but likely won't be until tomorrow I'm afraid. I should probably just wait for the patch to be accepted and then work from there....
Mark
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] platform/x86: think-lmi: Fix memory leaks when parsing ThinkStation WMI strings
2023-04-02 19:23 ` Mark Pearson
@ 2023-04-02 22:17 ` Limonciello, Mario
2023-04-03 0:38 ` Mark Pearson
0 siblings, 1 reply; 6+ messages in thread
From: Limonciello, Mario @ 2023-04-02 22:17 UTC (permalink / raw)
To: Mark Pearson
Cc: Hans de Goede, markgross, Armin Wolf, Mirsad Goran Todorovac,
Thomas Weißschuh, platform-driver-x86, linux-kernel
On 4/2/2023 14:23, Mark Pearson wrote:
> Hi Mario
>
> On Sun, Apr 2, 2023, at 10:04 AM, Mario Limonciello wrote:
>> 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@alu.unizg.hr>
>>> Link: https://lore.kernel.org/lkml/df26ff45-8933-f2b3-25f4-6ee51ccda7d8@gmx.de/T/
>>> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>>> ---
>>> 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).
>
> I was using v2 - but there shouldn't be any code changes between v3 and v2....so I hadn't re-based.
>
> I'm working in the fixes branch from pdx86.git (with the aim of making it easier for Hans to pull in the patches). It's possible I've goofed somehow...though not sure how :(
>
> I'll go double check - but likely won't be until tomorrow I'm afraid. I should probably just wait for the patch to be accepted and then work from there....
>
> Mark
Hmm, I just tried on platform-x86/for-next.
commit e3271a5917d1501089b1a224d702aa053e2877f4 (tag:
platform-drivers-x86-v6.3-4, platform-x86/fixes)
I get the same problem there. I just applied Armin's single v3 patch
and then tried your series.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] platform/x86: think-lmi: Fix memory leaks when parsing ThinkStation WMI strings
2023-04-02 22:17 ` Limonciello, Mario
@ 2023-04-03 0:38 ` Mark Pearson
0 siblings, 0 replies; 6+ messages in thread
From: Mark Pearson @ 2023-04-03 0:38 UTC (permalink / raw)
To: Limonciello, Mario
Cc: Hans de Goede, markgross, Armin Wolf, Mirsad Goran Todorovac,
Thomas Weißschuh, platform-driver-x86, linux-kernel
On Sun, Apr 2, 2023, at 6:17 PM, Limonciello, Mario wrote:
> On 4/2/2023 14:23, Mark Pearson wrote:
>> Hi Mario
>>
>> On Sun, Apr 2, 2023, at 10:04 AM, Mario Limonciello wrote:
>>> 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@alu.unizg.hr>
>>>> Link: https://lore.kernel.org/lkml/df26ff45-8933-f2b3-25f4-6ee51ccda7d8@gmx.de/T/
>>>> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>>>> ---
>>>> 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).
>>
>> I was using v2 - but there shouldn't be any code changes between v3 and v2....so I hadn't re-based.
>>
>> I'm working in the fixes branch from pdx86.git (with the aim of making it easier for Hans to pull in the patches). It's possible I've goofed somehow...though not sure how :(
>>
>> I'll go double check - but likely won't be until tomorrow I'm afraid. I should probably just wait for the patch to be accepted and then work from there....
>>
>> Mark
>
> Hmm, I just tried on platform-x86/for-next.
> commit e3271a5917d1501089b1a224d702aa053e2877f4 (tag:
> platform-drivers-x86-v6.3-4, platform-x86/fixes)
>
> I get the same problem there. I just applied Armin's single v3 patch
> and then tried your series.
You're absolutely right...it doesn't apply if I start again from clean.
I have no idea why - it must have been something I did when applying the patch in the first place but I'm at a loss as to what. Urgh :(
I'm regenerating the patch and will resend as a v2. Just going to run some tests as a sanity check first.
Mark
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-04-03 0:39 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-01 18:43 [PATCH 1/2] platform/x86: think-lmi: Fix memory leaks when parsing ThinkStation WMI strings Mark Pearson
2023-04-01 18:43 ` [PATCH 2/2] platform/x86: think-lmi: Clean up display of current_value on Thinkstation Mark Pearson
2023-04-02 14:04 ` [PATCH 1/2] platform/x86: think-lmi: Fix memory leaks when parsing ThinkStation WMI strings Mario Limonciello
2023-04-02 19:23 ` Mark Pearson
2023-04-02 22:17 ` Limonciello, Mario
2023-04-03 0:38 ` Mark Pearson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).