Skip to contentSkip to conversation

hw/sparc/leon3: Fix wrong usage of DO_UPCAST macro

PATCH In review Thomas Huth 3 participants 6 messages Feb 21, 2024 – Feb 22, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/sparc/leon3: Fix wrong usage of DO_UPCAST macro

leon3.c currently fails to compile with some compilers when the -Wvla option has been enabled:

../hw/sparc/leon3.c: In function ‘leon3_cpu_reset’:
../hw/sparc/leon3.c:153:5: error: ISO C90 forbids variable length array
‘offset_must_be_zero’ [-Werror=vla]

   153 |     ResetData *s = (ResetData *)DO_UPCAST(ResetData, info[id], info);
       |     ^~~~~~~~~

cc1: all warnings being treated as errors

Looking at this code, the DO_UPCAST macro is indeed used in a wrong way
here: DO_UPCAST is supposed to check that the second parameter is the first entry of the struct that the first parameter indicates, but since we use and index into the info[] array, this of course cannot work.

The intention here was likely rather to use the container_of() macro instead, so switch the code accordingly.

---
 hw/sparc/leon3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/sparc/leon3.c +1 -1
index 4873b59b6c..6aaa04cb19 100644
@@ -150,7 +150,7 @@ static void leon3_cpu_reset(void *opaque)
 {
     struct CPUResetData *info = (struct CPUResetData *) opaque;
     int id = info->id;
-    ResetData *s = (ResetData *)DO_UPCAST(ResetData, info[id], info);
+    ResetData *s = container_of(info, ResetData, info[id]);
     CPUState *cpu = CPU(s->info[id].cpu);
     CPUSPARCState *env = cpu_env(cpu);
 
Signature · 1 line
2.43.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Thomas Huth

leon3.c currently fails to compile with some compilers when the -Wvla option has been enabled:

../hw/sparc/leon3.c: In function ‘leon3_cpu_reset’:
../hw/sparc/leon3.c:153:5: error: ISO C90 forbids variable length array
‘offset_must_be_zero’ [-Werror=vla]

    153 |     ResetData *s = (ResetData *)DO_UPCAST(ResetData, info[id], info);
        |     ^~~~~~~~~

cc1: all warnings being treated as errors

Looking at this code, the DO_UPCAST macro is indeed used in a wrong way
here: DO_UPCAST is supposed to check that the second parameter is the first entry of the struct that the first parameter indicates, but since we use and index into the info[] array, this of course cannot work.

Quoted 7 lines

The intention here was likely rather to use the container_of() macro instead, so switch the code accordingly.

---
  hw/sparc/leon3.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
#2 lore raw
Quoted 11 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Thomas Huth

leon3.c currently fails to compile with some compilers when the -Wvla option has been enabled:

  ../hw/sparc/leon3.c: In function ‘leon3_cpu_reset’:
  ../hw/sparc/leon3.c:153:5: error: ISO C90 forbids variable length array ‘offset_must_be_zero’ [-Werror=vla]
    153 |     ResetData *s = (ResetData *)DO_UPCAST(ResetData, info[id], info); |     ^~~~~~~~~
  cc1: all warnings being treated as errors

Quoted 7 lines
Quoted 7 lines

Looking at this code, the DO_UPCAST macro is indeed used in a wrong way
here: DO_UPCAST is supposed to check that the second parameter is the first entry of the struct that the first parameter indicates, but since we use and index into the info[] array, this of course cannot work.

The intention here was likely rather to use the container_of() macro instead, so switch the code accordingly.

Fixes d65aba8286 ("hw/sparc/leon3: implement multiprocessor")
Quoted 7 lines
Quoted 4 lines

---
  hw/sparc/leon3.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
#3 lore raw
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 16 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Thomas Huth

leon3.c currently fails to compile with some compilers when the -Wvla option has been enabled:

  ../hw/sparc/leon3.c: In function ‘leon3_cpu_reset’:
  ../hw/sparc/leon3.c:153:5: error: ISO C90 forbids variable length array ‘offset_must_be_zero’ [-Werror=vla]
    153 |     ResetData *s = (ResetData *)DO_UPCAST(ResetData, info[id], info); |     ^~~~~~~~~
  cc1: all warnings being treated as errors

Looking at this code, the DO_UPCAST macro is indeed used in a wrong way
here: DO_UPCAST is supposed to check that the second parameter is the first entry of the struct that the first parameter indicates, but since we use and index into the info[] array, this of course cannot work.

Quoted 12 lines
Quoted 2 lines
Quoted 2 lines

The intention here was likely rather to use the container_of() macro instead, so switch the code accordingly.

Fixes d65aba8286 ("hw/sparc/leon3: implement multiprocessor")
Quoted 7 lines
Quoted 4 lines

---
  hw/sparc/leon3.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)

Patch queued!

#4 lore raw

Hi Philippe, Thomas

Thanks for handling that !
And I do confirm that it does not trigger any obvious regression on our side.

Thanks,
Clément

Quoted 36 lines · Philippe Mathieu-Daudé
Quoted 19 lines · Philippe Mathieu-Daudé
Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Thomas Huth

leon3.c currently fails to compile with some compilers when the -Wvla option has been enabled:

../hw/sparc/leon3.c: In function ‘leon3_cpu_reset’:
../hw/sparc/leon3.c:153:5: error: ISO C90 forbids variable length
array
‘offset_must_be_zero’ [-Werror=vla]
153 | ResetData *s = (ResetData *)DO_UPCAST(ResetData,

info[id], info);
        |     ^~~~~~~~~

cc1: all warnings being treated as errors

Looking at this code, the DO_UPCAST macro is indeed used in a wrong way
here: DO_UPCAST is supposed to check that the second parameter is the first entry of the struct that the first parameter indicates, but since we use and index into the info[] array, this of course cannot work.

Quoted 12 lines
Quoted 2 lines
Quoted 2 lines

The intention here was likely rather to use the container_of() macro instead, so switch the code accordingly.

Fixes d65aba8286 ("hw/sparc/leon3: implement multiprocessor")
Quoted 7 lines
Quoted 4 lines
---
  hw/sparc/leon3.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Patch queued!

#5 lore raw
Quoted 4 lines · Clément Chigot

Hi Philippe, Thomas

Thanks for handling that !
And I do confirm that it does not trigger any obvious regression on our side.

Since I screwed my hw-misc pull request, I'll add your Tested-by to the commit before respin.

Quoted 42 lines

Thanks,
Clément

Quoted 36 lines · Philippe Mathieu-Daudé
Quoted 19 lines · Philippe Mathieu-Daudé
Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Thomas Huth

leon3.c currently fails to compile with some compilers when the -Wvla option has been enabled:

../hw/sparc/leon3.c: In function ‘leon3_cpu_reset’:
../hw/sparc/leon3.c:153:5: error: ISO C90 forbids variable length
array
‘offset_must_be_zero’ [-Werror=vla]
153 | ResetData *s = (ResetData *)DO_UPCAST(ResetData,

info[id], info);
         |     ^~~~~~~~~

cc1: all warnings being treated as errors

Looking at this code, the DO_UPCAST macro is indeed used in a wrong way
here: DO_UPCAST is supposed to check that the second parameter is the first entry of the struct that the first parameter indicates, but since we use and index into the info[] array, this of course cannot work.

Quoted 12 lines
Quoted 2 lines
Quoted 2 lines

The intention here was likely rather to use the container_of() macro instead, so switch the code accordingly.

Fixes d65aba8286 ("hw/sparc/leon3: implement multiprocessor")
Quoted 7 lines
Quoted 4 lines
---
   hw/sparc/leon3.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)

Patch queued!