Commit f7e506ec authored by Hans de Goede's avatar Hans de Goede

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: default avatarHans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20210717143607.3580-3-hdegoede@redhat.com
parent 30e78435
...@@ -866,7 +866,7 @@ static int tlmi_analyze(void) ...@@ -866,7 +866,7 @@ static int tlmi_analyze(void)
tlmi_priv.pwd_power = kzalloc(sizeof(struct tlmi_pwd_setting), GFP_KERNEL); tlmi_priv.pwd_power = kzalloc(sizeof(struct tlmi_pwd_setting), GFP_KERNEL);
if (!tlmi_priv.pwd_power) { if (!tlmi_priv.pwd_power) {
ret = -ENOMEM; ret = -ENOMEM;
goto fail_clear_attr; goto fail_free_pwd_admin;
} }
strscpy(tlmi_priv.pwd_power->kbdlang, "us", TLMI_LANG_MAXLEN); strscpy(tlmi_priv.pwd_power->kbdlang, "us", TLMI_LANG_MAXLEN);
tlmi_priv.pwd_power->encoding = TLMI_ENCODING_ASCII; tlmi_priv.pwd_power->encoding = TLMI_ENCODING_ASCII;
...@@ -882,9 +882,15 @@ static int tlmi_analyze(void) ...@@ -882,9 +882,15 @@ static int tlmi_analyze(void)
return 0; return 0;
fail_free_pwd_admin:
kfree(tlmi_priv.pwd_admin);
fail_clear_attr: fail_clear_attr:
for (i = 0; i < TLMI_SETTINGS_COUNT; ++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]); kfree(tlmi_priv.setting[i]);
}
}
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment