diff mbox series

[XEN,for-4.19,v4] xen: address violations of Rule 11.9

Message ID b8a82daf5862287bda9545d7e672ce98e49004a2.1697701358.git.nicola.vetrini@bugseng.com (mailing list archive)
State New, archived
Headers show
Series [XEN,for-4.19,v4] xen: address violations of Rule 11.9 | expand

Commit Message

Nicola Vetrini Oct. 19, 2023, 7:55 a.m. UTC
The constant 0 is used instead of NULL in '__ACCESS_ONCE' as a
compile-time check to detect non-scalar types; its usage for this
purpose is deviated.

Furthermore, the 'typeof_field' macro is introduced as a general way
to access the type of a struct member without declaring a variable
of struct type. Both this macro and 'sizeof_field' are moved to
'xen/macros.h'.

No functional change intended.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
Changes in v2:
- added entry in deviations.rst
Changes in v3:
- dropped access_field
- moved macro to macros.h
---
Changes in v4:
- Amend deviation record.
---
 automation/eclair_analysis/ECLAIR/deviations.ecl |  9 +++++++++
 docs/misra/deviations.rst                        |  6 ++++++
 xen/include/xen/compiler.h                       |  8 --------
 xen/include/xen/kernel.h                         |  2 +-
 xen/include/xen/macros.h                         | 16 ++++++++++++++++
 5 files changed, 32 insertions(+), 9 deletions(-)

--
2.34.1

Comments

Nicola Vetrini Nov. 6, 2023, 2:24 p.m. UTC | #1
On 2023-10-19 09:55, Nicola Vetrini wrote:
> The constant 0 is used instead of NULL in '__ACCESS_ONCE' as a
> compile-time check to detect non-scalar types; its usage for this
> purpose is deviated.
> 
> Furthermore, the 'typeof_field' macro is introduced as a general way
> to access the type of a struct member without declaring a variable
> of struct type. Both this macro and 'sizeof_field' are moved to
> 'xen/macros.h'.
> 
> No functional change intended.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> ---
> Changes in v2:
> - added entry in deviations.rst
> Changes in v3:
> - dropped access_field
> - moved macro to macros.h
> ---
> Changes in v4:
> - Amend deviation record.
> ---

This patch has received some R-by-s, but no acks at the moment.
Perhaps at least one is needed to get this into 4.19?
Jan Beulich Nov. 6, 2023, 2:27 p.m. UTC | #2
On 06.11.2023 15:24, Nicola Vetrini wrote:
> On 2023-10-19 09:55, Nicola Vetrini wrote:
>> The constant 0 is used instead of NULL in '__ACCESS_ONCE' as a
>> compile-time check to detect non-scalar types; its usage for this
>> purpose is deviated.
>>
>> Furthermore, the 'typeof_field' macro is introduced as a general way
>> to access the type of a struct member without declaring a variable
>> of struct type. Both this macro and 'sizeof_field' are moved to
>> 'xen/macros.h'.
>>
>> No functional change intended.
>>
>> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
>> Reviewed-by: Jan Beulich <jbeulich@suse.com>
>> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
>> ---
>> Changes in v2:
>> - added entry in deviations.rst
>> Changes in v3:
>> - dropped access_field
>> - moved macro to macros.h
>> ---
>> Changes in v4:
>> - Amend deviation record.
>> ---
> 
> This patch has received some R-by-s, but no acks at the moment.
> Perhaps at least one is needed to get this into 4.19?

I didn't think it does, and I have it marked as ready to go in. But
from an earlier email from Stefano I inferred that it might be
preferable to commit larger sets of Misra changes only once the tree
is fully open again.

