From 8567b5733715e959474851dbec666aafcdba86e8 Mon Sep 17 00:00:00 2001 From: Kartik Rajput Date: Wed, 14 Jan 2026 13:53:06 +0530 Subject: [PATCH] ACPI: bus: Align acpi_device_get_match_data() with driver match order MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit During pre-production development, drivers may provide both ACPI and OF match tables while a formal ACPI HID for the device is not yet allocated. Such devices are enumerated via PRP0001. In this case, acpi_device_get_match_data() consults only the driver’s ACPI match table and returns NULL, even though the device was successfully matched via PRP0001. This behavior also risks breaking existing PRP0001 setups if a driver later gains an ACPI HID, as the presence of an ACPI match table changes the match-data lookup path. Make acpi_device_get_match_data() use the same precedence as driver matching by using __acpi_match_device(). Return match data from the acpi_id or of_id that was actually matched. Remove now-unused acpi_of_device_get_match_data(). Signed-off-by: Kartik Rajput Reviewed-by: Andy Shevchenko Reviewed-by: Sakari Ailus Link: https://patch.msgid.link/20260114082306.48119-1-kkartik@nvidia.com Signed-off-by: Rafael J. Wysocki --- drivers/acpi/bus.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 06b51886bef87..a616e62c1ab0d 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -1013,30 +1013,24 @@ const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids, } EXPORT_SYMBOL_GPL(acpi_match_device); -static const void *acpi_of_device_get_match_data(const struct device *dev) -{ - struct acpi_device *adev = ACPI_COMPANION(dev); - const struct of_device_id *match = NULL; - - if (!acpi_of_match_device(adev, dev->driver->of_match_table, &match)) - return NULL; - - return match->data; -} - const void *acpi_device_get_match_data(const struct device *dev) { const struct acpi_device_id *acpi_ids = dev->driver->acpi_match_table; - const struct acpi_device_id *match; + const struct of_device_id *of_ids = dev->driver->of_match_table; + const struct acpi_device *adev = acpi_companion_match(dev); + const struct acpi_device_id *acpi_id = NULL; + const struct of_device_id *of_id = NULL; - if (!acpi_ids) - return acpi_of_device_get_match_data(dev); - - match = acpi_match_device(acpi_ids, dev); - if (!match) + if (!__acpi_match_device(adev, acpi_ids, of_ids, &acpi_id, &of_id)) return NULL; - return (const void *)match->driver_data; + if (acpi_id) + return (const void *)acpi_id->driver_data; + + if (of_id) + return of_id->data; + + return NULL; } EXPORT_SYMBOL_GPL(acpi_device_get_match_data); -- 2.47.3