ACPI: scan: Avoid enumerating devices with clearly invalid _STA values
PATCH 1/1 ACPI: scan: Avoid enumerating devices with clearly invalid _STA values
From: Rafael J. Wysocki <[email protected]>
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.
--- drivers/acpi/bus.c | 11 +++++++++++ drivers/acpi/scan.c | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-)
drivers/acpi/bus.c +11 -0
@@ -112,6 +112,17 @@ int acpi_bus_get_status(struct acpi_deviif (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 enabled 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) {
drivers/acpi/scan.c +1 -1
@@ -1962,7 +1962,7 @@ bool acpi_device_is_present(const structbool 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,
Quoted 34 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The return value of
_STAwith 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_STAreturn 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/[email protected]/Suggested-by Salil Mehta <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>---
drivers/acpi/bus.c | 11 +++++++++++
drivers/acpi/scan.c | 2 +-2 files changed, 12 insertions(+), 1 deletion(-)Index:
linux-pm/drivers/acpi/bus.c
===================================================================drivers/acpi/bus.c +0
-0@@ -112,6 +112,17 @@ int acpi_bus_get_status(struct acpi_devi if (ACPI_FAILURE(status)) return -ENODEV;
+ if (!device->status.present &&device->status.enabled) { + pr_info(FW_BUG "Device [%s] status [%08x]: not
Quoted 8 lines
present and enabled\n",
+ device->pnp.bus_id, (u32)sta); + device->status.enabled = 0;
+ /*
+ * The status is clearly invalid, so clear the enabled bit as
+ * well to avoid attempting to use the device. + */
seems that this comment is for the line above?
thanks,
rui
Quoted 24 lines
+ device->status.functional = 0;
+ }
+
acpi_set_device_status(device, sta);
if (device->status.functional&& !device->status.present) {
Index:linux-pm/drivers/acpi/scan.c
===================================================================drivers/acpi/scan.c +0
-0@@ -1962,7 +1962,7 @@ bool acpi_device_is_present(const struct
boolacpi_device_is_enabled(const struct acpi_device *adev){
- returnadev->status.present&&adev->status.enabled; + returnadev->status.enabled;
}
static bool acpi_scan_handler_matching(structacpi_scan_handler*handler,
Rafael J. Wysocki
maintainerQuoted 34 lines · Rui
Quoted 32 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The return value of
_STAwith 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_STAreturn 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/[email protected]/Suggested-by Salil Mehta <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/acpi/bus.c | 11 +++++++++++ drivers/acpi/scan.c | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-)Index:
linux-pm/drivers/acpi/bus.c
===================================================================drivers/acpi/bus.c +0
-0@@ -112,6 +112,17 @@ int acpi_bus_get_status(struct acpi_deviif (ACPI_FAILURE (status))return -ENODEV ;
Quoted 12 lines
drivers/acpi/bus.c int acpi_bus_get_status(struct acpi_devi · line 122
Quoted 10 lines
drivers/acpi/bus.c +6
-0+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 enabled bit as
drivers/acpi/bus.c +2
-0+* well to avoid attempting to use the device. +*/ seems that this comment is for the line above?
No, I meant "functional" and wrote "enabled". Not sure why really.
Quoted 25 lines
Quoted 24 lines
drivers/acpi/bus.c +3
-0+ device->status.functional =0 ; + } +acpi_set_device_status (device, sta);if (device->status.functional && !device->status.present) {Index:
linux-pm/drivers/acpi/scan.c
===================================================================drivers/acpi/scan.c +1
-1@@ -1962,7 +1962,7 @@ bool acpi_device_is_present(const structbool 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,
Quoted 7 lines · On Fri, 26 Apr 2024 18:56:21 +0200 "Rafael J. Wysocki" <[email protected]>…
From: Rafael J. Wysocki <[email protected]>
The return value of
_STAwith 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_STAreturn values.
Quoted 8 lines
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.
Seems a sensible tidying up. Hopefully nothing was relying on this looser behavior. One trivial thing inline.
Quoted 11 lines
--- drivers/acpi/bus.c | 11 +++++++++++ drivers/acpi/scan.c | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-)Index:
linux-pm/drivers/acpi/bus.c
===================================================================drivers/acpi/bus.c +0
-0@@ -112,6 +112,17 @@ int acpi_bus_get_status(struct acpi_deviif (ACPI_FAILURE (status))
drivers/acpi/bus.c int acpi_bus_get_status(struct acpi_devi · line 122
Quoted 10 lines
drivers/acpi/bus.c +8
-0return -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 enabled bit as +* well to avoid attempting to use the device. +*/
Comment seems to be in a slightly odd place. Perhaps one line earlier makes more sense? Or was the intent to mention functional here?
Quoted 22 lines
drivers/acpi/bus.c +3
-0+ device->status.functional =0 ; + } +acpi_set_device_status (device, sta);if (device->status.functional && !device->status.present) {Index:
linux-pm/drivers/acpi/scan.c
===================================================================drivers/acpi/scan.c +1
-1@@ -1962,7 +1962,7 @@ bool acpi_device_is_present(const structbool 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,
Rafael J. Wysocki
maintainerQuoted 15 lines · Jonathan Cameron
Quoted 11 lines · On Fri, 26 Apr 2024 18:56:21 +0200 "Rafael J. Wysocki" <[email protected]>…
From: Rafael J. Wysocki <[email protected]>
The return value of
_STAwith 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_STAreturn 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.
Quoted 8 lines
Quoted 4 lines
Seems a sensible tidying up. Hopefully nothing was relying on this looser behavior. One trivial thing inline.
Reviewed-by Jonathan Cameron <[email protected]>
Thanks!
Quoted 13 lines
Quoted 13 lines
--- drivers/acpi/bus.c | 11 +++++++++++ drivers/acpi/scan.c | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-)Index:
linux-pm/drivers/acpi/bus.c
===================================================================drivers/acpi/bus.c +0
-0@@ -112,6 +112,17 @@ int acpi_bus_get_status(struct acpi_deviif (ACPI_FAILURE (status))return -ENODEV ;
Quoted 11 lines
drivers/acpi/bus.c int acpi_bus_get_status(struct acpi_devi · line 122
Quoted 8 lines
drivers/acpi/bus.c +8
-0+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 enabled bit as +* well to avoid attempting to use the device. +*/ Comment seems to be in a slightly odd place. Perhaps one line earlier makes more sense? Or was the intent to mention functional here?
Rui has noticed this already.
I thought "functional" and wrote "enabled". Oh well, I'll send a v2.
Quoted 24 lines
Quoted 22 lines
drivers/acpi/bus.c +3
-0+ device->status.functional =0 ; + } +acpi_set_device_status (device, sta);if (device->status.functional && !device->status.present) {Index:
linux-pm/drivers/acpi/scan.c
===================================================================drivers/acpi/scan.c +1
-1@@ -1962,7 +1962,7 @@ bool acpi_device_is_present(const structbool 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,