Jan
Nicola Vetrini Nov. 6, 2023, 2:30 p.m. UTC | #3
On 2023-11-06 15:27, Jan Beulich wrote:
> On 06.11.2023 15:24, Nicola Vetrini wrote:
>> On 2023-10-19 09:55, Nicola Vetrini wrote:
>>> The constant 0 is used instead of NULL in '__ACCESS_ONCE' as a
>>> compile-time check to detect non-scalar types; its usage for this
>>> purpose is deviated.
>>> 
>>> Furthermore, the 'typeof_field' macro is introduced as a general way
>>> to access the type of a struct member without declaring a variable
>>> of struct type. Both this macro and 'sizeof_field' are moved to
>>> 'xen/macros.h'.
>>> 
>>> No functional change intended.
>>> 
>>> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
>>> Reviewed-by: Jan Beulich <jbeulich@suse.com>
>>> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
>>> ---
>>> Changes in v2:
>>> - added entry in deviations.rst
>>> Changes in v3:
>>> - dropped access_field
>>> - moved macro to macros.h
>>> ---
>>> Changes in v4:
>>> - Amend deviation record.
>>> ---
>> 
>> This patch has received some R-by-s, but no acks at the moment.
>> Perhaps at least one is needed to get this into 4.19?
> 
> I didn't think it does, and I have it marked as ready to go in. But
> from an earlier email from Stefano I inferred that it might be
> preferable to commit larger sets of Misra changes only once the tree
> is fully open again.
> 
> Jan

Ok, thanks for the clarification.
Jan Beulich Nov. 13, 2023, 2:09 p.m. UTC | #4
On 19.10.2023 09:55, Nicola Vetrini wrote:
> The constant 0 is used instead of NULL in '__ACCESS_ONCE' as a
> compile-time check to detect non-scalar types; its usage for this
> purpose is deviated.
> 
> Furthermore, the 'typeof_field' macro is introduced as a general way
> to access the type of a struct member without declaring a variable
> of struct type. Both this macro and 'sizeof_field' are moved to
> 'xen/macros.h'.
> 
> No functional change intended.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> ---
> Changes in v2:
> - added entry in deviations.rst
> Changes in v3:
> - dropped access_field
> - moved macro to macros.h
> ---
> Changes in v4:
> - Amend deviation record.
> ---
>  automation/eclair_analysis/ECLAIR/deviations.ecl |  9 +++++++++
>  docs/misra/deviations.rst                        |  6 ++++++
>  xen/include/xen/compiler.h                       |  8 --------
>  xen/include/xen/kernel.h                         |  2 +-
>  xen/include/xen/macros.h                         | 16 ++++++++++++++++
>  5 files changed, 32 insertions(+), 9 deletions(-)

I tried to commit this patch, but ...

> diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl b/automation/eclair_analysis/ECLAIR/deviations.ecl
> index fa56e5c00a27..28d9c37bedb2 100644
> --- a/automation/eclair_analysis/ECLAIR/deviations.ecl
> +++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
> @@ -246,6 +246,15 @@ constant expressions are required.\""
>    "any()"}
>  -doc_end
> 
> +#
> +# Series 11
> +#
> +
> +-doc_begin="This construct is used to check if the type is scalar, and for this purpose the use of 0 as a null pointer constant is deliberate."
> +-config=MC3R1.R11.9,reports+={deliberate, "any_area(any_loc(any_exp(macro(^__ACCESS_ONCE$))))"
> +}
> +-doc_end
> +
>  #
>  # Series 13
>  #

... this change doesn't apply, and I also can't see how it would. There were
no dependencies specified, so it's also not clear on top of which other
(ready to be committed) patch(es) this might have been meant to apply. Please
resubmit in a shape applicable to the staging branch.

