Skip to contentSkip to conversation

mei: vsc: Fix wrong invocation of ACPI SID method

PATCH In review Hans de Goede 3 participants 5 messages Jun 3, 2024 – Jun 4, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mei: vsc: Fix wrong invocation of ACPI SID method

When using an initializer for a union only one of the union members must be initialized. The initializer for the acpi_object union variable passed as argument to the SID ACPI method was initializing both the type and the integer members of the union.

Unfortunately rather then complaining about this gcc simply ignores the first initializer and only used the second integer.value = 1 initializer. Leaving type set to 0 which leads to the argument being skipped by acpi acpi_ns_evaluate() resulting in:

ACPI Warning: \_SB.PC00.SPI1.SPFD.CVFD.SID: Insufficient arguments - Caller passed 0, method requires 1 (20240322/nsarguments-232)

Fix this by initializing only the integer struct part of the union and initializing both members of the integer struct.

---
Even though this is a one-liner, figuring out what was actually going wrong here took quite a while.

---
 drivers/misc/mei/vsc-fw-loader.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/mei/vsc-fw-loader.c +1 -1
index ffa4ccd96a10..596a9d695dfc 100644
@@ -252,7 +252,7 @@ static int vsc_get_sensor_name(struct vsc_fw_loader *fw_loader,
 {
 	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER };
 	union acpi_object obj = {
-		.type = ACPI_TYPE_INTEGER,
+		.integer.type = ACPI_TYPE_INTEGER,
 		.integer.value = 1,
 	};
 	struct acpi_object_list arg_list = {
Signature · 1 line
2.45.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Hans,

Thanks for the patch.

Quoted 13 lines · Hans de Goede

When using an initializer for a union only one of the union members must be initialized. The initializer for the acpi_object union variable passed as argument to the SID ACPI method was initializing both the type and the integer members of the union.

Unfortunately rather then complaining about this gcc simply ignores the first initializer and only used the second integer.value = 1 initializer. Leaving type set to 0 which leads to the argument being skipped by acpi acpi_ns_evaluate() resulting in:

ACPI Warning: \_SB.PC00.SPI1.SPFD.CVFD.SID: Insufficient arguments - Caller passed 0, method requires 1 (20240322/nsarguments-232)

Quoted 7 lines

Fix this by initializing only the integer struct part of the union and initializing both members of the integer struct.

---
Even though this is a one-liner, figuring out what was actually going wrong here took quite a while.

I was wondering this with Wentong, too...!

Quoted 9 lines
---
 drivers/misc/mei/vsc-fw-loader.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/mei/vsc-fw-loader.c +0 -0
index ffa4ccd96a10..596a9d695dfc 100644

drivers/misc/mei/vsc-fw-loader.c static int vsc_get_sensor_name(struct vsc_fw_loader *fw_loader, · line 256

Quoted 6 lines
drivers/misc/mei/vsc-fw-loader.c +1 -1
@@ -252,7 +252,7 @@ static int vsc_get_sensor_name(struct vsc_fw_loader *fw_loader,
 {
 	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER };
 	union acpi_object obj = {
-		.type = ACPI_TYPE_INTEGER,
+		.integer.type = ACPI_TYPE_INTEGER,
 		.integer.value = 1,

I guess initialising integer.value implies that all integer fields are set to zero (and so zeroing type set the line above)? Maybe moving setting type below setting integer.value might do the trick as well? ;-)

It'd be useful to be warned by the compiler in such a case. There are much less useful warnings out there.

Excellent finding indeed.

This could be cc'd to stable, this warning will display for a lot of systems. I.e. I think:

Fixes 566f5ca97680 ("mei: Add transport driver for IVSC device")
Cc [email protected] # for 6.8 and later
Quoted 2 lines
drivers/misc/mei/vsc-fw-loader.c +0 -0
 	};
 	struct acpi_object_list arg_list = {
Signature · 3 lines
Kind regards,

Sakari Ailus
#2 lore raw

Hi,

Quoted 32 lines · Sakari Ailus

Hi Hans,

Thanks for the patch.

Quoted 13 lines · Hans de Goede

When using an initializer for a union only one of the union members must be initialized. The initializer for the acpi_object union variable passed as argument to the SID ACPI method was initializing both the type and the integer members of the union.

Unfortunately rather then complaining about this gcc simply ignores the first initializer and only used the second integer.value = 1 initializer. Leaving type set to 0 which leads to the argument being skipped by acpi acpi_ns_evaluate() resulting in:

ACPI Warning: \_SB.PC00.SPI1.SPFD.CVFD.SID: Insufficient arguments - Caller passed 0, method requires 1 (20240322/nsarguments-232)

Quoted 7 lines

Fix this by initializing only the integer struct part of the union and initializing both members of the integer struct.

---
Even though this is a one-liner, figuring out what was actually going wrong here took quite a while.

I was wondering this with Wentong, too...!

Quoted 4 lines
---
 drivers/misc/mei/vsc-fw-loader.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines

drivers/misc/mei/vsc-fw-loader.c static int vsc_get_sensor_name(struct vsc_fw_loader *fw_loader, · line 256

Quoted 11 lines
drivers/misc/mei/vsc-fw-loader.c +1 -1
index ffa4ccd96a10..596a9d695dfc 100644
@@ -252,7 +252,7 @@ static int vsc_get_sensor_name(struct vsc_fw_loader *fw_loader,
 {
 	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER };
 	union acpi_object obj = {
-		.type = ACPI_TYPE_INTEGER,
+		.integer.type = ACPI_TYPE_INTEGER,
 		.integer.value = 1,

I guess initialising integer.value implies that all integer fields are set to zero (and so zeroing type set the line above)?

Yes I was thinking that might be happening too.

Quoted 2 lines

Maybe moving setting type
below setting integer.value might do the trick as well? ;-)

I was wondering the same thing, but that seems error-prone / something which may break with different compiler versions.

Actually most code using union acpi_object variables simply does not initialize them at declaration time.

So I was also considering to maybe change the code like this:

        struct acpi_object_list arg_list;
        union acpi_object *ret_obj;
        union acpi_object param;

	...

        param.type = ACPI_TYPE_INTEGER;
        param.integer.value = 1;

        arg_list.count = 1;
        arg_list.pointer = &param;

        status = acpi_evaluate_object(handle, "SID", &arg_list, &buffer);

Slightly more verbose, but this is basically what all other callers of acpi_evaluate_object() (with a non NULL arg_list) do.

Quoted 2 lines

It'd be useful to be warned by the compiler in such a case. There are much less useful warnings out there.

Ack.

Quoted 9 lines

Excellent finding indeed.

This could be cc'd to stable, this warning will display for a lot of systems. I.e. I think:

Fixes 566f5ca97680 ("mei: Add transport driver for IVSC device")
Cc [email protected] # for 6.8 and later

Ack.

Regards,

Hans

Quoted 3 lines
Quoted 2 lines
drivers/misc/mei/vsc-fw-loader.c +0 -0
 	};
 	struct acpi_object_list arg_list = {
#3 lore raw

Hi Hans,

Quoted 50 lines · Hans de Goede

Hi,

Quoted 32 lines · Sakari Ailus

Hi Hans,

Thanks for the patch.

Quoted 13 lines · Hans de Goede

When using an initializer for a union only one of the union members must be initialized. The initializer for the acpi_object union variable passed as argument to the SID ACPI method was initializing both the type and the integer members of the union.

Unfortunately rather then complaining about this gcc simply ignores the first initializer and only used the second integer.value = 1 initializer. Leaving type set to 0 which leads to the argument being skipped by acpi acpi_ns_evaluate() resulting in:

ACPI Warning: \_SB.PC00.SPI1.SPFD.CVFD.SID: Insufficient arguments - Caller passed 0, method requires 1 (20240322/nsarguments-232)

Quoted 7 lines

Fix this by initializing only the integer struct part of the union and initializing both members of the integer struct.

---
Even though this is a one-liner, figuring out what was actually going wrong here took quite a while.

I was wondering this with Wentong, too...!

Quoted 4 lines
---
 drivers/misc/mei/vsc-fw-loader.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines

drivers/misc/mei/vsc-fw-loader.c static int vsc_get_sensor_name(struct vsc_fw_loader *fw_loader, · line 256

Quoted 11 lines
drivers/misc/mei/vsc-fw-loader.c +1 -1
index ffa4ccd96a10..596a9d695dfc 100644
@@ -252,7 +252,7 @@ static int vsc_get_sensor_name(struct vsc_fw_loader *fw_loader,
 {
 	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER };
 	union acpi_object obj = {
-		.type = ACPI_TYPE_INTEGER,
+		.integer.type = ACPI_TYPE_INTEGER,
 		.integer.value = 1,

I guess initialising integer.value implies that all integer fields are set to zero (and so zeroing type set the line above)?

Quoted 7 lines

Yes I was thinking that might be happening too.

Quoted 2 lines

Maybe moving setting type
below setting integer.value might do the trick as well? ;-)

I was wondering the same thing, but that seems error-prone / something which may break with different compiler versions.

Yes, I didn't actually mean to suggest this.

Quoted 20 lines

Actually most code using union acpi_object variables simply does not initialize them at declaration time.

So I was also considering to maybe change the code like this:

        struct acpi_object_list arg_list;
        union acpi_object *ret_obj;
        union acpi_object param;

	...

        param.type = ACPI_TYPE_INTEGER;
        param.integer.value = 1;

        arg_list.count = 1;
        arg_list.pointer = &param;

        status = acpi_evaluate_object(handle, "SID", &arg_list, &buffer);
Quoted 2 lines

Slightly more verbose, but this is basically what all other callers of acpi_evaluate_object() (with a non NULL arg_list) do.

I prefer your current patch actually, it's good as-is.

Quoted 17 lines
Quoted 3 lines

It'd be useful to be warned by the compiler in such a case. There are much less useful warnings out there.

Ack.

Quoted 9 lines

Excellent finding indeed.

This could be cc'd to stable, this warning will display for a lot of systems. I.e. I think:

Fixes 566f5ca97680 ("mei: Add transport driver for IVSC device")
Cc [email protected] # for 6.8 and later

Ack.

Signature · 3 lines
Kind regards,

Sakari Ailus
Reviewed-by on v1 1/1
#4 lore raw
In reply to Hans de Goede
Quoted 12 lines

From: Hans de Goede <[email protected]>

When using an initializer for a union only one of the union members must be initialized. The initializer for the acpi_object union variable passed as argument to the SID ACPI method was initializing both the type and the integer members of the union.

Unfortunately rather then complaining about this gcc simply ignores the first initializer and only used the second integer.value = 1 initializer. Leaving type set to 0 which leads to the argument being skipped by acpi acpi_ns_evaluate() resulting in:

Quoted 7 lines

ACPI Warning: \_SB.PC00.SPI1.SPFD.CVFD.SID: Insufficient arguments - Caller passed 0, method requires 1 (20240322/nsarguments-232)

Fix this by initializing only the integer struct part of the union and initializing both members of the integer struct.

Quoted 3 lines

---
Even though this is a one-liner, figuring out what was actually going wrong here took quite a while.

Thanks a lot

BR,
Wentong

Quoted 20 lines
---
 drivers/misc/mei/vsc-fw-loader.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/mei/vsc-fw- renamed from drivers/misc/mei/vsc-fw-loader.c +0 -0

loader.c
index ffa4ccd96a10..596a9d695dfc 100644

drivers/misc/mei/vsc-fw-loader.c +1 -2
@@ -252,7 +252,7 @@ static int vsc_get_sensor_name(struct vsc_fw_loader
 *fw_loader,  {
 	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER };
 	union acpi_object obj = {
-		.type = ACPI_TYPE_INTEGER,
+		.integer.type = ACPI_TYPE_INTEGER,
 		.integer.value = 1,
 	};
 	struct acpi_object_list arg_list = {
--

2.45.1