Skip to content

Commit f7e506e

Browse files
committed
platform/x86: think-lmi: Fix possible mem-leaks on tlmi_analyze() error-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 <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 30e7843 commit f7e506e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

drivers/platform/x86/think-lmi.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ static int tlmi_analyze(void)
866866
tlmi_priv.pwd_power = kzalloc(sizeof(struct tlmi_pwd_setting), GFP_KERNEL);
867867
if (!tlmi_priv.pwd_power) {
868868
ret = -ENOMEM;
869-
goto fail_clear_attr;
869+
goto fail_free_pwd_admin;
870870
}
871871
strscpy(tlmi_priv.pwd_power->kbdlang, "us", TLMI_LANG_MAXLEN);
872872
tlmi_priv.pwd_power->encoding = TLMI_ENCODING_ASCII;
@@ -882,9 +882,15 @@ static int tlmi_analyze(void)
882882

883883
return 0;
884884

885+
fail_free_pwd_admin:
886+
kfree(tlmi_priv.pwd_admin);
885887
fail_clear_attr:
886-
for (i = 0; i < TLMI_SETTINGS_COUNT; ++i)
887-
kfree(tlmi_priv.setting[i]);
888+
for (i = 0; i < TLMI_SETTINGS_COUNT; ++i) {
889+
if (tlmi_priv.setting[i]) {
890+
kfree(tlmi_priv.setting[i]->possible_values);
891+
kfree(tlmi_priv.setting[i]);
892+
}
893+
}
888894
return ret;
889895
}
890896

0 commit comments

Comments
 (0)