diff mbox series

[03/17] misra: add deviations for direct inclusion guards

Message ID 64e80abfaa68d87e8cb4fee67bc2624eda4f466a.1719829101.git.alessandro.zucchelli@bugseng.com (mailing list archive)
State Superseded
Headers show
Series xen: address violation of MISRA C:2012 Directive 4.10 | expand

Commit Message

Alessandro Zucchelli July 1, 2024, 11:10 a.m. UTC
From: Simone Ballarin <simone.ballarin@bugseng.com>

Add deviation comments to address violations of
MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order
to prevent the contents of a header file being included more than
once").

Inclusion guards must appear at the beginning of the headers
(comments are permitted anywhere).

This patch adds deviation comments using the format specified
in docs/misra/safe.json for headers with just the direct
inclusion guard before the inclusion guard since they are
safe and not supposed to comply with the directive.

Note that with SAF-9-safe in place, failures to have proper guards later
in the header files will not be reported

Signed-off-by: Simone Ballarin <simone.ballarin@bugseng.com>
Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Signed-off-by: Alessandro Zucchelli <alessandro.zucchelli@bugseng.com>

---
Changes in v4:
- Added comment clarifying that no further checks will be performed
on a file that has a SAF-9-safe deviation against missing inclusion
guards.
- rebased against the current staging tree

Changes in v3:
- fix inconsistent deviation ID
The patch has been introduced in v2.
---
 docs/misra/safe.json                 | 8 ++++++++
 xen/arch/arm/include/asm/hypercall.h | 1 +
 xen/arch/x86/include/asm/hypercall.h | 1 +
 3 files changed, 10 insertions(+)

Comments

Jan Beulich July 1, 2024, 2:16 p.m. UTC | #1
On 01.07.2024 13:10, Alessandro Zucchelli wrote:
> From: Simone Ballarin <simone.ballarin@bugseng.com>
> 
> Add deviation comments to address violations of
> MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order
> to prevent the contents of a header file being included more than
> once").
> 
> Inclusion guards must appear at the beginning of the headers
> (comments are permitted anywhere).
> 
> This patch adds deviation comments using the format specified
> in docs/misra/safe.json for headers with just the direct
> inclusion guard before the inclusion guard since they are
> safe and not supposed to comply with the directive.
> 
> Note that with SAF-9-safe in place, failures to have proper guards later
> in the header files will not be reported

Rebasing mistake, seeing that it's ...

