Skip to content

Commit

Permalink
platform/x86: think-lmi: Abort probe on analyze failure
Browse files Browse the repository at this point in the history
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 <alex.williamson@redhat.com>
Reviewed-by: Mark Gross <markgross@kernel.org>
Reviewed-by: Mark Pearson <markpearson@lenovo.com>
Link: https://lore.kernel.org/r/163639463588.1330483.15850167112490200219.stgit@omen
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  • Loading branch information
Alex Williamson authored and Hans de Goede committed Nov 16, 2021
1 parent 0f07c02 commit 812fcc6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
13 changes: 10 additions & 3 deletions drivers/platform/x86/think-lmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -888,8 +888,10 @@ static int tlmi_analyze(void)
break;
if (!item)
break;
if (!*item)
if (!*item) {
kfree(item);
continue;
}

/* It is not allowed to have '/' for file name. Convert it into '\'. */
strreplace(item, '/', '\\');
Expand All @@ -902,6 +904,7 @@ static int tlmi_analyze(void)
setting = kzalloc(sizeof(*setting), GFP_KERNEL);
if (!setting) {
ret = -ENOMEM;
kfree(item);
goto fail_clear_attr;
}
setting->index = i;
Expand All @@ -916,7 +919,6 @@ static int tlmi_analyze(void)
}
kobject_init(&setting->kobj, &tlmi_attr_setting_ktype);
tlmi_priv.setting[i] = setting;
tlmi_priv.settings_count++;
kfree(item);
}

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

static int tlmi_probe(struct wmi_device *wdev, const void *context)
{
tlmi_analyze();
int ret;

ret = tlmi_analyze();
if (ret)
return ret;

return tlmi_sysfs_init();
}

Expand Down
1 change: 0 additions & 1 deletion drivers/platform/x86/think-lmi.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ struct tlmi_attr_setting {
struct think_lmi {
struct wmi_device *wmi_device;

int settings_count;
bool can_set_bios_settings;
bool can_get_bios_selections;
bool can_set_bios_password;
Expand Down

0 comments on commit 812fcc6

Please sign in to comment.