Skip to contentSkip to conversation

lib: utils: Simplify SET_ISA_EXT_MAP()

PATCH Superseded Heinrich Schuchardt 3 participants 4 messages Sep 27, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: utils: Simplify SET_ISA_EXT_MAP()

The define is hard to read.

Addresses-Coverity-ID: 1568359 Unexpected control flow

Fixes d72f5f17478d ("lib: utils: Add detection of Smepmp from ISA string in FDT")
---
 lib/utils/fdt/fdt_helper.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
lib/utils/fdt/fdt_helper.c +3 -5
index c97f09d..6f23f6f 100644
@@ -370,12 +370,10 @@ static int fdt_parse_isa_one_hart(const char *isa, unsigned long *extensions)
 			continue;
 
 #define SET_ISA_EXT_MAP(name, bit)				\
-		do {						\
-			if (!strcmp(mstr, name)) {		\
+		{						\
+			if (!strcmp(mstr, name))		\
 				__set_bit(bit, extensions);	\
-				continue;			\
-			}					\
-		} while (false)					\
+		}						\
 
 		SET_ISA_EXT_MAP("smepmp", SBI_HART_EXT_SMEPMP);
 #undef SET_ISA_EXT_MAP
Signature · 1 line
2.40.1
#1 lore raw

PATCH 1/1 lib: utils: Simplify SET_ISA_EXT_MAP()

? 2023-09-27???? 16:21 +0200?Heinrich Schuchardt???

Quoted 22 lines

The define is hard to read.

Addresses-Coverity-ID: 1568359 Unexpected control flow

Fixes d72f5f17478d ("lib: utils: Add detection of Smepmp from ISA string in FDT")

---
?lib/utils/fdt/fdt_helper.c | 8 +++-----
?1 file changed, 3 insertions(+), 5 deletions(-)

lib/utils/fdt/fdt_helper.c +0 -0
index c97f09d..6f23f6f 100644
@@ -370,12 +370,10 @@ static int fdt_parse_isa_one_hart(const char *isa, unsigned long *extensions)
 ?			continue;

?
?#define SET_ISA_EXT_MAP(name, bit) \

lib/utils/fdt/fdt_helper.c +2 -2
-		do {						\
-			if (!strcmp(mstr, name)) {		\
+		{						\
+			if (!strcmp(mstr, name))		\

? __set_bit(bit, extensions); \

lib/utils/fdt/fdt_helper.c static int fdt_parse_isa_one_hart(const char *isa, unsigned long *extensions) · line 376

Quoted 1 line
lib/utils/fdt/fdt_helper.c +0 -1
-				continue;			\

Only remove 'do ... while' and 'continue' can be keep . In this way, after finding the extension, the subsequent judgment can be skip.

Regards,
Xiang W

Quoted 10 lines
lib/utils/fdt/fdt_helper.c +1 -2
-			}					\
-		} while (false)					\
+		}						\

?
? SET_ISA_EXT_MAP("smepmp", SBI_HART_EXT_SMEPMP);
?#undef SET_ISA_EXT_MAP

Signature · 1 line
2.40.1
#2 lore raw

PATCH 1/1 lib: utils: Simplify SET_ISA_EXT_MAP()

Quoted 17 lines · Xiang W

? 2023-09-27???? 16:21 +0200?Heinrich Schuchardt???

Quoted 16 lines

The define is hard to read.

Addresses-Coverity-ID: 1568359 Unexpected control flow

Fixes d72f5f17478d ("lib: utils: Add detection of Smepmp from ISA string in FDT")
---
 ?lib/utils/fdt/fdt_helper.c | 8 +++-----

?1 file changed, 3 insertions(+), 5 deletions(-)

lib/utils/fdt/fdt_helper.c +0 -0
index c97f09d..6f23f6f 100644
@@ -370,12 +370,10 @@ static int fdt_parse_isa_one_hart(const char *isa, unsigned long *extensions)
 ?			continue;
 
Quoted 9 lines

lib/utils/fdt/fdt_helper.c static int fdt_parse_isa_one_hart(const char *isa, unsigned long *extensions) · line 376

Quoted 7 lines
lib/utils/fdt/fdt_helper.c +2 -3
 ?#define SET_ISA_EXT_MAP(name, bit)				\
-		do {						\
-			if (!strcmp(mstr, name)) {		\
+		{						\
+			if (!strcmp(mstr, name))		\
 ?				__set_bit(bit, extensions);	\
-				continue;			\

Only remove 'do ... while' and 'continue' can be keep . In this way, after finding the extension, the subsequent judgment can be skip.

I understand why you want to have a continue here. Makes sense to me once you add more invocations of the macro.

Just to be clear this is not what the incoming code did.

With your suggestion we should rename the macro to something like SET_ISA_EXT_AND_CONTINUE() to make the behavior obvious.

Best regards

Heinrich

Quoted 14 lines

Regards,
Xiang W

Quoted 10 lines
lib/utils/fdt/fdt_helper.c +1 -2
-			}					\
-		} while (false)					\
+		}						\
 
 ?		SET_ISA_EXT_MAP("smepmp", SBI_HART_EXT_SMEPMP);
 ?#undef SET_ISA_EXT_MAP
Signature · 1 line
2.40.1
#3 lore raw

PATCH 1/1 lib: utils: Simplify SET_ISA_EXT_MAP()

Quoted 1 line · Heinrich Schuchardt

Just to be clear this is not what the incoming code did.

Though perhaps indented, given the use of continue throughout the loop. The wrapping with do/while was probably an afterthought.

Signature · 3 lines
Andreas Schwab, schwab at linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."