Re: [PATCH 04/13] platform/x86: lenovo: think-lmi: store attributes as linked list
From: Rong Zhang
Date: Fri Dec 04 2026 - 08:36:11 EST
Hi Mark,
On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
> Use a linked list for storing attributes instead of a fixed array.
>
> Signed-off-by: Mark Pearson <mpearson-lenovo@xxxxxxxxx>
> ---
> drivers/platform/x86/lenovo/think-lmi.c | 55 +++++++++++--------------
> drivers/platform/x86/lenovo/think-lmi.h | 3 +-
> 2 files changed, 25 insertions(+), 33 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/think-lmi.c b/drivers/platform/x86/lenovo/think-lmi.c
> index 6580b1401f01..7a24985882ea 100644
> --- a/drivers/platform/x86/lenovo/think-lmi.c
> +++ b/drivers/platform/x86/lenovo/think-lmi.c
> @@ -1249,6 +1249,7 @@ static void tlmi_attr_setting_release(struct kobject *kobj)
> {
> struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
>
> + list_del(&setting->node);
I guess you need a scoped_guard() or lockdep_assert_held() for it, but is
it useful to keep the list in the first place? It seems that no one
touches it once probe finishes.
Thanks,
Rong
> kfree(setting->name);
> kfree(setting->display_name);
> kfree(setting->possible_values);
> @@ -1440,14 +1441,14 @@ static struct kobj_attribute debug_cmd = __ATTR_WO(debug_cmd);
>
> /* ---- Initialisation --------------------------------------------------------- */
> /* Utility function to free record when not in the attribute_kset list */
> -static void tlmi_free_attr_record(int i)
> +static void tlmi_free_attr_record(struct tlmi_attr_setting *attr)
> {
> - kfree(tlmi_priv.setting[i]->name);
> - kfree(tlmi_priv.setting[i]->display_name);
> - kfree(tlmi_priv.setting[i]->possible_values);
> - kfree(tlmi_priv.setting[i]->current_value);
> - kfree(tlmi_priv.setting[i]);
> - tlmi_priv.setting[i] = NULL;
> + list_del(&attr->node);
> + kfree(attr->name);
> + kfree(attr->display_name);
> + kfree(attr->possible_values);
> + kfree(attr->current_value);
> + kfree(attr);
> }
>
> static void tlmi_release_attr(void)
> @@ -1465,8 +1466,6 @@ static void tlmi_release_attr(void)
> kobject_put(pos);
>
> kset_unregister(tlmi_priv.attribute_kset);
> - /* Clear up settings array */
> - memset(tlmi_priv.setting, 0, sizeof(tlmi_priv.setting));
>
> /* Free up any saved signatures */
> if (tlmi_priv.pwd_admin) {
> @@ -1505,7 +1504,8 @@ static int tlmi_validate_setting_name(struct kset *attribute_kset, char *name)
>
> static int tlmi_sysfs_init(void)
> {
> - int i, ret = 0, auth_ret = 0;
> + struct tlmi_attr_setting *attr, *na;
> + int ret = 0, auth_ret = 0;
>
> guard(mutex)(&tlmi_mutex);
> tlmi_priv.class_dev = device_create(&firmware_attributes_class, NULL, MKDEV(0, 0),
> @@ -1530,29 +1530,25 @@ static int tlmi_sysfs_init(void)
> goto fail_device_created;
> }
>
> - for (i = 0; i < TLMI_SETTINGS_COUNT; i++) {
> - /* Check if index is a valid setting - skip if it isn't */
> - if (!tlmi_priv.setting[i])
> - continue;
> -
> + list_for_each_entry_safe(attr, na, &tlmi_priv.settings, node) {
> if (ret) { /* We had a critical failure. Just clean up */
> - tlmi_free_attr_record(i);
> + tlmi_free_attr_record(attr);
> continue;
> }
>
> /* check for duplicate or reserved values */
> if (tlmi_validate_setting_name(tlmi_priv.attribute_kset,
> - tlmi_priv.setting[i]->display_name) < 0) {
> - tlmi_free_attr_record(i);
> + attr->display_name) < 0) {
> + tlmi_free_attr_record(attr);
> continue;
> }
>
> /* Build attribute */
> - tlmi_priv.setting[i]->kobj.kset = tlmi_priv.attribute_kset;
> - ret = kobject_init_and_add(&tlmi_priv.setting[i]->kobj, &tlmi_attr_setting_ktype,
> - NULL, "%s", tlmi_priv.setting[i]->display_name);
> + attr->kobj.kset = tlmi_priv.attribute_kset;
> + ret = kobject_init_and_add(&attr->kobj, &tlmi_attr_setting_ktype,
> + NULL, "%s", attr->display_name);
> if (ret) {
> - kobject_put(&tlmi_priv.setting[i]->kobj);
> + kobject_put(&attr->kobj);
> continue; /* use loop to clear remaining items */
> }
> }
> @@ -1664,6 +1660,7 @@ static struct tlmi_pwd_setting *tlmi_create_auth(const char *pwd_type,
>
> static int tlmi_analyze(struct wmi_device *wdev)
> {
> + struct tlmi_attr_setting *attr, *na;
> int i, ret;
>
> if (wmi_has_guid(LENOVO_SET_BIOS_SETTINGS_GUID) &&
> @@ -1699,6 +1696,7 @@ static int tlmi_analyze(struct wmi_device *wdev)
> pr_info("ThinkCenter modified support being used\n");
> }
>
> + INIT_LIST_HEAD(&tlmi_priv.settings);
> /*
> * Try to find the number of valid settings of this machine
> * and use it to create sysfs attributes.
> @@ -1804,7 +1802,7 @@ static int tlmi_analyze(struct wmi_device *wdev)
> if (setting->possible_values)
> strreplace(setting->possible_values, ',', ';');
>
> - tlmi_priv.setting[i] = setting;
> + list_add_tail(&setting->node, &tlmi_priv.settings);
> kfree(item);
> }
>
> @@ -1890,15 +1888,8 @@ static int tlmi_analyze(struct wmi_device *wdev)
> return 0;
>
> fail_clear_attr:
> - for (i = 0; i < TLMI_SETTINGS_COUNT; ++i) {
> - if (tlmi_priv.setting[i]) {
> - kfree(tlmi_priv.setting[i]->name);
> - kfree(tlmi_priv.setting[i]->display_name);
> - kfree(tlmi_priv.setting[i]->possible_values);
> - kfree(tlmi_priv.setting[i]->current_value);
> - kfree(tlmi_priv.setting[i]);
> - }
> - }
> + list_for_each_entry_safe(attr, na, &tlmi_priv.settings, node)
> + tlmi_free_attr_record(attr);
> kfree(tlmi_priv.pwd_admin);
> kfree(tlmi_priv.pwd_power);
> kfree(tlmi_priv.pwd_system);
> diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
> index 54d5c3b8233e..d0d8428ee440 100644
> --- a/drivers/platform/x86/lenovo/think-lmi.h
> +++ b/drivers/platform/x86/lenovo/think-lmi.h
> @@ -100,6 +100,7 @@ struct tlmi_pwd_setting {
> struct tlmi_attr_setting {
> struct kobject kobj;
> struct wmi_device *wdev;
> + struct list_head node;
> int index;
> char *name;
> char *display_name;
> @@ -123,7 +124,7 @@ struct think_lmi {
> bool reboot_required;
> bool thinkcenter_mode;
>
> - struct tlmi_attr_setting *setting[TLMI_SETTINGS_COUNT];
> + struct list_head settings;
> struct device *class_dev;
> struct kset *attribute_kset;
> struct kset *authentication_kset;