platform/x86: wmi: Ignore duplicated GUIDs in legacy matches
authorArmin Wolf <W_Armin@gmx.de>
Mon, 26 Feb 2024 19:35:55 +0000 (20:35 +0100)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Tue, 12 Mar 2024 10:47:33 +0000 (12:47 +0200)
When matching a WMI device to a GUID used by the legacy GUID-based
API, devices with a duplicated GUID should be ignored.

Add an additional WMI device flag signaling that the GUID used by
the WMI device is also used by another WMI device. Ignore such
devices inside the match functions used by the legacy GUID-based API.

Tested on a ASUS Prime B650-Plus.

Signed-off-by: Armin Wolf <W_Armin@gmx.de>
Link: https://lore.kernel.org/r/20240226193557.2888-1-W_Armin@gmx.de
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/wmi.c

index abd0183c4107848edb637d17edc4757784f4fa68..29dfe52eb802879a8c789d1b7adbe66d5aba52aa 100644 (file)
@@ -57,6 +57,7 @@ static_assert(__alignof__(struct guid_block) == 1);
 
 enum { /* wmi_block flags */
        WMI_READ_TAKES_NO_ARGS,
+       WMI_GUID_DUPLICATED,
        WMI_NO_EVENT_DATA,
 };
 
@@ -196,6 +197,12 @@ static int wmidev_match_guid(struct device *dev, const void *data)
        struct wmi_block *wblock = dev_to_wblock(dev);
        const guid_t *guid = data;
 
+       /* Legacy GUID-based functions are restricted to only see
+        * a single WMI device for each GUID.
+        */
+       if (test_bit(WMI_GUID_DUPLICATED, &wblock->flags))
+               return 0;
+
        if (guid_equal(guid, &wblock->gblock.guid))
                return 1;
 
@@ -207,6 +214,12 @@ static int wmidev_match_notify_id(struct device *dev, const void *data)
        struct wmi_block *wblock = dev_to_wblock(dev);
        const u32 *notify_id = data;
 
+       /* Legacy GUID-based functions are restricted to only see
+        * a single WMI device for each GUID.
+        */
+       if (test_bit(WMI_GUID_DUPLICATED, &wblock->flags))
+               return 0;
+
        if (wblock->gblock.flags & ACPI_WMI_EVENT && wblock->gblock.notify_id == *notify_id)
                return 1;
 
@@ -1036,10 +1049,12 @@ static int wmi_create_device(struct device *wmi_bus_dev,
        wblock->dev.dev.parent = wmi_bus_dev;
 
        count = guid_count(&wblock->gblock.guid);
-       if (count)
+       if (count) {
                dev_set_name(&wblock->dev.dev, "%pUL-%d", &wblock->gblock.guid, count);
-       else
+               set_bit(WMI_GUID_DUPLICATED, &wblock->flags);
+       } else {
                dev_set_name(&wblock->dev.dev, "%pUL", &wblock->gblock.guid);
+       }
 
        device_initialize(&wblock->dev.dev);