From: Jan Beulich <jbeulich@suse.com>
To: Luca Fancellu <Luca.Fancellu@arm.com>
Cc: "consulting @ bugseng . com" <consulting@bugseng.com>,
Nicola Vetrini <nicola.vetrini@bugseng.com>,
Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>,
Bertrand Marquis <Bertrand.Marquis@arm.com>,
Michal Orzel <michal.orzel@amd.com>,
Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH 2/2] xen/arm: Fix MISRA regression on R1.1, flexible array member not at the end
Date: Thu, 2 May 2024 11:53:27 +0200 [thread overview]
Message-ID: <4fee2998-e29b-43bb-855a-8600dbef9f13@suse.com> (raw)
In-Reply-To: <2DF15520-B0A4-4972-92F6-FCB6BB852292@arm.com>
On 02.05.2024 10:13, Luca Fancellu wrote:
>
>
>> On 2 May 2024, at 07:43, Jan Beulich <jbeulich@suse.com> wrote:
>>
>> On 02.05.2024 08:33, Luca Fancellu wrote:
>>>
>>>
>>>> On 2 May 2024, at 07:14, Jan Beulich <jbeulich@suse.com> wrote:
>>>>
>>>> On 01.05.2024 08:57, Luca Fancellu wrote:
>>>>> Hi Jan,
>>>>>
>>>>>> On 30 Apr 2024, at 12:37, Jan Beulich <jbeulich@suse.com> wrote:
>>>>>>
>>>>>> On 30.04.2024 13:09, Luca Fancellu wrote:
>>>>>>> --- a/xen/arch/arm/include/asm/setup.h
>>>>>>> +++ b/xen/arch/arm/include/asm/setup.h
>>>>>>> @@ -64,18 +64,20 @@ struct membank {
>>>>>>> };
>>>>>>>
>>>>>>> struct membanks {
>>>>>>> - unsigned int nr_banks;
>>>>>>> - unsigned int max_banks;
>>>>>>> + __struct_group(membanks_hdr, common, ,
>>>>>>> + unsigned int nr_banks;
>>>>>>> + unsigned int max_banks;
>>>>>>> + );
>>>>>>> struct membank bank[];
>>>>>>> };
>>>>>>
>>>>>> I'm afraid I can't spot why __struct_group() is needed here. Why would just
>>>>>> one of the two more straightforward
>>>>>>
>>>>>> struct membanks {
>>>>>> struct membanks_hdr {
>>>>>> unsigned int nr_banks;
>>>>>> unsigned int max_banks;
>>>>>> );
>>>>>> struct membank bank[];
>>>>>> };
>>>>>>
>>>>>
>>>>> At the first sight I thought this solution could have worked, however GCC brought me back down to earth
>>>>> remembering me that flexible array members can’t be left alone in an empty structure:
>>>>>
>>>>> /data_sdc/lucfan01/gitlab_mickledore_xen/xen/xen/arch/arm/include/asm/setup.h:70:6: error: declaration does not declare anything [-Werror]
>>>>> 70 | };
>>>>> | ^
>>>>> /data_sdc/lucfan01/gitlab_mickledore_xen/xen/xen/arch/arm/include/asm/setup.h:71:20: error: flexible array member in a struct with no named members
>>>>> 71 | struct membank bank[];
>>>>> | ^~~~
>>>>> [...]
>>>>
>>>> Since for patch 1 you looked at Linux'es uapi/linux/stddef.h, the solution
>>>> to this lies there, in __DECLARE_FLEX_ARRAY(). Alongside or instead of
>>>> borrowing __struct_group(), we could consider borrowing this as well. Or
>>>> open-code it just here, for the time being (perhaps my preference). Yet
>>>> it's not clear to me that doing so will actually be enough to make things
>>>> work for you.
>>>
>>> I looked also into __DECLARE_FLEX_ARRAY(), but then decided __struct_group()
>>> was enough for my purpose, can I ask the technical reasons why it would be your
>>> preference? Is there something in that construct that is a concern for you?
>>
>> I don't like either construct very much, but of the two __DECLARE_FLEX_ARRAY()
>> looks slightly more "natural" for what is wanted and how it's done.
>> __struct_group() introducing twice the (effectively) same structure feels
>> pretty odd, for now at least. It's not even entirely clear to me whether there
>> aren't pitfalls, seeing that the C spec differentiates named and unnamed
>> struct fields in a few cases. For __DECLARE_FLEX_ARRAY(), otoh, I can't
>> presently see any reason to suspect possible corner cases.
>>
>> Yet as said before - I'm not sure __DECLARE_FLEX_ARRAY() alone would be enough
>> for what you want to achieve.
>
> Mmm yes, I think I would still have problems because container_of wants a named member,
> so __DECLARE_FLEX_ARRAY() doesn’t help much alone, if I’m not missing something obvious.
> If you believe however that importing __struct_group() only for this instance is not enough to justify
> its presence in the codebase, I could open-code it, provided that maintainers are ok with that.
I'm afraid I've even more strongly against open-coding. If you can get an
ack from another maintainer for the introduction of struct_group(), that
would still allow it to go in. I didn't NAK the change, I merely have
reservations.
> In any case it would be used soon also for other architectures using bootinfo.
Oh, would it?
Jan
next prev parent reply other threads:[~2024-05-02 9:53 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-30 11:09 [PATCH 0/2] Fix MISRA regression about flexible array member not at the end Luca Fancellu
2024-04-30 11:09 ` [PATCH 1/2] xen/kernel.h: Import __struct_group from Linux Luca Fancellu
2024-04-30 11:43 ` Jan Beulich
2024-05-01 6:54 ` Luca Fancellu
2024-05-02 6:09 ` Jan Beulich
2024-05-02 6:23 ` Luca Fancellu
2024-05-02 6:38 ` Jan Beulich
2024-05-02 18:23 ` Stefano Stabellini
2024-04-30 11:09 ` [PATCH 2/2] xen/arm: Fix MISRA regression on R1.1, flexible array member not at the end Luca Fancellu
2024-04-30 11:37 ` Jan Beulich
2024-05-01 6:57 ` Luca Fancellu
2024-05-02 6:14 ` Jan Beulich
2024-05-02 6:33 ` Luca Fancellu
2024-05-02 6:43 ` Jan Beulich
2024-05-02 8:13 ` Luca Fancellu
2024-05-02 9:53 ` Jan Beulich [this message]
2024-05-02 10:12 ` Luca Fancellu
2024-05-02 10:30 ` Jan Beulich
2024-05-02 10:42 ` Luca Fancellu
2024-04-30 12:55 ` Nicola Vetrini
2024-05-02 18:35 ` Stefano Stabellini
2024-05-08 16:18 ` Luca Fancellu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4fee2998-e29b-43bb-855a-8600dbef9f13@suse.com \
--to=jbeulich@suse.com \
--cc=Bertrand.Marquis@arm.com \
--cc=Luca.Fancellu@arm.com \
--cc=Volodymyr_Babchuk@epam.com \
--cc=consulting@bugseng.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=nicola.vetrini@bugseng.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.