[RFC PATCH v1] platform/x86: wmi: Do not register driver with invalid GUID

From: Barnabás Pőcze
Date: Sat Jul 15 2023 - 17:24:39 EST


Since a WMI driver's ID table contains strings it is relatively
easy to make mistakes. At the moment, there is no feedback
if any of the specified GUIDs are invalid (since
028e6e204ace1f080cfeacd72c50397eb8ae8883).

So check if the GUIDs in the driver's ID table are valid,
print all invalid ones, and refuse to register the driver
if any of the GUIDs are invalid.

Signed-off-by: Barnabás Pőcze <pobrn@xxxxxxxxxxxxxx>
---
drivers/platform/x86/wmi.c | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index a78ddd83cda0..bf0be40b418a 100644
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -1513,6 +1513,19 @@ static int acpi_wmi_probe(struct platform_device *device)
int __must_check __wmi_driver_register(struct wmi_driver *driver,
struct module *owner)
{
+ bool any_id_invalid = false;
+
+ for (const struct wmi_device_id *id = driver->id_table; *id->guid_string; id++) {
+ if (!uuid_is_valid(id->guid_string)) {
+ pr_err("driver '%s' has invalid GUID: %s",
+ driver->driver.name, id->guid_string);
+ any_id_invalid = true;
+ }
+ }
+
+ if (any_id_invalid)
+ return -EINVAL;
+
driver->driver.owner = owner;
driver->driver.bus = &wmi_bus_type;

--
2.41.0