* [PATCH] hw/sparc/leon3: Fix wrong usage of DO_UPCAST macro
@ 2024-02-21 18:07 Thomas Huth
2024-02-21 18:47 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 6+ messages in thread
From: Thomas Huth @ 2024-02-21 18:07 UTC (permalink / raw)
To: Clément Chigot, Frederic Konrad, qemu-devel
Cc: Mark Cave-Ayland, Artyom Tarasenko, Philippe Mathieu-Daudé,
Peter Maydell
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.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
hw/sparc/leon3.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
index 4873b59b6c..6aaa04cb19 100644
--- a/hw/sparc/leon3.c
+++ b/hw/sparc/leon3.c
@@ -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);
--
2.43.2
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] hw/sparc/leon3: Fix wrong usage of DO_UPCAST macro
2024-02-21 18:07 [PATCH] hw/sparc/leon3: Fix wrong usage of DO_UPCAST macro Thomas Huth
@ 2024-02-21 18:47 ` Philippe Mathieu-Daudé
2024-02-21 18:49 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-02-21 18:47 UTC (permalink / raw)
To: Thomas Huth, Clément Chigot, Frederic Konrad, qemu-devel
Cc: Mark Cave-Ayland, Artyom Tarasenko, Peter Maydell
On 21/2/24 19:07, Thomas Huth wrote:
> 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.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> hw/sparc/leon3.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] hw/sparc/leon3: Fix wrong usage of DO_UPCAST macro
2024-02-21 18:47 ` Philippe Mathieu-Daudé
@ 2024-02-21 18:49 ` Philippe Mathieu-Daudé
2024-02-22 7:46 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-02-21 18:49 UTC (permalink / raw)
To: Thomas Huth, Clément Chigot, Frederic Konrad, qemu-devel
Cc: Mark Cave-Ayland, Artyom Tarasenko, Peter Maydell
On 21/2/24 19:47, Philippe Mathieu-Daudé wrote:
> On 21/2/24 19:07, Thomas Huth wrote:
>> 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.
Fixes: d65aba8286 ("hw/sparc/leon3: implement multiprocessor")
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>> hw/sparc/leon3.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] hw/sparc/leon3: Fix wrong usage of DO_UPCAST macro
2024-02-21 18:49 ` Philippe Mathieu-Daudé
@ 2024-02-22 7:46 ` Philippe Mathieu-Daudé
2024-02-22 8:26 ` Clément Chigot
0 siblings, 1 reply; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-02-22 7:46 UTC (permalink / raw)
To: Thomas Huth, Clément Chigot, Frederic Konrad, qemu-devel
Cc: Mark Cave-Ayland, Artyom Tarasenko, Peter Maydell
On 21/2/24 19:49, Philippe Mathieu-Daudé wrote:
> On 21/2/24 19:47, Philippe Mathieu-Daudé wrote:
>> On 21/2/24 19:07, Thomas Huth wrote:
>>> 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.
>
> Fixes: d65aba8286 ("hw/sparc/leon3: implement multiprocessor")
>
>>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>>> ---
>>> hw/sparc/leon3.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>>
Patch queued!
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] hw/sparc/leon3: Fix wrong usage of DO_UPCAST macro
2024-02-22 7:46 ` Philippe Mathieu-Daudé
@ 2024-02-22 8:26 ` Clément Chigot
2024-02-22 11:27 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 6+ messages in thread
From: Clément Chigot @ 2024-02-22 8:26 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Thomas Huth, Frederic Konrad, qemu-devel, Mark Cave-Ayland,
Artyom Tarasenko, Peter Maydell
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
On Thu, Feb 22, 2024 at 8:46 AM Philippe Mathieu-Daudé
<philmd@linaro.org> wrote:
>
> On 21/2/24 19:49, Philippe Mathieu-Daudé wrote:
> > On 21/2/24 19:47, Philippe Mathieu-Daudé wrote:
> >> On 21/2/24 19:07, Thomas Huth wrote:
> >>> 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.
> >
> > Fixes: d65aba8286 ("hw/sparc/leon3: implement multiprocessor")
> >
> >>> Signed-off-by: Thomas Huth <thuth@redhat.com>
> >>> ---
> >>> hw/sparc/leon3.c | 2 +-
> >>> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> >>
>
> Patch queued!
>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] hw/sparc/leon3: Fix wrong usage of DO_UPCAST macro
2024-02-22 8:26 ` Clément Chigot
@ 2024-02-22 11:27 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-02-22 11:27 UTC (permalink / raw)
To: Clément Chigot
Cc: Thomas Huth, Frederic Konrad, qemu-devel, Mark Cave-Ayland,
Artyom Tarasenko, Peter Maydell
On 22/2/24 09:26, Clément Chigot wrote:
> 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.
>
> Thanks,
> Clément
>
> On Thu, Feb 22, 2024 at 8:46 AM Philippe Mathieu-Daudé
> <philmd@linaro.org> wrote:
>>
>> On 21/2/24 19:49, Philippe Mathieu-Daudé wrote:
>>> On 21/2/24 19:47, Philippe Mathieu-Daudé wrote:
>>>> On 21/2/24 19:07, Thomas Huth wrote:
>>>>> 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.
>>>
>>> Fixes: d65aba8286 ("hw/sparc/leon3: implement multiprocessor")
>>>
>>>>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>>>>> ---
>>>>> hw/sparc/leon3.c | 2 +-
>>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>>>>
>>
>> Patch queued!
>>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-02-22 11:28 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-21 18:07 [PATCH] hw/sparc/leon3: Fix wrong usage of DO_UPCAST macro Thomas Huth
2024-02-21 18:47 ` Philippe Mathieu-Daudé
2024-02-21 18:49 ` Philippe Mathieu-Daudé
2024-02-22 7:46 ` Philippe Mathieu-Daudé
2024-02-22 8:26 ` Clément Chigot
2024-02-22 11:27 ` Philippe Mathieu-Daudé
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).