Skip to contentSkip to conversation

lib: utils/fdt: Allow zero length mtime when parsing ACLINT

PATCH New Inochi Amaoto 2 participants 3 messages Oct 11, 2023 – Oct 12, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: utils/fdt: Allow zero length mtime when parsing ACLINT

Currently, the fdt_parse_aclint_node() does not allow the first reg to be zero length. This may cause the parser to fail when the ACLINT does not support mtime.

To be robust, delay the check of first reg in fdt_parse_aclint_node() so the parser can handle ACLINT without mtime support.

---
 lib/utils/fdt/fdt_helper.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
lib/utils/fdt/fdt_helper.c +5 -1
index c97f09d..6b4ef38 100644
@@ -897,8 +897,10 @@ int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer,
 
 	rc = fdt_get_node_addr_size(fdt, nodeoffset, 0,
 				    &reg_addr, &reg_size);
-	if (rc < 0 || !reg_size)
+	if (rc < 0)
 		return SBI_ENODEV;
+	if (!reg_size)
+		reg_addr = reg_size = 0;
 	*out_addr1 = reg_addr;
 	*out_size1 = reg_size;
 
@@ -906,6 +908,8 @@ int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer,
 				    &reg_addr, &reg_size);
 	if (rc < 0 || !reg_size)
 		reg_addr = reg_size = 0;
+	if (!reg_addr && *out_size1 == 0)
+		return SBI_ENODEV;
 	if (out_addr2)
 		*out_addr2 = reg_addr;
 	if (out_size2)
Signature · 1 line
2.42.0
#1 lore raw

PATCH 1/1 lib: utils/fdt: Allow zero length mtime when parsing ACLINT

? 2023-10-12???? 07:25 +0800?Inochi Amaoto???

Quoted 23 lines

Currently, the fdt_parse_aclint_node() does not allow the first reg to be zero length. This may cause the parser to fail when the ACLINT does not support mtime.

To be robust, delay the check of first reg in fdt_parse_aclint_node() so the parser can handle ACLINT without mtime support.

---
?lib/utils/fdt/fdt_helper.c | 6 +++++-
?1 file changed, 5 insertions(+), 1 deletion(-)

lib/utils/fdt/fdt_helper.c +0 -0
index c97f09d..6b4ef38 100644
@@ -897,8 +897,10 @@ int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer,

?
? rc = fdt_get_node_addr_size(fdt, nodeoffset, 0,
? ??? &reg_addr, &reg_size);

lib/utils/fdt/fdt_helper.c +1 -1
-	if (rc < 0 || !reg_size)
+	if (rc < 0)

? return SBI_ENODEV;

lib/utils/fdt/fdt_helper.c int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer, · line 903

Quoted 2 lines
lib/utils/fdt/fdt_helper.c +2 -0
+	if (!reg_size)
+		reg_addr = reg_size = 0;

If abandon checking reg_size here, should add a check where this function is called. Because reg_size=0 is only legal under without_mtime.

Regards,
Xiang W

Quoted 17 lines

? *out_addr1 = reg_addr;
? *out_size1 = reg_size;
?

lib/utils/fdt/fdt_helper.c +2 -0
@@ -906,6 +908,8 @@ int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer,
 ?				??? &reg_addr, &reg_size);
 ?	if (rc < 0 || !reg_size)
 ?		reg_addr = reg_size = 0;
+	if (!reg_addr && *out_size1 == 0)
+		return SBI_ENODEV;
 
 ?	if (out_addr2)
 ?		*out_addr2 = reg_addr;

? if (out_size2)

Signature · 1 line
2.42.0
#2 lore raw

PATCH 1/1 lib: utils/fdt: Allow zero length mtime when parsing ACLINT

Quoted 19 lines

? 2023-10-12???? 07:25 +0800?Inochi Amaoto???

Quoted 18 lines

Currently, the fdt_parse_aclint_node() does not allow the first reg to be zero length. This may cause the parser to fail when the ACLINT does not support mtime.

To be robust, delay the check of first reg in fdt_parse_aclint_node() so the parser can handle ACLINT without mtime support.

---
 lib/utils/fdt/fdt_helper.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
lib/utils/fdt/fdt_helper.c +0 -0
index c97f09d..6b4ef38 100644
@@ -897,8 +897,10 @@ int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer,
 
Quoted 10 lines

lib/utils/fdt/fdt_helper.c int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer, · line 903

Quoted 7 lines
lib/utils/fdt/fdt_helper.c +3 -1
 	rc = fdt_get_node_addr_size(fdt, nodeoffset, 0,
 				    &reg_addr, &reg_size);
-	if (rc < 0 || !reg_size)
+	if (rc < 0)
 		return SBI_ENODEV;
+	if (!reg_size)
+		reg_addr = reg_size = 0;

If abandon checking reg_size here, should add a check where this function is called. Because reg_size=0 is only legal under without_mtime.

This check is not abandoned, but delayed.

Quoted 5 lines

Regards,
Xiang W

Quoted 3 lines
lib/utils/fdt/fdt_helper.c +0 -0
 	*out_addr1 = reg_addr;
 	*out_size1 = reg_size;
 
Quoted 7 lines

lib/utils/fdt/fdt_helper.c int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer, · line 912

Quoted 6 lines
lib/utils/fdt/fdt_helper.c +2 -0
@@ -906,6 +908,8 @@ int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer,
 				    &reg_addr, &reg_size);
 	if (rc < 0 || !reg_size)
 		reg_addr = reg_size = 0;
+	if (!reg_addr && *out_size1 == 0)
+		return SBI_ENODEV;

The reg_size of the first pair is checked here.
It seems I should check reg_size here, will fix.

Quoted 9 lines
Quoted 7 lines
lib/utils/fdt/fdt_helper.c +0 -1
 	if (out_addr2)
 		*out_addr2 = reg_addr;
 	if (out_size2)
--

2.42.0