public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] acpi: zero-initialize acpi_object union structure
@ 2024-10-17  3:59 Payam Moradshahi
  2024-10-21 11:31 ` Rafael J. Wysocki
  0 siblings, 1 reply; 4+ messages in thread
From: Payam Moradshahi @ 2024-10-17  3:59 UTC (permalink / raw)
  To: Rafael J . Wysocki, Len Brown; +Cc: linux-acpi, linux-kernel, Payam Moradshahi

The way in which acpi_object union is being initialized varies based on
compiler type, version and flags used. Some will zero-initialize the
entire union structure and some will only initialize the first N-bytes
of the union structure. This could lead to uninitialized union members.

This bug was confirmed by observing non-zero value for object->processor
structure variables.

non-zero initialized members of acpi_object union structure causes
incorrect error reporting by the driver.

If a BIOS is using "Device" statement as opposed to "Processor"
statement, object variable may contain uninitialized members causing the
driver to report "Invalid PBLK length" incorrectly.

Using memset to zero-initialize the union structure fixes this issue and
also removes the dependency of this function on compiler versions and
flags being used.

Tested: Tested on ARM64 hardware that was printing this error and
confirmed the prints were gone.

Also confirmed this does not cause regression on ARM64 and X86
machines.

Signed-off-by: Payam Moradshahi <payamm@google.com>
---
 drivers/acpi/acpi_processor.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c
index 7cf6101cb4c73..6696ad4937d21 100644
--- a/drivers/acpi/acpi_processor.c
+++ b/drivers/acpi/acpi_processor.c
@@ -275,7 +275,7 @@ static inline int acpi_processor_hotadd_init(struct acpi_processor *pr,
 
 static int acpi_processor_get_info(struct acpi_device *device)
 {
-	union acpi_object object = { 0 };
+	union acpi_object object;
 	struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
 	struct acpi_processor *pr = acpi_driver_data(device);
 	int device_declaration = 0;
@@ -284,6 +284,8 @@ static int acpi_processor_get_info(struct acpi_device *device)
 	unsigned long long value;
 	int ret;
 
+	memset(&object, 0, sizeof(union acpi_object));
+
 	acpi_processor_errata();
 
 	/*
-- 
2.47.0.rc1.288.g06298d1525-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-10-25 17:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-17  3:59 [PATCH] acpi: zero-initialize acpi_object union structure Payam Moradshahi
2024-10-21 11:31 ` Rafael J. Wysocki
2024-10-24 21:58   ` Payam Moradshahi
2024-10-25 17:29     ` Moritz Fischer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox