Skip to content

Commit 812fcc6

Browse files
awilliamjwrdegoede
authored andcommitted
platform/x86: think-lmi: Abort probe on analyze failure
A Lenovo ThinkStation S20 (4157CTO BIOS 60KT41AUS) fails to boot on recent kernels including the think-lmi driver, due to the fact that errors returned by the tlmi_analyze() function are ignored by tlmi_probe(), where tlmi_sysfs_init() is called unconditionally. This results in making use of an array of already freed, non-null pointers and other uninitialized globals, causing all sorts of nasty kobject and memory faults. Make use of the analyze function return value, free a couple leaked allocations, and remove the settings_count field, which is incremented but never consumed. Fixes: a40cd7e ("platform/x86: think-lmi: Add WMI interface support on Lenovo platforms") Signed-off-by: Alex Williamson <[email protected]> Reviewed-by: Mark Gross <[email protected]> Reviewed-by: Mark Pearson <[email protected]> Link: https://lore.kernel.org/r/163639463588.1330483.15850167112490200219.stgit@omen Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Hans de Goede <[email protected]>
1 parent 0f07c02 commit 812fcc6

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

drivers/platform/x86/think-lmi.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -888,8 +888,10 @@ static int tlmi_analyze(void)
888888
break;
889889
if (!item)
890890
break;
891-
if (!*item)
891+
if (!*item) {
892+
kfree(item);
892893
continue;
894+
}
893895

894896
/* It is not allowed to have '/' for file name. Convert it into '\'. */
895897
strreplace(item, '/', '\\');
@@ -902,6 +904,7 @@ static int tlmi_analyze(void)
902904
setting = kzalloc(sizeof(*setting), GFP_KERNEL);
903905
if (!setting) {
904906
ret = -ENOMEM;
907+
kfree(item);
905908
goto fail_clear_attr;
906909
}
907910
setting->index = i;
@@ -916,7 +919,6 @@ static int tlmi_analyze(void)
916919
}
917920
kobject_init(&setting->kobj, &tlmi_attr_setting_ktype);
918921
tlmi_priv.setting[i] = setting;
919-
tlmi_priv.settings_count++;
920922
kfree(item);
921923
}
922924

@@ -983,7 +985,12 @@ static void tlmi_remove(struct wmi_device *wdev)
983985

984986
static int tlmi_probe(struct wmi_device *wdev, const void *context)
985987
{
986-
tlmi_analyze();
988+
int ret;
989+
990+
ret = tlmi_analyze();
991+
if (ret)
992+
return ret;
993+
987994
return tlmi_sysfs_init();
988995
}
989996

drivers/platform/x86/think-lmi.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ struct tlmi_attr_setting {
5555
struct think_lmi {
5656
struct wmi_device *wmi_device;
5757

58-
int settings_count;
5958
bool can_set_bios_settings;
6059
bool can_get_bios_selections;
6160
bool can_set_bios_password;

0 commit comments

Comments
 (0)