Jan
Stefano Stabellini Nov. 13, 2023, 11:58 p.m. UTC | #5
On Mon, 13 Nov 2023, Jan Beulich wrote:
> On 19.10.2023 09:55, Nicola Vetrini wrote:
> > The constant 0 is used instead of NULL in '__ACCESS_ONCE' as a
> > compile-time check to detect non-scalar types; its usage for this
> > purpose is deviated.
> > 
> > Furthermore, the 'typeof_field' macro is introduced as a general way
> > to access the type of a struct member without declaring a variable
> > of struct type. Both this macro and 'sizeof_field' are moved to
> > 'xen/macros.h'.
> > 
> > No functional change intended.
> > 
> > Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
> > Reviewed-by: Jan Beulich <jbeulich@suse.com>
> > Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> > ---
> > Changes in v2:
> > - added entry in deviations.rst
> > Changes in v3:
> > - dropped access_field
> > - moved macro to macros.h
> > ---
> > Changes in v4:
> > - Amend deviation record.
> > ---
> >  automation/eclair_analysis/ECLAIR/deviations.ecl |  9 +++++++++
> >  docs/misra/deviations.rst                        |  6 ++++++
> >  xen/include/xen/compiler.h                       |  8 --------
> >  xen/include/xen/kernel.h                         |  2 +-
> >  xen/include/xen/macros.h                         | 16 ++++++++++++++++
> >  5 files changed, 32 insertions(+), 9 deletions(-)
> 
> I tried to commit this patch, but ...
> 
> > diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl b/automation/eclair_analysis/ECLAIR/deviations.ecl
> > index fa56e5c00a27..28d9c37bedb2 100644
> > --- a/automation/eclair_analysis/ECLAIR/deviations.ecl
> > +++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
> > @@ -246,6 +246,15 @@ constant expressions are required.\""
> >    "any()"}
> >  -doc_end
> > 
> > +#
> > +# Series 11
> > +#
> > +
> > +-doc_begin="This construct is used to check if the type is scalar, and for this purpose the use of 0 as a null pointer constant is deliberate."
> > +-config=MC3R1.R11.9,reports+={deliberate, "any_area(any_loc(any_exp(macro(^__ACCESS_ONCE$))))"
> > +}
> > +-doc_end
> > +
> >  #
> >  # Series 13
> >  #
> 
> ... this change doesn't apply, and I also can't see how it would. There were
> no dependencies specified, so it's also not clear on top of which other
> (ready to be committed) patch(es) this might have been meant to apply. Please
> resubmit in a shape applicable to the staging branch.

The order doesn't matter in that file, you can place # Series 11 just
after # Series 10


diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl b/automation/eclair_analysis/ECLAIR/deviations.ecl
index d8170106b4..14c5134575 100644
--- a/automation/eclair_analysis/ECLAIR/deviations.ecl
+++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
@@ -274,6 +274,15 @@ still non-negative."
 -config=MC3R1.R10.1,etypes+={safe, "stmt(operator(logical)||node(conditional_operator||binary_conditional_operator))", "dst_type(ebool||boolean)"}
 -doc_end
 
+#
+# Series 11
+#
+
+-doc_begin="This construct is used to check if the type is scalar, and for this purpose the use of 0 as a null pointer constant is deliberate."
+-config=MC3R1.R11.9,reports+={deliberate, "any_area(any_loc(any_exp(macro(^__ACCESS_ONCE$))))"
+}
+-doc_end
+
 ### Set 3 ###
 
 #
