Skip to content

Commit 9110056

Browse files
kuu-rtij-intel
authored andcommitted
platform/x86: think-lmi: Fix kobject cleanup
In tlmi_analyze(), allocated structs with an embedded kobject are freed in error paths after the they were already initialized. Fix this by first by avoiding the initialization of kobjects in tlmi_analyze() and then by correctly cleaning them up in tlmi_release_attr() using their kset's kobject list. Fixes: a40cd7e ("platform/x86: think-lmi: Add WMI interface support on Lenovo platforms") Fixes: 30e7843 ("platform/x86: think-lmi: Split kobject_init() and kobject_add() calls") Cc: [email protected] Reviewed-by: Mark Pearson <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Kurt Borja <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ilpo Järvinen <[email protected]>
1 parent 8dab34c commit 9110056

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

drivers/platform/x86/think-lmi.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,13 +1380,13 @@ static struct kobj_attribute debug_cmd = __ATTR_WO(debug_cmd);
13801380
/* ---- Initialisation --------------------------------------------------------- */
13811381
static void tlmi_release_attr(void)
13821382
{
1383+
struct kobject *pos, *n;
13831384
int i;
13841385

13851386
/* Attribute structures */
13861387
for (i = 0; i < TLMI_SETTINGS_COUNT; i++) {
13871388
if (tlmi_priv.setting[i]) {
13881389
sysfs_remove_group(&tlmi_priv.setting[i]->kobj, &tlmi_attr_group);
1389-
kobject_put(&tlmi_priv.setting[i]->kobj);
13901390
}
13911391
}
13921392
sysfs_remove_file(&tlmi_priv.attribute_kset->kobj, &pending_reboot.attr);
@@ -1395,6 +1395,9 @@ static void tlmi_release_attr(void)
13951395
if (tlmi_priv.can_debug_cmd && debug_support)
13961396
sysfs_remove_file(&tlmi_priv.attribute_kset->kobj, &debug_cmd.attr);
13971397

1398+
list_for_each_entry_safe(pos, n, &tlmi_priv.attribute_kset->list, entry)
1399+
kobject_put(pos);
1400+
13981401
kset_unregister(tlmi_priv.attribute_kset);
13991402

14001403
/* Free up any saved signatures */
@@ -1403,19 +1406,17 @@ static void tlmi_release_attr(void)
14031406

14041407
/* Authentication structures */
14051408
sysfs_remove_group(&tlmi_priv.pwd_admin->kobj, &auth_attr_group);
1406-
kobject_put(&tlmi_priv.pwd_admin->kobj);
14071409
sysfs_remove_group(&tlmi_priv.pwd_power->kobj, &auth_attr_group);
1408-
kobject_put(&tlmi_priv.pwd_power->kobj);
14091410

14101411
if (tlmi_priv.opcode_support) {
14111412
sysfs_remove_group(&tlmi_priv.pwd_system->kobj, &auth_attr_group);
1412-
kobject_put(&tlmi_priv.pwd_system->kobj);
14131413
sysfs_remove_group(&tlmi_priv.pwd_hdd->kobj, &auth_attr_group);
1414-
kobject_put(&tlmi_priv.pwd_hdd->kobj);
14151414
sysfs_remove_group(&tlmi_priv.pwd_nvme->kobj, &auth_attr_group);
1416-
kobject_put(&tlmi_priv.pwd_nvme->kobj);
14171415
}
14181416

1417+
list_for_each_entry_safe(pos, n, &tlmi_priv.authentication_kset->list, entry)
1418+
kobject_put(pos);
1419+
14191420
kset_unregister(tlmi_priv.authentication_kset);
14201421
}
14211422

@@ -1479,8 +1480,8 @@ static int tlmi_sysfs_init(void)
14791480

14801481
/* Build attribute */
14811482
tlmi_priv.setting[i]->kobj.kset = tlmi_priv.attribute_kset;
1482-
ret = kobject_add(&tlmi_priv.setting[i]->kobj, NULL,
1483-
"%s", tlmi_priv.setting[i]->display_name);
1483+
ret = kobject_init_and_add(&tlmi_priv.setting[i]->kobj, &tlmi_attr_setting_ktype,
1484+
NULL, "%s", tlmi_priv.setting[i]->display_name);
14841485
if (ret)
14851486
goto fail_create_attr;
14861487

