Skip to contentSkip to conversation

iommu: replace single-char identifiers in macros

PATCH In review Qian Cai 2 participants 4 messages Jun 3, 2019

lore
Share & tools
lore

Qian Cai

author
#0 lore raw

PATCH 1/1 iommu: replace single-char identifiers in macros

There are a few macros in IOMMU have single-char identifiers make the code hard to read and debug. Replace them with meaningful names.

---
 include/linux/dmar.h | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
include/linux/dmar.h +8 -6
index f8af1d770520..eb634912f475 100644
@@ -104,12 +104,14 @@ static inline bool dmar_rcu_check(void)
 
 #define	dmar_rcu_dereference(p)	rcu_dereference_check((p), dmar_rcu_check())
 
-#define	for_each_dev_scope(a, c, p, d)	\
-	for ((p) = 0; ((d) = (p) < (c) ? dmar_rcu_dereference((a)[(p)].dev) : \
-			NULL, (p) < (c)); (p)++)
-
-#define	for_each_active_dev_scope(a, c, p, d)	\
-	for_each_dev_scope((a), (c), (p), (d))	if (!(d)) { continue; } else
+#define for_each_dev_scope(devs, cnt, i, tmp)				\
+	for ((i) = 0; ((tmp) = (i) < (cnt) ?				\
+	    dmar_rcu_dereference((devs)[(i)].dev) : NULL, (i) < (cnt)); \
+	    (i)++)
+
+#define for_each_active_dev_scope(devs, cnt, i, tmp)			\
+	for_each_dev_scope((devs), (cnt), (i), (tmp))			\
+		if (!(tmp)) { continue; } else
 
 extern int dmar_table_init(void);
 extern int dmar_dev_scope_init(void);
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 15 lines · Qian Cai

There are a few macros in IOMMU have single-char identifiers make the code hard to read and debug. Replace them with meaningful names.

---
  include/linux/dmar.h | 14 ++++++++------
  1 file changed, 8 insertions(+), 6 deletions(-)
include/linux/dmar.h +0 -0
index f8af1d770520..eb634912f475 100644
@@ -104,12 +104,14 @@ static inline bool dmar_rcu_check(void)
 

include/linux/dmar.h static inline bool dmar_rcu_check(void) · line 108

Quoted 10 lines
include/linux/dmar.h +2 -6
  #define	dmar_rcu_dereference(p)	rcu_dereference_check((p), dmar_rcu_check())
 
-#define	for_each_dev_scope(a, c, p, d)	\
-	for ((p) = 0; ((d) = (p) < (c) ? dmar_rcu_dereference((a)[(p)].dev) : \
-			NULL, (p) < (c)); (p)++)
-
-#define	for_each_active_dev_scope(a, c, p, d)	\
-	for_each_dev_scope((a), (c), (p), (d))	if (!(d)) { continue; } else
+#define for_each_dev_scope(devs, cnt, i, tmp)				\
+	for ((i) = 0; ((tmp) = (i) < (cnt) ?				\

Given that "tmp" actually appears to be some sort of device cursor, I'm not sure that that naming really achieves the stated goal of clarity :/

Robin.

Quoted 10 lines
include/linux/dmar.h +6 -0
+	    dmar_rcu_dereference((devs)[(i)].dev) : NULL, (i) < (cnt)); \
+	    (i)++)
+
+#define for_each_active_dev_scope(devs, cnt, i, tmp)			\
+	for_each_dev_scope((devs), (cnt), (i), (tmp))			\
+		if (!(tmp)) { continue; } else
 
  extern int dmar_table_init(void);
  extern int dmar_dev_scope_init(void);
author
#2 lore raw
Quoted 26 lines · Robin Murphy
Quoted 25 lines · Qian Cai

There are a few macros in IOMMU have single-char identifiers make the code hard to read and debug. Replace them with meaningful names.

---
  include/linux/dmar.h | 14 ++++++++------

  1 file changed, 8 insertions(+), 6 deletions(-)
include/linux/dmar.h +0 -0
index f8af1d770520..eb634912f475 100644
@@ -104,12 +104,14 @@ static inline bool dmar_rcu_check(void)


  #define dmar_rcu_dereference(p) rcu_dereference_check((p),
dmar_rcu_check())

include/linux/dmar.h +0 -2
-#define	for_each_dev_scope(a, c, p, d)	\
-	for ((p) = 0; ((d) = (p) < (c) ? dmar_rcu_dereference((a)[(p)].dev)

: \

include/linux/dmar.h +0 -4
-			NULL, (p) < (c)); (p)++)
-
-#define	for_each_active_dev_scope(a, c, p, d)	\
-	for_each_dev_scope((a), (c), (p), (d))	if (!(d)) { continue;
Quoted 8 lines
Quoted 5 lines

} else
+#define for_each_dev_scope(devs, cnt, i, tmp)
\

include/linux/dmar.h +1 -0
+	for ((i) = 0; ((tmp) = (i) < (cnt) ?				

\

Given that "tmp" actually appears to be some sort of device cursor, I'm not sure that that naming really achieves the stated goal of clarity :/

"tmp" is used in the callers everywhere though, although I suppose something like "tmp_dev" can be used if you prefer.

#3 lore raw
Quoted 36 lines · Qian Cai
Quoted 19 lines · Robin Murphy
Quoted 18 lines · Qian Cai

There are a few macros in IOMMU have single-char identifiers make the code hard to read and debug. Replace them with meaningful names.

---
   include/linux/dmar.h | 14 ++++++++------
   1 file changed, 8 insertions(+), 6 deletions(-)
include/linux/dmar.h +0 -0
index f8af1d770520..eb634912f475 100644
@@ -104,12 +104,14 @@ static inline bool dmar_rcu_check(void)
 
   #define	dmar_rcu_dereference(p)	rcu_dereference_check((p),
 dmar_rcu_check())
 
Quoted 15 lines
Quoted 11 lines
include/linux/dmar.h +1 -6
-#define	for_each_dev_scope(a, c, p, d)	\
-	for ((p) = 0; ((d) = (p) < (c) ? dmar_rcu_dereference((a)[(p)].dev)
 : \
-			NULL, (p) < (c)); (p)++)
-
-#define	for_each_active_dev_scope(a, c, p, d)	\
-	for_each_dev_scope((a), (c), (p), (d))	if (!(d)) { continue;
 } else
+#define for_each_dev_scope(devs, cnt, i, tmp)				

\

include/linux/dmar.h +1 -0
+	for ((i) = 0; ((tmp) = (i) < (cnt) ?				
Quoted 1 line

\

Given that "tmp" actually appears to be some sort of device cursor, I'm not sure that that naming really achieves the stated goal of clarity :/

Quoted 2 lines

"tmp" is used in the callers everywhere though, although I suppose something like "tmp_dev" can be used if you prefer.

I don't have any preference, I'm just questioning the assertion in the commit message - as a reader not intimately familiar with this code, "tmp" is honestly no more meaningful than "d" was.

Robin.