Skip to content

Commit 30e7843

Browse files
committed
platform/x86: think-lmi: Split kobject_init() and kobject_add() calls
tlmi_sysfs_init() calls tlmi_release_attr() on errors which calls kobject_put() for attributes created by tlmi_analyze(), but if we bail early because of an error, then this means that some of the kobjects will not have been initialized yet; and we should thus not call kobject_put() on them. Switch from using kobject_init_and_add() inside tlmi_sysfs_init() to initializing all the created kobjects directly in tlmi_analyze() and only adding them from tlmi_sysfs_init(). This way all kobjects will always be initialized when tlmi_release_attr() gets called. Signed-off-by: Hans de Goede <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent e62fb1e commit 30e7843

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

drivers/platform/x86/think-lmi.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,8 @@ static int tlmi_sysfs_init(void)
723723

724724
/* Build attribute */
725725
tlmi_priv.setting[i]->kobj.kset = tlmi_priv.attribute_kset;
726-
ret = kobject_init_and_add(&tlmi_priv.setting[i]->kobj, &tlmi_attr_setting_ktype,
727-
NULL, "%s", tlmi_priv.setting[i]->display_name);
726+
ret = kobject_add(&tlmi_priv.setting[i]->kobj, NULL,
727+
"%s", tlmi_priv.setting[i]->display_name);
728728
if (ret)
729729
goto fail_create_attr;
730730

@@ -745,8 +745,7 @@ static int tlmi_sysfs_init(void)
745745
goto fail_create_attr;
746746
}
747747
tlmi_priv.pwd_admin->kobj.kset = tlmi_priv.authentication_kset;
748-
ret = kobject_init_and_add(&tlmi_priv.pwd_admin->kobj, &tlmi_pwd_setting_ktype,
749-
NULL, "%s", "Admin");
748+
ret = kobject_add(&tlmi_priv.pwd_admin->kobj, NULL, "%s", "Admin");
750749
if (ret)
751750
goto fail_create_attr;
752751

@@ -755,8 +754,7 @@ static int tlmi_sysfs_init(void)
755754
goto fail_create_attr;
756755

757756
tlmi_priv.pwd_power->kobj.kset = tlmi_priv.authentication_kset;
758-
ret = kobject_init_and_add(&tlmi_priv.pwd_power->kobj, &tlmi_pwd_setting_ktype,
759-
NULL, "%s", "System");
757+
ret = kobject_add(&tlmi_priv.pwd_power->kobj, NULL, "%s", "System");
760758
if (ret)
761759
goto fail_create_attr;
762760

@@ -836,6 +834,7 @@ static int tlmi_analyze(void)
836834
pr_info("Error retrieving possible values for %d : %s\n",
837835
i, setting->display_name);
838836
}
837+
kobject_init(&setting->kobj, &tlmi_attr_setting_ktype);
839838
tlmi_priv.setting[i] = setting;
840839
tlmi_priv.settings_count++;
841840
kfree(item);
@@ -862,6 +861,8 @@ static int tlmi_analyze(void)
862861
if (pwdcfg.password_state & TLMI_PAP_PWD)
863862
tlmi_priv.pwd_admin->valid = true;
864863

864+
kobject_init(&tlmi_priv.pwd_admin->kobj, &tlmi_pwd_setting_ktype);
865+
865866
tlmi_priv.pwd_power = kzalloc(sizeof(struct tlmi_pwd_setting), GFP_KERNEL);
866867
if (!tlmi_priv.pwd_power) {
867868
ret = -ENOMEM;
@@ -877,6 +878,8 @@ static int tlmi_analyze(void)
877878
if (pwdcfg.password_state & TLMI_POP_PWD)
878879
tlmi_priv.pwd_power->valid = true;
879880

881+
kobject_init(&tlmi_priv.pwd_power->kobj, &tlmi_pwd_setting_ktype);
882+
880883
return 0;
881884

882885
fail_clear_attr:

0 commit comments

Comments
 (0)