Skip to contentSkip to conversation

xen: avoid grep fodder define and undef

RFC Superseded Federico Serafini 2 participants 3 messages Mar 12, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC 1/1 xen: avoid grep fodder define and undef

Place an "#if 0" before grep fodder definitions and remove the "#undef".

This addresses several violations of MISRA C:2012 Rule 5.5 ("Identifiers shall be distinct from macro names").

No functional change.

---
Hello, I would like to know what you think about this change. If you want to keep grep fodders as they are, an alternative could be to deviate violations of Rule 5.5 involving the TYPE_SAFE macro.

---
 xen/include/xen/iommu.h    |  5 +----
 xen/include/xen/mm-frame.h | 15 +++------------
 2 files changed, 4 insertions(+), 16 deletions(-)
xen/include/xen/iommu.h +1 -4
index 9621459c63..ef57f31417 100644
@@ -33,13 +33,10 @@ TYPE_SAFE(uint64_t, dfn);
 #define PRI_dfn     PRIx64
 #define INVALID_DFN _dfn(~0ULL)
 
-#ifndef dfn_t
+#if 0
 #define dfn_t /* Grep fodder: dfn_t, _dfn() and dfn_x() are defined above */
 #define _dfn
 #define dfn_x
-#undef dfn_t
-#undef _dfn
-#undef dfn_x
 #endif
 
 static inline dfn_t __must_check dfn_add(dfn_t dfn, unsigned long i)
xen/include/xen/mm-frame.h +3 -12
index c25e836f25..d973aec901 100644
@@ -14,13 +14,10 @@ TYPE_SAFE(unsigned long, mfn);
  */
 #define INVALID_MFN_INITIALIZER { INVALID_MFN_RAW }
 
-#ifndef mfn_t
+#if 0
 #define mfn_t /* Grep fodder: mfn_t, _mfn() and mfn_x() are defined above */
 #define _mfn
 #define mfn_x
-#undef mfn_t
-#undef _mfn
-#undef mfn_x
 #endif
 
 static inline mfn_t __must_check mfn_add(mfn_t mfn, unsigned long i)
@@ -53,13 +50,10 @@ TYPE_SAFE(unsigned long, gfn);
  */
 #define INVALID_GFN_INITIALIZER { INVALID_GFN_RAW }
 
-#ifndef gfn_t
+#if 0
 #define gfn_t /* Grep fodder: gfn_t, _gfn() and gfn_x() are defined above */
 #define _gfn
 #define gfn_x
-#undef gfn_t
-#undef _gfn
-#undef gfn_x
 #endif
 
 static inline gfn_t __must_check gfn_add(gfn_t gfn, unsigned long i)
@@ -85,13 +79,10 @@ static inline bool gfn_eq(gfn_t x, gfn_t y)
 TYPE_SAFE(unsigned long, pfn);
 #define PRI_pfn          "05lx"
 
-#ifndef pfn_t
+#if 0
 #define pfn_t /* Grep fodder: pfn_t, _pfn() and pfn_x() are defined above */
 #define _pfn
 #define pfn_x
-#undef pfn_t
-#undef _pfn
-#undef pfn_x
 #endif
 
 #endif /* __XEN_FRAME_NUM_H__ */
Signature · 1 line
2.34.1
#1 lore raw
Quoted 6 lines · Federico Serafini

Place an "#if 0" before grep fodder definitions and remove the "#undef".

This addresses several violations of MISRA C:2012 Rule 5.5 ("Identifiers shall be distinct from macro names").

Quoted 7 lines

No functional change.

---
Hello, I would like to know what you think about this change. If you want to keep grep fodders as they are, an alternative could be to deviate violations of Rule 5.5 involving the TYPE_SAFE macro.

I think the original intention was to allow for some (arch?) override. But we have lived without for long enough that I think we could do as you suggest. One question though: Wasn't there also a rule against the use of #undef, violations of which would then be eliminate here as well? If so, I think that would want mentioning in the description. If not, I'd like to give it a couple of days before ack-ing, just in case other opinions would be voiced.

Quoted 5 lines
xen/include/xen/iommu.h +0 -0
@@ -33,13 +33,10 @@ TYPE_SAFE(uint64_t, dfn);
 #define PRI_dfn     PRIx64
 #define INVALID_DFN _dfn(~0ULL)

xen/include/xen/iommu.h TYPE_SAFE(uint64_t, dfn); · line 40

Quoted 10 lines
xen/include/xen/iommu.h +1 -4
 
-#ifndef dfn_t
+#if 0
 #define dfn_t /* Grep fodder: dfn_t, _dfn() and dfn_x() are defined above */
 #define _dfn
 #define dfn_x
-#undef dfn_t
-#undef _dfn
-#undef dfn_x
 #endif

I have to admit that I'm a little surprised that Misra (Eclair) is happy with this: The #define-s are all still there, after all.

Jan

#2 lore raw
Quoted 15 lines · Jan Beulich
Quoted 6 lines · Federico Serafini

Place an "#if 0" before grep fodder definitions and remove the "#undef".

This addresses several violations of MISRA C:2012 Rule 5.5 ("Identifiers shall be distinct from macro names").

Quoted 7 lines

No functional change.

---
Hello, I would like to know what you think about this change. If you want to keep grep fodders as they are, an alternative could be to deviate violations of Rule 5.5 involving the TYPE_SAFE macro.

Quoted 6 lines

I think the original intention was to allow for some (arch?) override.
But we have lived without for long enough that I think we could do as
you suggest. One question though: Wasn't there also a rule against the
use of #undef, violations of which would then be eliminate here as well? > If so, I think that would want mentioning in the description. If not, I'd like to give it a couple of days before ack-ing, just in case other
opinions would be voiced.

Yes, it is advisory Rule 20.5.

Quoted 7 lines
Quoted 7 lines
xen/include/xen/iommu.h +0 -0
@@ -33,13 +33,10 @@ TYPE_SAFE(uint64_t, dfn);
  #define PRI_dfn     PRIx64
  #define INVALID_DFN _dfn(~0ULL)
 
Quoted 12 lines

xen/include/xen/iommu.h TYPE_SAFE(uint64_t, dfn); · line 40

Quoted 9 lines
xen/include/xen/iommu.h +1 -4
-#ifndef dfn_t
+#if 0
  #define dfn_t /* Grep fodder: dfn_t, _dfn() and dfn_x() are defined above */
  #define _dfn
  #define dfn_x
-#undef dfn_t
-#undef _dfn
-#undef dfn_x
  #endif

I have to admit that I'm a little surprised that Misra (Eclair) is happy with this: The #define-s are all still there, after all.

The #define-s after the #if 0 are skipped by the preprocessor and this is something that MISRA takes into account.

As an example, Directive 4.4 states that code should not be commented out and explicitly cites the use of #if and #ifdef to exclude code from the compilation.

Signature · 3 lines
Federico Serafini, M.Sc.

Software Engineer, BUGSENG (http://bugseng.com)