> --- a/docs/misra/safe.json
> +++ b/docs/misra/safe.json
> @@ -84,6 +84,14 @@
>          },
>          {
>              "id": "SAF-10-safe",
> +            "analyser": {
> +                "eclair": "MC3R1.D4.10"
> +            },
> +            "name": "Dir 4.10: direct inclusion guard before",
> +            "text": "Headers with just the direct inclusion guard before the inclusion guard are safe."
> +        },
> +        {
> +            "id": "SAF-11-safe",
>              "analyser": {},
>              "name": "Sentinel",
>              "text": "Next ID to be used"

... SFA-10-safe that's being added and ...

> --- a/xen/arch/arm/include/asm/hypercall.h
> +++ b/xen/arch/arm/include/asm/hypercall.h
> @@ -1,3 +1,4 @@
> +/* SAF-10-safe direct inclusion guard before */
>  #ifndef __XEN_HYPERCALL_H__
>  #error "asm/hypercall.h should not be included directly - include xen/hypercall.h instead"
>  #endif
> --- a/xen/arch/x86/include/asm/hypercall.h
> +++ b/xen/arch/x86/include/asm/hypercall.h
> @@ -2,6 +2,7 @@
>   * asm-x86/hypercall.h
>   */
>  
> +/* SAF-10-safe direct inclusion guard before */
>  #ifndef __XEN_HYPERCALL_H__
>  #error "asm/hypercall.h should not be included directly - include xen/hypercall.h instead"
>  #endif

... used here?

Jan
Stefano Stabellini July 12, 2024, 10 p.m. UTC | #2
On Mon, 1 Jul 2024, Jan Beulich wrote:
> On 01.07.2024 13:10, Alessandro Zucchelli wrote:
> > From: Simone Ballarin <simone.ballarin@bugseng.com>
> > 
> > Add deviation comments to address violations of
> > MISRA C:2012 Directive 4.10 ("Precautions shall be taken in order
> > to prevent the contents of a header file being included more than
> > once").
> > 
> > Inclusion guards must appear at the beginning of the headers
> > (comments are permitted anywhere).
> > 
> > This patch adds deviation comments using the format specified
> > in docs/misra/safe.json for headers with just the direct
> > inclusion guard before the inclusion guard since they are
> > safe and not supposed to comply with the directive.
> > 
> > Note that with SAF-9-safe in place, failures to have proper guards later
> > in the header files will not be reported
> 
> Rebasing mistake, seeing that it's ...

Yes with "SAF-9-safe" changed to SAF-10-safe in the commit message:

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>



> > --- a/docs/misra/safe.json
> > +++ b/docs/misra/safe.json
> > @@ -84,6 +84,14 @@
> >          },
> >          {
> >              "id": "SAF-10-safe",
> > +            "analyser": {
> > +                "eclair": "MC3R1.D4.10"
> > +            },
> > +            "name": "Dir 4.10: direct inclusion guard before",
> > +            "text": "Headers with just the direct inclusion guard before the inclusion guard are safe."
> > +        },
> > +        {
> > +            "id": "SAF-11-safe",
> >              "analyser": {},
> >              "name": "Sentinel",
> >              "text": "Next ID to be used"
> 
> ... SFA-10-safe that's being added and ...
> 
> > --- a/xen/arch/arm/include/asm/hypercall.h
> > +++ b/xen/arch/arm/include/asm/hypercall.h
> > @@ -1,3 +1,4 @@
> > +/* SAF-10-safe direct inclusion guard before */
> >  #ifndef __XEN_HYPERCALL_H__
> >  #error "asm/hypercall.h should not be included directly - include xen/hypercall.h instead"
> >  #endif
> > --- a/xen/arch/x86/include/asm/hypercall.h
> > +++ b/xen/arch/x86/include/asm/hypercall.h
> > @@ -2,6 +2,7 @@
> >   * asm-x86/hypercall.h
> >   */
> >  
> > +/* SAF-10-safe direct inclusion guard before */
> >  #ifndef __XEN_HYPERCALL_H__
> >  #error "asm/hypercall.h should not be included directly - include xen/hypercall.h instead"
> >  #endif
> 
> ... used here?
> 
> Jan
>
diff mbox series

Patch

diff --git a/docs/misra/safe.json b/docs/misra/safe.json
index 282013aa4e..3e9ebff8fe 100644
--- a/docs/misra/safe.json
+++ b/docs/misra/safe.json
@@ -84,6 +84,14 @@ 
         },
         {
             "id": "SAF-10-safe",
+            "analyser": {
+                "eclair": "MC3R1.D4.10"
+            },
+            "name": "Dir 4.10: direct inclusion guard before",
+            "text": "Headers with just the direct inclusion guard before the inclusion guard are safe."
+        },
+        {
+            "id": "SAF-11-safe",
             "analyser": {},
             "name": "Sentinel",
             "text": "Next ID to be used"
diff --git a/xen/arch/arm/include/asm/hypercall.h b/xen/arch/arm/include/asm/hypercall.h
index ccd26c5184..07e231f8b5 100644
--- a/xen/arch/arm/include/asm/hypercall.h
+++ b/xen/arch/arm/include/asm/hypercall.h
@@ -1,3 +1,4 @@ 
+/* SAF-10-safe direct inclusion guard before */
 #ifndef __XEN_HYPERCALL_H__
 #error "asm/hypercall.h should not be included directly - include xen/hypercall.h instead"
 #endif
diff --git a/xen/arch/x86/include/asm/hypercall.h b/xen/arch/x86/include/asm/hypercall.h
index ec2edc771e..389fa62af2 100644
--- a/xen/arch/x86/include/asm/hypercall.h
+++ b/xen/arch/x86/include/asm/hypercall.h
@@ -2,6 +2,7 @@ 
  * asm-x86/hypercall.h
  */
 
+/* SAF-10-safe direct inclusion guard before */
 #ifndef __XEN_HYPERCALL_H__
 #error "asm/hypercall.h should not be included directly - include xen/hypercall.h instead"
 #endif