]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
platform/x86: think-lmi: Fix issues with duplicate attributes
authorMario Limonciello <mario.limonciello@amd.com>
Tue, 22 Jun 2021 20:07:54 +0000 (15:07 -0500)
committerHans de Goede <hdegoede@redhat.com>
Mon, 28 Jun 2021 09:34:44 +0000 (11:34 +0200)
On an AMD based Lenovo T14, I find that the module doesn't work at
all, and instead has a traceback with messages like:

```
sysfs: cannot create duplicate filename '/devices/virtual/firmware-attributes/thinklmi/attributes/Reserved'
```

Duplicate and reserved values showing up appear to be a firmware bug,
but they shouldn't make the driver explode.  So catch them and skip
them.

Fixes: a40cd7ef22fb ("platform/x86: think-lmi: Add WMI interface support on Lenovo platforms")
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Link: https://lore.kernel.org/r/20210622200755.12379-2-mario.limonciello@amd.com
[hdegoede@redhat.com: Add missing kfree(tlmi_priv.setting[i])]
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
drivers/platform/x86/think-lmi.c

index b5706107928810a998394875af2c586231c91126..bbfcaf23d4207812b0e518cf4dd0ae3328bb8531 100644 (file)
@@ -691,6 +691,17 @@ static int tlmi_sysfs_init(void)
                if (!tlmi_priv.setting[i])
                        continue;
 
+               /* check for duplicate or reserved values */
+               if (kset_find_obj(tlmi_priv.attribute_kset, tlmi_priv.setting[i]->display_name) ||
+                   !strcmp(tlmi_priv.setting[i]->display_name, "Reserved")) {
+                       pr_debug("duplicate or reserved attribute name found - %s\n",
+                               tlmi_priv.setting[i]->display_name);
+                       kfree(tlmi_priv.setting[i]->possible_values);
+                       kfree(tlmi_priv.setting[i]);
+                       tlmi_priv.setting[i] = NULL;
+                       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,