@@ -1505,7 +1506,8 @@ static int tlmi_sysfs_init(void)
15051506

15061507
/* Create authentication entries */
15071508
tlmi_priv.pwd_admin->kobj.kset = tlmi_priv.authentication_kset;
1508-
ret = kobject_add(&tlmi_priv.pwd_admin->kobj, NULL, "%s", "Admin");
1509+
ret = kobject_init_and_add(&tlmi_priv.pwd_admin->kobj, &tlmi_pwd_setting_ktype,
1510+
NULL, "%s", "Admin");
15091511
if (ret)
15101512
goto fail_create_attr;
15111513

@@ -1514,7 +1516,8 @@ static int tlmi_sysfs_init(void)
15141516
goto fail_create_attr;
15151517

15161518
tlmi_priv.pwd_power->kobj.kset = tlmi_priv.authentication_kset;
1517-
ret = kobject_add(&tlmi_priv.pwd_power->kobj, NULL, "%s", "Power-on");
1519+
ret = kobject_init_and_add(&tlmi_priv.pwd_power->kobj, &tlmi_pwd_setting_ktype,
1520+
NULL, "%s", "Power-on");
15181521
if (ret)
15191522
goto fail_create_attr;
15201523

@@ -1524,7 +1527,8 @@ static int tlmi_sysfs_init(void)
15241527

15251528
if (tlmi_priv.opcode_support) {
15261529
tlmi_priv.pwd_system->kobj.kset = tlmi_priv.authentication_kset;
1527-
ret = kobject_add(&tlmi_priv.pwd_system->kobj, NULL, "%s", "System");
1530+
ret = kobject_init_and_add(&tlmi_priv.pwd_system->kobj, &tlmi_pwd_setting_ktype,
1531+
NULL, "%s", "System");
15281532
if (ret)
15291533
goto fail_create_attr;
15301534

@@ -1533,7 +1537,8 @@ static int tlmi_sysfs_init(void)
15331537
goto fail_create_attr;
15341538

15351539
tlmi_priv.pwd_hdd->kobj.kset = tlmi_priv.authentication_kset;
1536-
ret = kobject_add(&tlmi_priv.pwd_hdd->kobj, NULL, "%s", "HDD");
1540+
ret = kobject_init_and_add(&tlmi_priv.pwd_hdd->kobj, &tlmi_pwd_setting_ktype,
1541+
NULL, "%s", "HDD");
15371542
if (ret)
15381543
goto fail_create_attr;
15391544

@@ -1542,7 +1547,8 @@ static int tlmi_sysfs_init(void)
15421547
goto fail_create_attr;
15431548

15441549
tlmi_priv.pwd_nvme->kobj.kset = tlmi_priv.authentication_kset;
1545-
ret = kobject_add(&tlmi_priv.pwd_nvme->kobj, NULL, "%s", "NVMe");
1550+
ret = kobject_init_and_add(&tlmi_priv.pwd_nvme->kobj, &tlmi_pwd_setting_ktype,
1551+
NULL, "%s", "NVMe");
15461552
if (ret)
15471553
goto fail_create_attr;
15481554

@@ -1579,8 +1585,6 @@ static struct tlmi_pwd_setting *tlmi_create_auth(const char *pwd_type,
15791585
new_pwd->maxlen = tlmi_priv.pwdcfg.core.max_length;
15801586
new_pwd->index = 0;
15811587

1582-
kobject_init(&new_pwd->kobj, &tlmi_pwd_setting_ktype);
1583-
15841588
return new_pwd;
15851589
}
15861590

@@ -1685,7 +1689,6 @@ static int tlmi_analyze(struct wmi_device *wdev)
16851689
if (setting->possible_values)
16861690
strreplace(setting->possible_values, ',', ';');
16871691

1688-
kobject_init(&setting->kobj, &tlmi_attr_setting_ktype);
16891692
tlmi_priv.setting[i] = setting;
16901693
kfree(item);
16911694
}

0 commit comments

Comments
 (0)