Skip to contentSkip to conversation

lib: utils: Simplify SET_ISA_EXT_MAP()

PATCH New Heinrich Schuchardt 3 participants 3 messages Sep 28, 2023 – Oct 6, 2023

lore
Share & tools
lore
#0 lore raw

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

The define is hard to read. The continue statement does not do what was intended.

* Remove do {} while (false);
* Change the name to set_multi_letter_ext
- Other local macros are lower case too.
- Refer to the fact that this is only used for multi-letter extensions.

Addresses-Coverity-ID: 1568359 Unexpected control flow

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

---
v2:
keep continue statement
rename macro

---
 lib/utils/fdt/fdt_helper.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
lib/utils/fdt/fdt_helper.c +6 -7
index c97f09d..b97ff74 100644
@@ -369,16 +369,15 @@ static int fdt_parse_isa_one_hart(const char *isa, unsigned long *extensions)
 		if (!j)
 			continue;
 
-#define SET_ISA_EXT_MAP(name, bit)				\
-		do {						\
-			if (!strcmp(mstr, name)) {		\
+#define set_multi_letter_ext(name, bit)				\
+		{						\
+			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
+		set_multi_letter_ext("smepmp", SBI_HART_EXT_SMEPMP);
+#undef set_multi_letter_ext
 	}
 
 	return 0;
Signature · 1 line
2.40.1
#1 lore raw

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

? 2023-09-28???? 14:17 +0200?Heinrich Schuchardt???

Quoted 11 lines

The define is hard to read. The continue statement does not do what was intended.

* Remove do {} while (false);
* Change the name to set_multi_letter_ext
? - Other local macros are lower case too.
? - Refer to the fact that this is only used for multi-letter extensions.

Addresses-Coverity-ID: 1568359 Unexpected control flow

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

LGTM

Quoted 39 lines

---
v2:
keep continue statement
rename macro
---
?lib/utils/fdt/fdt_helper.c | 13 ++++++-------
?1 file changed, 6 insertions(+), 7 deletions(-)

lib/utils/fdt/fdt_helper.c +0 -0
index c97f09d..b97ff74 100644
@@ -369,16 +369,15 @@ static int fdt_parse_isa_one_hart(const char *isa, unsigned long *extensions)
 ?		if (!j)
 ?			continue;

?

lib/utils/fdt/fdt_helper.c +3 -3
-#define SET_ISA_EXT_MAP(name, bit)				\
-		do {						\
-			if (!strcmp(mstr, name)) {		\
+#define set_multi_letter_ext(name, bit)				\
+		{						\
+			if (!strcmp(mstr, name))		\

? __set_bit(bit, extensions); \
? continue; \

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

?

lib/utils/fdt/fdt_helper.c +2 -2
-		SET_ISA_EXT_MAP("smepmp", SBI_HART_EXT_SMEPMP);
-#undef SET_ISA_EXT_MAP
+		set_multi_letter_ext("smepmp", SBI_HART_EXT_SMEPMP);
+#undef set_multi_letter_ext

? }
?
? return 0;

Signature · 1 line
2.40.1
Applied
#2 lore raw

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

In reply to Heinrich Schuchardt
Quoted 27 lines · On Thu, Sep 28, 2023 at 5:47?PM Heinrich Schuchardt…

The define is hard to read. The continue statement does not do what was intended.

* Remove do {} while (false);
* Change the name to set_multi_letter_ext
- Other local macros are lower case too.
- Refer to the fact that this is only used for multi-letter extensions.

Addresses-Coverity-ID: 1568359 Unexpected control flow

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

---
v2:
keep continue statement
rename macro

---
 lib/utils/fdt/fdt_helper.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
lib/utils/fdt/fdt_helper.c +0 -0
index c97f09d..b97ff74 100644
@@ -369,16 +369,15 @@ static int fdt_parse_isa_one_hart(const char *isa, unsigned long *extensions)
                if (!j)
                        continue;

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

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

The braces around "if ()" are still required otherwise it fails to compile.

I have taken care of this at the time of merging this patch.

Quoted 11 lines
lib/utils/fdt/fdt_helper.c +3 -4
-               } while (false)                                 \
+               }                                               \
 
-               SET_ISA_EXT_MAP("smepmp", SBI_HART_EXT_SMEPMP);
-#undef SET_ISA_EXT_MAP
+               set_multi_letter_ext("smepmp", SBI_HART_EXT_SMEPMP);
+#undef set_multi_letter_ext
        }
 
        return 0;
--
Quoted 2 lines

2.40.1

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup