[PATCH v2] xen: add header guards to generated asm generic headers

Stefano Stabellini posted 1 patch 4 months, 3 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/alpine.DEB.2.22.394.2506051708100.2495561@ubuntu-linux-20-04-desktop
There is a newer version of this series
xen/scripts/Makefile.asm-generic | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
[PATCH v2] xen: add header guards to generated asm generic headers
Posted by Stefano Stabellini 4 months, 3 weeks ago
MISRA D4.10 requires to have proper header guards in place in all header
files. Add header guards for generated asm generic headers as well.

Suggested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
---
Changes in v2:
- write to $@.new and move the file
- change the header guard name
---
 xen/scripts/Makefile.asm-generic | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/xen/scripts/Makefile.asm-generic b/xen/scripts/Makefile.asm-generic
index b0d356bfa3..1e85a92c32 100644
--- a/xen/scripts/Makefile.asm-generic
+++ b/xen/scripts/Makefile.asm-generic
@@ -32,7 +32,14 @@ old-headers := $(wildcard $(obj)/*.h)
 unwanted    := $(filter-out $(generic-y) $(generated-y),$(old-headers))
 
 quiet_cmd_wrap = WRAP    $@
-      cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@
+      cmd_wrap = \
+	arch=$$(echo $@ | sed -n 's:.*arch/\([^/]*\)/.*:\1:p' | tr a-z A-Z); \
+	upper=$$(echo $*.h | tr a-z A-Z | tr '/.' '__'); \
+	printf "\#ifndef $${arch}_GENERIC_$${upper}\n" > $@.new; \
+	printf "\#define $${arch}_GENERIC_$${upper}\n" >> $@.new; \
+	printf "\#include <asm-generic/$*.h>\n" >> $@.new; \
+	printf "\#endif /* $${arch}_GENERIC_$${upper} */\n" >> $@.new; \
+	mv -f $@.new $@
 
 quiet_cmd_remove = REMOVE  $(unwanted)
       cmd_remove = rm -f $(unwanted)
-- 
2.25.1
Re: [PATCH v2] xen: add header guards to generated asm generic headers
Posted by Jan Beulich 4 months, 3 weeks ago
On 06.06.2025 02:08, Stefano Stabellini wrote:
> MISRA D4.10 requires to have proper header guards in place in all header
> files. Add header guards for generated asm generic headers as well.
> 
> Suggested-by: Jan Beulich <jbeulich@suse.com>
> Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>

Acked-by: Jan Beulich <jbeulich@suse.com>
albeit, as mentioned elsewhere, preferably with ...

> --- a/xen/scripts/Makefile.asm-generic
> +++ b/xen/scripts/Makefile.asm-generic
> @@ -32,7 +32,14 @@ old-headers := $(wildcard $(obj)/*.h)
>  unwanted    := $(filter-out $(generic-y) $(generated-y),$(old-headers))
>  
>  quiet_cmd_wrap = WRAP    $@
> -      cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@
> +      cmd_wrap = \
> +	arch=$$(echo $@ | sed -n 's:.*arch/\([^/]*\)/.*:\1:p' | tr a-z A-Z); \
> +	upper=$$(echo $*.h | tr a-z A-Z | tr '/.' '__'); \
> +	printf "\#ifndef $${arch}_GENERIC_$${upper}\n" > $@.new; \
> +	printf "\#define $${arch}_GENERIC_$${upper}\n" >> $@.new; \
> +	printf "\#include <asm-generic/$*.h>\n" >> $@.new; \
> +	printf "\#endif /* $${arch}_GENERIC_$${upper} */\n" >> $@.new; \
> +	mv -f $@.new $@
>  
>  quiet_cmd_remove = REMOVE  $(unwanted)
>        cmd_remove = rm -f $(unwanted)

... echo instead of printf (and then respective adjustments to the strings), if
that's technically possible.

Jan