Skip to content

Commit f65ad43

Browse files
kuu-rtgregkh
authored andcommitted
platform/x86: think-lmi: Fix sysfs group cleanup
commit 4f30f94 upstream. Many error paths in tlmi_sysfs_init() lead to sysfs groups being removed when they were not even created. Fix this by letting the kobject core manage these groups through their kobj_type's defult_groups. Fixes: a40cd7e ("platform/x86: think-lmi: Add WMI interface support on Lenovo platforms") 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5805edb commit f65ad43

File tree

1 file changed

+4
-39
lines changed

1 file changed

+4
-39
lines changed

drivers/platform/x86/think-lmi.c

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,7 @@ static const struct attribute_group auth_attr_group = {
906906
.is_visible = auth_attr_is_visible,
907907
.attrs = auth_attrs,
908908
};
909+
__ATTRIBUTE_GROUPS(auth_attr);
909910

910911
/* ---- Attributes sysfs --------------------------------------------------------- */
911912
static ssize_t display_name_show(struct kobject *kobj, struct kobj_attribute *attr,
@@ -1121,6 +1122,7 @@ static const struct attribute_group tlmi_attr_group = {
11211122
.is_visible = attr_is_visible,
11221123
.attrs = tlmi_attrs,
11231124
};
1125+
__ATTRIBUTE_GROUPS(tlmi_attr);
11241126

11251127
static void tlmi_attr_setting_release(struct kobject *kobj)
11261128
{
@@ -1140,11 +1142,13 @@ static void tlmi_pwd_setting_release(struct kobject *kobj)
11401142
static const struct kobj_type tlmi_attr_setting_ktype = {
11411143
.release = &tlmi_attr_setting_release,
11421144
.sysfs_ops = &kobj_sysfs_ops,
1145+
.default_groups = tlmi_attr_groups,
11431146
};
11441147

11451148
static const struct kobj_type tlmi_pwd_setting_ktype = {
11461149
.release = &tlmi_pwd_setting_release,
11471150
.sysfs_ops = &kobj_sysfs_ops,
1151+
.default_groups = auth_attr_groups,
11481152
};
11491153

11501154
static ssize_t pending_reboot_show(struct kobject *kobj, struct kobj_attribute *attr,
@@ -1314,14 +1318,8 @@ static struct kobj_attribute debug_cmd = __ATTR_WO(debug_cmd);
13141318
static void tlmi_release_attr(void)
13151319
{
13161320
struct kobject *pos, *n;
1317-
int i;
13181321

13191322
/* Attribute structures */
1320-
for (i = 0; i < TLMI_SETTINGS_COUNT; i++) {
1321-
if (tlmi_priv.setting[i]) {
1322-
sysfs_remove_group(&tlmi_priv.setting[i]->kobj, &tlmi_attr_group);
1323-
}
1324-
}
13251323
sysfs_remove_file(&tlmi_priv.attribute_kset->kobj, &pending_reboot.attr);
13261324
sysfs_remove_file(&tlmi_priv.attribute_kset->kobj, &save_settings.attr);
13271325

@@ -1338,15 +1336,6 @@ static void tlmi_release_attr(void)
13381336
kfree(tlmi_priv.pwd_admin->save_signature);
13391337

13401338
/* Authentication structures */
1341-
sysfs_remove_group(&tlmi_priv.pwd_admin->kobj, &auth_attr_group);
1342-
sysfs_remove_group(&tlmi_priv.pwd_power->kobj, &auth_attr_group);
1343-
1344-
if (tlmi_priv.opcode_support) {
1345-
sysfs_remove_group(&tlmi_priv.pwd_system->kobj, &auth_attr_group);
1346-
sysfs_remove_group(&tlmi_priv.pwd_hdd->kobj, &auth_attr_group);
1347-
sysfs_remove_group(&tlmi_priv.pwd_nvme->kobj, &auth_attr_group);
1348-
}
1349-
13501339
list_for_each_entry_safe(pos, n, &tlmi_priv.authentication_kset->list, entry)
13511340
kobject_put(pos);
13521341

@@ -1417,10 +1406,6 @@ static int tlmi_sysfs_init(void)
14171406
NULL, "%s", tlmi_priv.setting[i]->display_name);
14181407
if (ret)
14191408
goto fail_create_attr;
1420-
1421-
ret = sysfs_create_group(&tlmi_priv.setting[i]->kobj, &tlmi_attr_group);
1422-
if (ret)
1423-
goto fail_create_attr;
14241409
}
14251410

14261411
ret = sysfs_create_file(&tlmi_priv.attribute_kset->kobj, &pending_reboot.attr);
@@ -1444,50 +1429,30 @@ static int tlmi_sysfs_init(void)
14441429
if (ret)
14451430
goto fail_create_attr;
14461431

1447-
ret = sysfs_create_group(&tlmi_priv.pwd_admin->kobj, &auth_attr_group);
1448-
if (ret)
1449-
goto fail_create_attr;
1450-
14511432
tlmi_priv.pwd_power->kobj.kset = tlmi_priv.authentication_kset;
14521433
ret = kobject_init_and_add(&tlmi_priv.pwd_power->kobj, &tlmi_pwd_setting_ktype,
14531434
NULL, "%s", "Power-on");
14541435
if (ret)
14551436
goto fail_create_attr;
14561437

1457-
ret = sysfs_create_group(&tlmi_priv.pwd_power->kobj, &auth_attr_group);
1458-
if (ret)
1459-
goto fail_create_attr;
1460-
14611438
if (tlmi_priv.opcode_support) {
14621439
tlmi_priv.pwd_system->kobj.kset = tlmi_priv.authentication_kset;
14631440
ret = kobject_init_and_add(&tlmi_priv.pwd_system->kobj, &tlmi_pwd_setting_ktype,
14641441
NULL, "%s", "System");
14651442
if (ret)
14661443
goto fail_create_attr;
14671444

1468-
ret = sysfs_create_group(&tlmi_priv.pwd_system->kobj, &auth_attr_group);
1469-
if (ret)
1470-
goto fail_create_attr;
1471-
14721445
tlmi_priv.pwd_hdd->kobj.kset = tlmi_priv.authentication_kset;
14731446
ret = kobject_init_and_add(&tlmi_priv.pwd_hdd->kobj, &tlmi_pwd_setting_ktype,
14741447
NULL, "%s", "HDD");
14751448
if (ret)
14761449
goto fail_create_attr;
14771450

1478-
ret = sysfs_create_group(&tlmi_priv.pwd_hdd->kobj, &auth_attr_group);
1479-
if (ret)
1480-
goto fail_create_attr;
1481-
14821451
tlmi_priv.pwd_nvme->kobj.kset = tlmi_priv.authentication_kset;
14831452
ret = kobject_init_and_add(&tlmi_priv.pwd_nvme->kobj, &tlmi_pwd_setting_ktype,
14841453
NULL, "%s", "NVMe");
14851454
if (ret)
14861455
goto fail_create_attr;
1487-
1488-
ret = sysfs_create_group(&tlmi_priv.pwd_nvme->kobj, &auth_attr_group);
1489-
if (ret)
1490-
goto fail_create_attr;
14911456
}
14921457

14931458
return ret;

0 commit comments

Comments
 (0)