[PATCH v2 01/12] platform/wmi: Introduce wmidev_exists()

From: Rong Zhang

Date: Fri Oct 09 2026 - 08:56:26 EST


From: Armin Wolf <W_Armin@xxxxxx>

Some WMI drivers need to be able to detect the existence of WMI
devices matching a given GUID in order to determine the availability
of optional features. Using wmi_has_guid() for this will not work for
WMI devices that cannot be used with the legacy GUID-based API (aka
have WMI_GUID_DUPLICATED set).

Introduce wmidev_exists() that also checks WMI devices that are only
available to the bus-based API. Also mark wmi_has_guid() as deprecated
because only WMI drivers using the legacy GUID-based API will continue
to have use for it.

Signed-off-by: Armin Wolf <W_Armin@xxxxxx>
Signed-off-by: Rong Zhang <i@xxxxxxxx>
---
Changes in v2:
- New patch in the series as discussed at
https://msgid.link/83776200-4A60-4756-A99F-D5A3BB4D834A@xxxxxxxx
---
drivers/platform/wmi/core.c | 33 +++++++++++++++++++++++++++++----
include/linux/wmi.h | 3 +++
2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/wmi/core.c b/drivers/platform/wmi/core.c
index 529825dcfbfe..a99da9b7039d 100644
--- a/drivers/platform/wmi/core.c
+++ b/drivers/platform/wmi/core.c
@@ -145,7 +145,7 @@ static inline void get_acpi_method_name(const struct wmi_block *wblock,
buffer[4] = '\0';
}

-static int wmidev_match_guid(struct device *dev, const void *data)
+static int wmidev_match_guid_legacy(struct device *dev, const void *data)
{
struct wmi_block *wblock = dev_to_wblock(dev);
const guid_t *guid = data;
@@ -218,7 +218,7 @@ static struct wmi_device *wmi_find_device_by_guid(const char *guid_string)
if (ret < 0)
return ERR_PTR(ret);

- dev = bus_find_device(&wmi_bus_type, NULL, &guid, wmidev_match_guid);
+ dev = bus_find_device(&wmi_bus_type, NULL, &guid, wmidev_match_guid_legacy);
if (!dev)
return ERR_PTR(-ENODEV);

@@ -800,10 +800,10 @@ acpi_status wmi_remove_notify_handler(const char *guid)
EXPORT_SYMBOL_GPL(wmi_remove_notify_handler);

/**
- * wmi_has_guid - Check if a GUID is available
+ * wmi_has_guid - Check if a GUID is available (deprecated)
* @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
*
- * Check if a given GUID is defined by _WDG.
+ * Check if a given GUID is available and usable with the legacy GUID-based API.
*
* Return: True if GUID is available, false otherwise.
*/
@@ -821,6 +821,31 @@ bool wmi_has_guid(const char *guid_string)
}
EXPORT_SYMBOL_GPL(wmi_has_guid);

+static int wmidev_match_guid(struct device *dev, void *data)
+{
+ struct wmi_block *wblock = dev_to_wblock(dev);
+ const guid_t *guid = data;
+
+ if (guid_equal(guid, &wblock->gblock.guid))
+ return 1;
+
+ return 0;
+}
+
+/**
+ * wmidev_exists - Check if a WMI device with a given GUID exists
+ * @guid: GUID of the WMI device to search for
+ *
+ * Check if a WMI device with a given GUID exists at the given moment.
+ *
+ * Return: True if a matching WMI device exists, false otherwise.
+ */
+bool wmidev_exists(const guid_t *guid)
+{
+ return bus_for_each_dev(&wmi_bus_type, NULL, (void *)guid, wmidev_match_guid) == 1;
+}
+EXPORT_SYMBOL_GPL(wmidev_exists);
+
/**
* wmi_get_acpi_device_uid() - Get _UID name of ACPI device that defines GUID (deprecated)
* @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
diff --git a/include/linux/wmi.h b/include/linux/wmi.h
index defcb624a7e2..3dd223f2ff18 100644
--- a/include/linux/wmi.h
+++ b/include/linux/wmi.h
@@ -13,6 +13,7 @@
#include <linux/acpi.h>
#include <linux/device-id/wmi.h>
#include <linux/types.h>
+#include <linux/uuid.h>

/**
* struct wmi_device - WMI device structure
@@ -83,6 +84,8 @@ acpi_status wmidev_block_set(struct wmi_device *wdev, u8 instance, const struct

u8 wmidev_instance_count(struct wmi_device *wdev);

+bool wmidev_exists(const guid_t *guid);
+
/**
* struct wmi_driver - WMI driver structure
* @driver: Driver model structure

--
2.55.0