Jan Beulich Nov. 14, 2023, 7:19 a.m. UTC | #6
On 14.11.2023 00:58, Stefano Stabellini wrote:
> On Mon, 13 Nov 2023, Jan Beulich wrote:
>> On 19.10.2023 09:55, Nicola Vetrini wrote:
>>> The constant 0 is used instead of NULL in '__ACCESS_ONCE' as a
>>> compile-time check to detect non-scalar types; its usage for this
>>> purpose is deviated.
>>>
>>> Furthermore, the 'typeof_field' macro is introduced as a general way
>>> to access the type of a struct member without declaring a variable
>>> of struct type. Both this macro and 'sizeof_field' are moved to
>>> 'xen/macros.h'.
>>>
>>> No functional change intended.
>>>
>>> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
>>> Reviewed-by: Jan Beulich <jbeulich@suse.com>
>>> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
>>> ---
>>> Changes in v2:
>>> - added entry in deviations.rst
>>> Changes in v3:
>>> - dropped access_field
>>> - moved macro to macros.h
>>> ---
>>> Changes in v4:
>>> - Amend deviation record.
>>> ---
>>>  automation/eclair_analysis/ECLAIR/deviations.ecl |  9 +++++++++
>>>  docs/misra/deviations.rst                        |  6 ++++++
>>>  xen/include/xen/compiler.h                       |  8 --------
>>>  xen/include/xen/kernel.h                         |  2 +-
>>>  xen/include/xen/macros.h                         | 16 ++++++++++++++++
>>>  5 files changed, 32 insertions(+), 9 deletions(-)
>>
>> I tried to commit this patch, but ...
>>
>>> diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl b/automation/eclair_analysis/ECLAIR/deviations.ecl
>>> index fa56e5c00a27..28d9c37bedb2 100644
>>> --- a/automation/eclair_analysis/ECLAIR/deviations.ecl
>>> +++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
>>> @@ -246,6 +246,15 @@ constant expressions are required.\""
>>>    "any()"}
>>>  -doc_end
>>>
>>> +#
>>> +# Series 11
>>> +#
>>> +
>>> +-doc_begin="This construct is used to check if the type is scalar, and for this purpose the use of 0 as a null pointer constant is deliberate."
>>> +-config=MC3R1.R11.9,reports+={deliberate, "any_area(any_loc(any_exp(macro(^__ACCESS_ONCE$))))"
>>> +}
>>> +-doc_end
>>> +
>>>  #
>>>  # Series 13
>>>  #
>>
>> ... this change doesn't apply, and I also can't see how it would. There were
>> no dependencies specified, so it's also not clear on top of which other
>> (ready to be committed) patch(es) this might have been meant to apply. Please
>> resubmit in a shape applicable to the staging branch.
> 
> The order doesn't matter in that file, you can place # Series 11 just
> after # Series 10

That would have been one of the possible guesses. Yet then ...

> --- a/automation/eclair_analysis/ECLAIR/deviations.ecl
> +++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
> @@ -274,6 +274,15 @@ still non-negative."
>  -config=MC3R1.R10.1,etypes+={safe, "stmt(operator(logical)||node(conditional_operator||binary_conditional_operator))", "dst_type(ebool||boolean)"}
>  -doc_end
>  
> +#
> +# Series 11
> +#
> +
> +-doc_begin="This construct is used to check if the type is scalar, and for this purpose the use of 0 as a null pointer constant is deliberate."
> +-config=MC3R1.R11.9,reports+={deliberate, "any_area(any_loc(any_exp(macro(^__ACCESS_ONCE$))))"
> +}
> +-doc_end
> +
>  ### Set 3 ###

... there is this grouping by sets as well.

