diff mbox series

[16/17] xen/build: address violation of MISRA C Directive 4.10

Message ID c3d0eb70d894a1dc0ddd53cacd6a525bc10577ce.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, 1:46 p.m. UTC
This addresses violations of MISRA C:2012 Rule 4.10 which states as
following: Precautions shall be taken in order to prevent the contents
of a header file being included more than once.

Added inclusion guards for autogenerated header files: include/xen/compile.h
and include/xen/hypercall-defs.h.

No functional change.

Signed-off-by: Alessandro Zucchelli <alessandro.zucchelli@bugseng.com>
---
 xen/build.mk         | 6 +++++-
 xen/include/Makefile | 5 ++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

Comments

Jan Beulich July 3, 2024, 1:32 p.m. UTC | #1
On 01.07.2024 15:46, Alessandro Zucchelli wrote:
> --- a/xen/build.mk
> +++ b/xen/build.mk
> @@ -18,6 +18,8 @@ quiet_cmd_compile.h = UPD     $@
>  define cmd_compile.h
>      if [ ! -r $@ -o -O $@ ]; then \
>  	cat .banner; \
> +	echo '#ifndef INCLUDE_XEN_COMPILE_H' >> $(dot-target).tmp; \

Leaving aside the question on the INCLUDE_ prefix (see earlier comments
on another patch in this series), I wonder what good a guard does here
in the first place. But anyway, I expect this again gets us into "we
need to mechanically and slavishly follow the rules" territory.

However, shouldn't this first "echo" use > in place of >>, to prevent
surprises when e.g. an earlier build was interrupted at exactly the
"right" point?

Jan
diff mbox series

Patch

diff --git a/xen/build.mk b/xen/build.mk
index bbd4c2970f..c83882c949 100644
--- a/xen/build.mk
+++ b/xen/build.mk
@@ -18,6 +18,8 @@  quiet_cmd_compile.h = UPD     $@
 define cmd_compile.h
     if [ ! -r $@ -o -O $@ ]; then \
 	cat .banner; \
+	echo '#ifndef INCLUDE_XEN_COMPILE_H' >> $(dot-target).tmp; \
+	echo '#define INCLUDE_XEN_COMPILE_H' >> $(dot-target).tmp; \
 	sed -e 's/@@date@@/$(XEN_BUILD_DATE)/g' \
 	    -e 's/@@time@@/$(XEN_BUILD_TIME)/g' \
 	    -e 's/@@whoami@@/$(XEN_WHOAMI)/g' \
@@ -28,8 +30,9 @@  define cmd_compile.h
 	    -e 's/@@subversion@@/$(XEN_SUBVERSION)/g' \
 	    -e 's/@@extraversion@@/$(XEN_EXTRAVERSION)/g' \
 	    -e 's!@@changeset@@!$(shell $(srctree)/tools/scmversion $(XEN_ROOT) || echo "unavailable")!g' \
-	    < $< > $(dot-target).tmp; \
+	    < $< >> $(dot-target).tmp; \
 	sed -rf $(srctree)/tools/process-banner.sed < .banner >> $(dot-target).tmp; \
+	echo '#endif /* INCLUDE_XEN_COMPILE_H */' >> $(dot-target).tmp; \
 	mv -f $(dot-target).tmp $@; \
     fi
 endef
@@ -40,6 +43,7 @@  include/xen/compile.h: include/xen/compile.h.in .banner FORCE
 
 targets += include/xen/compile.h
 
+
 -include $(wildcard .asm-offsets.s.d)
 asm-offsets.s: arch/$(SRCARCH)/$(ARCH)/asm-offsets.c
 	$(CC) $(call cpp_flags,$(c_flags)) -S -g0 -o $@.new -MQ $@ $<
diff --git a/xen/include/Makefile b/xen/include/Makefile
index eccc2e017a..34e133949c 100644
--- a/xen/include/Makefile
+++ b/xen/include/Makefile
@@ -121,7 +121,10 @@  $(obj)/compat/xlat.h: $(addprefix $(obj)/compat/.xlat/,$(xlat-y)) FORCE
 
 quiet_cmd_genhyp = GEN     $@
 define cmd_genhyp
-    awk -f $(srctree)/scripts/gen_hypercall.awk <$< >$@
+    echo "#ifndef XEN_HYPERCALL_DEFS_H" >$@; \
+    echo "#define XEN_HYPERCALL_DEFS_H" >>$@; \
+    awk -f $(srctree)/scripts/gen_hypercall.awk <$< >>$@; \
+    echo "#endif /* XEN_HYPERCALL_DEFS_H */" >>$@
 endef
 
 all: $(obj)/xen/hypercall-defs.h