platform/x86: think-lmi: Split kobject_init() and kobject_add() calls
authorHans de Goede <hdegoede@redhat.com>
Sat, 17 Jul 2021 14:36:06 +0000 (16:36 +0200)
committerHans de Goede <hdegoede@redhat.com>
Sat, 17 Jul 2021 14:39:55 +0000 (16:39 +0200)
commit30e78435d3bf803cabdc2a1c2eb36e6983aa4596
tree8133dae389a0134d542e7af07ec0b3204ac206a7
parente62fb1e3faae60f483a96c359c8d72bb04a7b728
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 <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20210717143607.3580-2-hdegoede@redhat.com
drivers/platform/x86/think-lmi.c