Jan
Nicola Vetrini Nov. 14, 2023, 9:46 a.m. UTC | #7
On 2023-11-14 08:19, Jan Beulich wrote:
> On 14.11.2023 00:58, Stefano Stabellini wrote:
>> On Mon, 13 Nov 2023, Jan Beulich wrote:
>>> On 19.10.2023 09:55, Nicola Vetrini wrote:
>>>> The constant 0 is used instead of NULL in '__ACCESS_ONCE' as a
>>>> compile-time check to detect non-scalar types; its usage for this
>>>> purpose is deviated.
>>>> 
>>>> Furthermore, the 'typeof_field' macro is introduced as a general way
>>>> to access the type of a struct member without declaring a variable
>>>> of struct type. Both this macro and 'sizeof_field' are moved to
>>>> 'xen/macros.h'.
>>>> 
>>>> No functional change intended.
>>>> 
>>>> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
>>>> Reviewed-by: Jan Beulich <jbeulich@suse.com>
>>>> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
>>>> ---
>>>> Changes in v2:
>>>> - added entry in deviations.rst
>>>> Changes in v3:
>>>> - dropped access_field
>>>> - moved macro to macros.h
>>>> ---
>>>> Changes in v4:
>>>> - Amend deviation record.
>>>> ---
>>>>  automation/eclair_analysis/ECLAIR/deviations.ecl |  9 +++++++++
>>>>  docs/misra/deviations.rst                        |  6 ++++++
>>>>  xen/include/xen/compiler.h                       |  8 --------
>>>>  xen/include/xen/kernel.h                         |  2 +-
>>>>  xen/include/xen/macros.h                         | 16 
>>>> ++++++++++++++++
>>>>  5 files changed, 32 insertions(+), 9 deletions(-)
>>> 
>>> I tried to commit this patch, but ...
>>> 
>>>> diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl 
>>>> b/automation/eclair_analysis/ECLAIR/deviations.ecl
>>>> index fa56e5c00a27..28d9c37bedb2 100644
>>>> --- a/automation/eclair_analysis/ECLAIR/deviations.ecl
>>>> +++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
>>>> @@ -246,6 +246,15 @@ constant expressions are required.\""
>>>>    "any()"}
>>>>  -doc_end
>>>> 
>>>> +#
>>>> +# Series 11
>>>> +#
>>>> +
>>>> +-doc_begin="This construct is used to check if the type is scalar, 
>>>> and for this purpose the use of 0 as a null pointer constant is 
>>>> deliberate."
>>>> +-config=MC3R1.R11.9,reports+={deliberate, 
>>>> "any_area(any_loc(any_exp(macro(^__ACCESS_ONCE$))))"
>>>> +}
>>>> +-doc_end
>>>> +
>>>>  #
>>>>  # Series 13
>>>>  #
>>> 
>>> ... this change doesn't apply, and I also can't see how it would. 
>>> There were
>>> no dependencies specified, so it's also not clear on top of which 
>>> other
>>> (ready to be committed) patch(es) this might have been meant to 
>>> apply. Please
>>> resubmit in a shape applicable to the staging branch.
>> 
>> The order doesn't matter in that file, you can place # Series 11 just
>> after # Series 10
> 
> That would have been one of the possible guesses. Yet then ...
> 
>> --- a/automation/eclair_analysis/ECLAIR/deviations.ecl
>> +++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
>> @@ -274,6 +274,15 @@ still non-negative."
>>  -config=MC3R1.R10.1,etypes+={safe, 
>> "stmt(operator(logical)||node(conditional_operator||binary_conditional_operator))", 
>> "dst_type(ebool||boolean)"}
>>  -doc_end
>> 
>> +#
>> +# Series 11
>> +#
>> +
>> +-doc_begin="This construct is used to check if the type is scalar, 
>> and for this purpose the use of 0 as a null pointer constant is 
>> deliberate."
>> +-config=MC3R1.R11.9,reports+={deliberate, 
>> "any_area(any_loc(any_exp(macro(^__ACCESS_ONCE$))))"
>> +}
>> +-doc_end
>> +
>>  ### Set 3 ###
> 
> ... there is this grouping by sets as well.
> 

+Stefano

