diff mbox series

iosys-map: Rename locals used inside macros

Message ID 20231024110710.3039807-1-michal.winiarski@intel.com (mailing list archive)
State New, archived
Headers show
Series iosys-map: Rename locals used inside macros | expand

Commit Message

Michał Winiarski Oct. 24, 2023, 11:07 a.m. UTC
Widely used variable names can be used by macro users, potentially
leading to name collisions.
Suffix locals used inside the macros with an underscore, to reduce the
collision potential.

Suggested-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
---
 include/linux/iosys-map.h | 44 +++++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 22 deletions(-)

Comments

Lucas De Marchi Oct. 24, 2023, 1:10 p.m. UTC | #1
On Tue, Oct 24, 2023 at 01:07:10PM +0200, Michał Winiarski wrote:
>Widely used variable names can be used by macro users, potentially
>leading to name collisions.
>Suffix locals used inside the macros with an underscore, to reduce the
>collision potential.
>
>Suggested-by: Lucas De Marchi <lucas.demarchi@intel.com>
>Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>

`git show --color-words` shows this is doing exactly what it should.

Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>

Maybe note in the commit message the compilation error we get with
clang? Although that's in the xe driver that is still not merged
upstream... so not really required.

thanks
Lucas De Marchi
Lucas De Marchi Nov. 14, 2023, 5:46 p.m. UTC | #2
On Tue, Oct 24, 2023 at 08:10:32AM -0500, Lucas De Marchi wrote:
>On Tue, Oct 24, 2023 at 01:07:10PM +0200, Michał Winiarski wrote:
>>Widely used variable names can be used by macro users, potentially
>>leading to name collisions.
>>Suffix locals used inside the macros with an underscore, to reduce the
>>collision potential.
>>
>>Suggested-by: Lucas De Marchi <lucas.demarchi@intel.com>
>>Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
>
>`git show --color-words` shows this is doing exactly what it should.
>
>Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>

applied to drm-misc-next. Thanks

Lucas De Marchi

>
>Maybe note in the commit message the compilation error we get with
>clang? Although that's in the xe driver that is still not merged
>upstream... so not really required.
>
>thanks
>Lucas De Marchi
diff mbox series

Patch

diff --git a/include/linux/iosys-map.h b/include/linux/iosys-map.h
index cb71aa616bd37..bb3a8c30fb920 100644
--- a/include/linux/iosys-map.h
+++ b/include/linux/iosys-map.h
@@ -168,9 +168,9 @@  struct iosys_map {
  * about the use of uninitialized variable.
  */
 #define IOSYS_MAP_INIT_OFFSET(map_, offset_) ({				\
-	struct iosys_map copy = *map_;					\
-	iosys_map_incr(&copy, offset_);					\
-	copy;								\
+	struct iosys_map copy_ = *map_;					\
+	iosys_map_incr(&copy_, offset_);				\
+	copy_;								\
 })
 
 /**
@@ -391,14 +391,14 @@  static inline void iosys_map_memset(struct iosys_map *dst, size_t offset,
  * Returns:
  * The value read from the mapping.
  */
-#define iosys_map_rd(map__, offset__, type__) ({				\
-	type__ val;								\
-	if ((map__)->is_iomem) {						\
-		__iosys_map_rd_io(val, (map__)->vaddr_iomem + (offset__), type__);\
-	} else {								\
-		__iosys_map_rd_sys(val, (map__)->vaddr + (offset__), type__);	\
-	}									\
-	val;									\
+#define iosys_map_rd(map__, offset__, type__) ({					\
+	type__ val_;									\
+	if ((map__)->is_iomem) {							\
+		__iosys_map_rd_io(val_, (map__)->vaddr_iomem + (offset__), type__);	\
+	} else {									\
+		__iosys_map_rd_sys(val_, (map__)->vaddr + (offset__), type__);		\
+	}										\
+	val_;										\
 })
 
 /**
@@ -413,13 +413,13 @@  static inline void iosys_map_memset(struct iosys_map *dst, size_t offset,
  * or if pointer may be unaligned (and problematic for the architecture
  * supported), use iosys_map_memcpy_to()
  */
-#define iosys_map_wr(map__, offset__, type__, val__) ({				\
-	type__ val = (val__);							\
-	if ((map__)->is_iomem) {						\
-		__iosys_map_wr_io(val, (map__)->vaddr_iomem + (offset__), type__);\
-	} else {								\
-		__iosys_map_wr_sys(val, (map__)->vaddr + (offset__), type__);	\
-	}									\
+#define iosys_map_wr(map__, offset__, type__, val__) ({					\
+	type__ val_ = (val__);								\
+	if ((map__)->is_iomem) {							\
+		__iosys_map_wr_io(val_, (map__)->vaddr_iomem + (offset__), type__);	\
+	} else {									\
+		__iosys_map_wr_sys(val_, (map__)->vaddr + (offset__), type__);		\
+	}										\
 })
 
 /**
@@ -485,9 +485,9 @@  static inline void iosys_map_memset(struct iosys_map *dst, size_t offset,
  * The value read from the mapping.
  */
 #define iosys_map_rd_field(map__, struct_offset__, struct_type__, field__) ({	\
-	struct_type__ *s;							\
+	struct_type__ *s_;							\
 	iosys_map_rd(map__, struct_offset__ + offsetof(struct_type__, field__),	\
-		     typeof(s->field__));					\
+		     typeof(s_->field__));					\
 })
 
 /**
@@ -508,9 +508,9 @@  static inline void iosys_map_memset(struct iosys_map *dst, size_t offset,
  * usage and memory layout.
  */
 #define iosys_map_wr_field(map__, struct_offset__, struct_type__, field__, val__) ({	\
-	struct_type__ *s;								\
+	struct_type__ *s_;								\
 	iosys_map_wr(map__, struct_offset__ + offsetof(struct_type__, field__),		\
-		     typeof(s->field__), val__);					\
+		     typeof(s_->field__), val__);					\
 })
 
 #endif /* __IOSYS_MAP_H__ */