Skip to content

Commit

Permalink
platform/x86: think-lmi: Fix possible mem-leaks on tlmi_analyze() err…
Browse files Browse the repository at this point in the history
…or-exit

Fix 2 possible memleaks on error-exits from tlmi_analyze():

1. If the kzalloc of pwd_power fails, then not only free the atributes,
   but also the allocated pwd_admin struct.

2. Freeing the attributes should also free the possible_values strings.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20210717143607.3580-3-hdegoede@redhat.com
  • Loading branch information
Hans de Goede committed Jul 17, 2021
1 parent 30e7843 commit f7e506e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions drivers/platform/x86/think-lmi.c
Original file line number Diff line number Diff line change
@@ -866,7 +866,7 @@ static int tlmi_analyze(void)
tlmi_priv.pwd_power = kzalloc(sizeof(struct tlmi_pwd_setting), GFP_KERNEL);
if (!tlmi_priv.pwd_power) {
ret = -ENOMEM;
goto fail_clear_attr;
goto fail_free_pwd_admin;
}
strscpy(tlmi_priv.pwd_power->kbdlang, "us", TLMI_LANG_MAXLEN);
tlmi_priv.pwd_power->encoding = TLMI_ENCODING_ASCII;
@@ -882,9 +882,15 @@ static int tlmi_analyze(void)

return 0;

fail_free_pwd_admin:
kfree(tlmi_priv.pwd_admin);
fail_clear_attr:
for (i = 0; i < TLMI_SETTINGS_COUNT; ++i)
kfree(tlmi_priv.setting[i]);
for (i = 0; i < TLMI_SETTINGS_COUNT; ++i) {
if (tlmi_priv.setting[i]) {
kfree(tlmi_priv.setting[i]->possible_values);
kfree(tlmi_priv.setting[i]);
}
}
return ret;
}

0 comments on commit f7e506e

Please sign in to comment.