I think the culprit here is that this commit 699899f44d09
was never merged with 4.19. Is that correct? My own tree is rebased
against that.
Stefano Stabellini Nov. 14, 2023, 10:28 p.m. UTC | #8
On Tue, 14 Nov 2023, Nicola Vetrini wrote:
> On 2023-11-14 08:19, Jan Beulich wrote:
> > On 14.11.2023 00:58, Stefano Stabellini wrote:
> > > On Mon, 13 Nov 2023, Jan Beulich wrote:
> > > > On 19.10.2023 09:55, Nicola Vetrini wrote:
> > > > > The constant 0 is used instead of NULL in '__ACCESS_ONCE' as a
> > > > > compile-time check to detect non-scalar types; its usage for this
> > > > > purpose is deviated.
> > > > > 
> > > > > Furthermore, the 'typeof_field' macro is introduced as a general way
> > > > > to access the type of a struct member without declaring a variable
> > > > > of struct type. Both this macro and 'sizeof_field' are moved to
> > > > > 'xen/macros.h'.
> > > > > 
> > > > > No functional change intended.
> > > > > 
> > > > > Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
> > > > > Reviewed-by: Jan Beulich <jbeulich@suse.com>
> > > > > Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> > > > > ---
> > > > > Changes in v2:
> > > > > - added entry in deviations.rst
> > > > > Changes in v3:
> > > > > - dropped access_field
> > > > > - moved macro to macros.h
> > > > > ---
> > > > > Changes in v4:
> > > > > - Amend deviation record.
> > > > > ---
> > > > >  automation/eclair_analysis/ECLAIR/deviations.ecl |  9 +++++++++
> > > > >  docs/misra/deviations.rst                        |  6 ++++++
> > > > >  xen/include/xen/compiler.h                       |  8 --------
> > > > >  xen/include/xen/kernel.h                         |  2 +-
> > > > >  xen/include/xen/macros.h                         | 16
> > > > > ++++++++++++++++
> > > > >  5 files changed, 32 insertions(+), 9 deletions(-)
> > > > 
> > > > I tried to commit this patch, but ...
> > > > 
> > > > > diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl
> > > > > b/automation/eclair_analysis/ECLAIR/deviations.ecl
> > > > > index fa56e5c00a27..28d9c37bedb2 100644
> > > > > --- a/automation/eclair_analysis/ECLAIR/deviations.ecl
> > > > > +++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
> > > > > @@ -246,6 +246,15 @@ constant expressions are required.\""
> > > > >    "any()"}
> > > > >  -doc_end
> > > > > 
> > > > > +#
> > > > > +# Series 11
> > > > > +#
> > > > > +
> > > > > +-doc_begin="This construct is used to check if the type is scalar,
> > > > > and for this purpose the use of 0 as a null pointer constant is
> > > > > deliberate."
> > > > > +-config=MC3R1.R11.9,reports+={deliberate,
> > > > > "any_area(any_loc(any_exp(macro(^__ACCESS_ONCE$))))"
> > > > > +}
> > > > > +-doc_end
> > > > > +
> > > > >  #
> > > > >  # Series 13
> > > > >  #
> > > > 
> > > > ... this change doesn't apply, and I also can't see how it would. There
> > > > were
> > > > no dependencies specified, so it's also not clear on top of which other
> > > > (ready to be committed) patch(es) this might have been meant to apply.
> > > > Please
> > > > resubmit in a shape applicable to the staging branch.
> > > 
> > > The order doesn't matter in that file, you can place # Series 11 just
> > > after # Series 10
> > 
> > That would have been one of the possible guesses. Yet then ...
> > 
> > > --- a/automation/eclair_analysis/ECLAIR/deviations.ecl
> > > +++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
> > > @@ -274,6 +274,15 @@ still non-negative."
> > >  -config=MC3R1.R10.1,etypes+={safe,
> > > "stmt(operator(logical)||node(conditional_operator||binary_conditional_operator))",
> > > "dst_type(ebool||boolean)"}
> > >  -doc_end
> > > 
> > > +#
> > > +# Series 11
> > > +#
> > > +
> > > +-doc_begin="This construct is used to check if the type is scalar, and
> > > for this purpose the use of 0 as a null pointer constant is deliberate."
> > > +-config=MC3R1.R11.9,reports+={deliberate,
> > > "any_area(any_loc(any_exp(macro(^__ACCESS_ONCE$))))"
> > > +}
> > > +-doc_end
> > > +
> > >  ### Set 3 ###
> > 
> > ... there is this grouping by sets as well.
> > 
> 
> +Stefano
> 
> I think the culprit here is that this commit 699899f44d09
> was never merged with 4.19. Is that correct? My own tree is rebased
> against that.

