Message ID | 504cdd2a0f27d28e0a87492f75476b123b68bbc0.1710145041.git.simone.ballarin@bugseng.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | xen: address violation of MISRA C:2012 Directive 4.10 | expand |
On 11.03.2024 09:59, Simone Ballarin wrote: > Amend inclusion guards 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) and the #if directive cannot > be used for other checks. This latter restriction, even if just slightly, hampers readability > --- a/xen/include/xen/err.h > +++ b/xen/include/xen/err.h > @@ -1,5 +1,6 @@ > -#if !defined(__XEN_ERR_H__) && !defined(__ASSEMBLY__) > -#define __XEN_ERR_H__ > +#ifndef XEN_INCLUDE_XEN_ERR_H > +#define XEN_INCLUDE_XEN_ERR_H > +#ifndef __ASSEMBLY__ > > #include <xen/compiler.h> > #include <xen/errno.h> > @@ -41,4 +42,5 @@ static inline int __must_check PTR_RET(const void *ptr) > return IS_ERR(ptr) ? PTR_ERR(ptr) : 0; > } > > -#endif /* __XEN_ERR_H__ */ > +#endif /* __ASSEMBLY__ */ > +#endif /* XEN_INCLUDE_XEN_ERR_H */ ... here, ... > --- a/xen/include/xen/softirq.h > +++ b/xen/include/xen/softirq.h > @@ -1,5 +1,6 @@ > -#if !defined(__XEN_SOFTIRQ_H__) && !defined(__ASSEMBLY__) > -#define __XEN_SOFTIRQ_H__ > +#ifndef XEN_INCLUDE_XEN_SOFTIRQ_H > +#define XEN_INCLUDE_XEN_SOFTIRQ_H > +#ifndef __ASSEMBLY__ > > /* Low-latency softirqs come first in the following list. */ > enum { > @@ -40,4 +41,5 @@ void cpu_raise_softirq_batch_finish(void); > */ > void process_pending_softirqs(void); > > -#endif /* __XEN_SOFTIRQ_H__ */ > +#endif /* __ASSEMBLY__ */ > +#endif /* XEN_INCLUDE_XEN_SOFTIRQ_H */ ... here, and ... > --- a/xen/include/xen/vmap.h > +++ b/xen/include/xen/vmap.h > @@ -1,5 +1,6 @@ > -#if !defined(__XEN_VMAP_H__) && defined(VMAP_VIRT_START) > -#define __XEN_VMAP_H__ > +#ifndef XEN_INCLUDE_XEN_VMAP_H > +#define XEN_INCLUDE_XEN_VMAP_H > +#ifdef VMAP_VIRT_START > > #include <xen/mm-frame.h> > #include <xen/page-size.h> > @@ -42,4 +43,5 @@ static inline void vm_init(void) > vm_init_type(VMAP_DEFAULT, (void *)VMAP_VIRT_START, arch_vmap_virt_end()); > } > > -#endif /* __XEN_VMAP_H__ */ > +#endif /* VMAP_VIRT_START */ > +#endif /* XEN_INCLUDE_XEN_VMAP_H */ ... here. Wasn't a goal of Misra to also not have negative effects on code readability? Jan
Hi Simone, On 11/03/2024 08:59, Simone Ballarin wrote: > Amend inclusion guards 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) and the #if directive cannot > be used for other checks. > > Mechanical change. > > Signed-off-by: Simone Ballarin <simone.ballarin@bugseng.com> > Signed-off-by: Maria Celeste Cesario <maria.celeste.cesario@bugseng.com> Regarding Jan's comment, I don't have any strong opinion on whether this patch impair readability in this case. So: Acked-by: Julien Grall <jgrall@amazon.com> Cheers,
On Mon, 11 Mar 2024, Simone Ballarin wrote: > Amend inclusion guards 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) and the #if directive cannot > be used for other checks. > > Mechanical change. > > Signed-off-by: Simone Ballarin <simone.ballarin@bugseng.com> > Signed-off-by: Maria Celeste Cesario <maria.celeste.cesario@bugseng.com> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
diff --git a/xen/include/xen/err.h b/xen/include/xen/err.h index cbdd1bf7f8..360307c5da 100644 --- a/xen/include/xen/err.h +++ b/xen/include/xen/err.h @@ -1,5 +1,6 @@ -#if !defined(__XEN_ERR_H__) && !defined(__ASSEMBLY__) -#define __XEN_ERR_H__ +#ifndef XEN_INCLUDE_XEN_ERR_H +#define XEN_INCLUDE_XEN_ERR_H +#ifndef __ASSEMBLY__ #include <xen/compiler.h> #include <xen/errno.h> @@ -41,4 +42,5 @@ static inline int __must_check PTR_RET(const void *ptr) return IS_ERR(ptr) ? PTR_ERR(ptr) : 0; } -#endif /* __XEN_ERR_H__ */ +#endif /* __ASSEMBLY__ */ +#endif /* XEN_INCLUDE_XEN_ERR_H */ diff --git a/xen/include/xen/pci_ids.h b/xen/include/xen/pci_ids.h index e798477a7e..8f2318bccd 100644 --- a/xen/include/xen/pci_ids.h +++ b/xen/include/xen/pci_ids.h @@ -1,3 +1,6 @@ +#ifndef XEN_INCLUDE_XEN_PCI_IDS_H +#define XEN_INCLUDE_XEN_PCI_IDS_H + #define PCI_VENDOR_ID_AMD 0x1022 #define PCI_VENDOR_ID_NVIDIA 0x10de @@ -11,3 +14,5 @@ #define PCI_VENDOR_ID_BROADCOM 0x14e4 #define PCI_VENDOR_ID_INTEL 0x8086 + +#endif /* XEN_INCLUDE_XEN_PCI_IDS_H */ diff --git a/xen/include/xen/softirq.h b/xen/include/xen/softirq.h index 33d6f2ecd2..d108cdd4bc 100644 --- a/xen/include/xen/softirq.h +++ b/xen/include/xen/softirq.h @@ -1,5 +1,6 @@ -#if !defined(__XEN_SOFTIRQ_H__) && !defined(__ASSEMBLY__) -#define __XEN_SOFTIRQ_H__ +#ifndef XEN_INCLUDE_XEN_SOFTIRQ_H +#define XEN_INCLUDE_XEN_SOFTIRQ_H +#ifndef __ASSEMBLY__ /* Low-latency softirqs come first in the following list. */ enum { @@ -40,4 +41,5 @@ void cpu_raise_softirq_batch_finish(void); */ void process_pending_softirqs(void); -#endif /* __XEN_SOFTIRQ_H__ */ +#endif /* __ASSEMBLY__ */ +#endif /* XEN_INCLUDE_XEN_SOFTIRQ_H */ diff --git a/xen/include/xen/vmap.h b/xen/include/xen/vmap.h index 0c16baa85f..bb83f5f64a 100644 --- a/xen/include/xen/vmap.h +++ b/xen/include/xen/vmap.h @@ -1,5 +1,6 @@ -#if !defined(__XEN_VMAP_H__) && defined(VMAP_VIRT_START) -#define __XEN_VMAP_H__ +#ifndef XEN_INCLUDE_XEN_VMAP_H +#define XEN_INCLUDE_XEN_VMAP_H +#ifdef VMAP_VIRT_START #include <xen/mm-frame.h> #include <xen/page-size.h> @@ -42,4 +43,5 @@ static inline void vm_init(void) vm_init_type(VMAP_DEFAULT, (void *)VMAP_VIRT_START, arch_vmap_virt_end()); } -#endif /* __XEN_VMAP_H__ */ +#endif /* VMAP_VIRT_START */ +#endif /* XEN_INCLUDE_XEN_VMAP_H */