ACPI: scan: Avoid enumerating devices with clearly invalid _STA values
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 30 Apr 2024 16:02:20 +0000 (18:02 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 30 Apr 2024 19:32:06 +0000 (21:32 +0200)
The return value of _STA with the "present" bit unset and the "enabled"
bit set is clearly invalid as per the ACPI specification, Section 6.3.7
"_STA (Device Status)", so make the ACPI device enumeration code
disregard devices with such _STA return values.

Also, because this implies that status.enabled will only be set if
status.present is set too, acpi_device_is_enabled() can be modified
to simply return the value of the former.

Link: https://uefi.org/specs/ACPI/6.5/06_Device_Configuration.html#sta-device-status
Link: https://lore.kernel.org/linux-acpi/88179311a503493099028c12ca37d430@huawei.com/
Suggested-by: Salil Mehta <salil.mehta@huawei.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
drivers/acpi/bus.c
drivers/acpi/scan.c

index d9fa730416f1910b03ab07dfe7145db5acf5b0eb..18d50448ae1cb4d3ff3bf5d548eff903833f5f7a 100644 (file)
@@ -112,6 +112,17 @@ int acpi_bus_get_status(struct acpi_device *device)
        if (ACPI_FAILURE(status))
                return -ENODEV;
 
+       if (!device->status.present && device->status.enabled) {
+               pr_info(FW_BUG "Device [%s] status [%08x]: not present and enabled\n",
+                       device->pnp.bus_id, (u32)sta);
+               device->status.enabled = 0;
+               /*
+                * The status is clearly invalid, so clear the functional bit as
+                * well to avoid attempting to use the device.
+                */
+               device->status.functional = 0;
+       }
+
        acpi_set_device_status(device, sta);
 
        if (device->status.functional && !device->status.present) {
index 68f101323f535ce51d9362bc23dc68089c28d48f..e41fb5716bc06604358a2e8f776499c115469425 100644 (file)
@@ -1962,7 +1962,7 @@ bool acpi_device_is_present(const struct acpi_device *adev)
 
 bool acpi_device_is_enabled(const struct acpi_device *adev)
 {
-       return adev->status.present && adev->status.enabled;
+       return adev->status.enabled;
 }
 
 static bool acpi_scan_handler_matching(struct acpi_scan_handler *handler,