699899f44d09 is "automation/eclair: update deviations and accepted
guidelines" and should go in.

I'll wait until the release which should be imminent and then commit
both commits (if Jan doesn't beat me to it)
diff mbox series

Patch

diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl b/automation/eclair_analysis/ECLAIR/deviations.ecl
index fa56e5c00a27..28d9c37bedb2 100644
--- a/automation/eclair_analysis/ECLAIR/deviations.ecl
+++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
@@ -246,6 +246,15 @@  constant expressions are required.\""
   "any()"}
 -doc_end

+#
+# Series 11
+#
+
+-doc_begin="This construct is used to check if the type is scalar, and for this purpose the use of 0 as a null pointer constant is deliberate."
+-config=MC3R1.R11.9,reports+={deliberate, "any_area(any_loc(any_exp(macro(^__ACCESS_ONCE$))))"
+}
+-doc_end
+
 #
 # Series 13
 #
diff --git a/docs/misra/deviations.rst b/docs/misra/deviations.rst
index ee7aed0609d2..81a924612ddf 100644
--- a/docs/misra/deviations.rst
+++ b/docs/misra/deviations.rst
@@ -199,6 +199,12 @@  Deviations related to MISRA C:2012 Rules:
        See automation/eclair_analysis/deviations.ecl for the full explanation.
      - Tagged as `safe` for ECLAIR.

+   * - R11.9
+     - __ACCESS_ONCE uses an integer, which happens to be zero, as a
+       compile time check. The typecheck uses a cast. The usage of zero or other
+       integers for this purpose is allowed.
+     - Tagged as `deliberate` for ECLAIR.
+
    * - R13.5
      - All developers and reviewers can be safely assumed to be well aware of
        the short-circuit evaluation strategy for logical operators.
diff --git a/xen/include/xen/compiler.h b/xen/include/xen/compiler.h
index dd99e573083f..a8be1f19cfc2 100644
--- a/xen/include/xen/compiler.h
+++ b/xen/include/xen/compiler.h
@@ -109,14 +109,6 @@ 

 #define offsetof(a,b) __builtin_offsetof(a,b)

-/**
- * sizeof_field(TYPE, MEMBER)
- *
- * @TYPE: The structure containing the field of interest
- * @MEMBER: The field to return the size of
- */
-#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
-
 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
 #define alignof __alignof__
 #endif
diff --git a/xen/include/xen/kernel.h b/xen/include/xen/kernel.h
index 46b3c9c02625..2c5ed7736c99 100644
--- a/xen/include/xen/kernel.h
+++ b/xen/include/xen/kernel.h
@@ -51,7 +51,7 @@ 
  *
  */
 #define container_of(ptr, type, member) ({                      \
-        typeof( ((type *)0)->member ) *__mptr = (ptr);          \
+        typeof_field(type, member) *__mptr = (ptr);             \
         (type *)( (char *)__mptr - offsetof(type,member) );})

 /*
diff --git a/xen/include/xen/macros.h b/xen/include/xen/macros.h
index d0caae7db298..457c84b9d1a0 100644
--- a/xen/include/xen/macros.h
+++ b/xen/include/xen/macros.h
@@ -54,6 +54,22 @@ 

 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) + __must_be_array(x))

+/**
+ * typeof_field(type, member)
+ *
+ * @type: The structure containing the field of interest
+ * @member: The field whose type is returned
+ */
+#define typeof_field(type, member) typeof(((type *)NULL)->member)
+
+/**
+ * sizeof_field(type, member)
+ *
+ * @type: The structure containing the field of interest
+ * @member: The field to return the size of
+ */
+#define sizeof_field(type, member) sizeof(((type *)NULL)->member)
+
 #endif /* __ASSEMBLY__ */

 #endif /* __MACROS_H__ */