lib: fixes for fdt functions
v2 cover lib: fixes for fdt functions
* Use correct type for variables used in error checks
* Check correct variables
* Avoid duplicates checks
* Don't assign values that are never used.
v2:
check correct variables
fix fdt_parse_aclint_node() too
Heinrich Schuchardt (6):
lib: simplify fdt_parse_plmt_node()
lib: simplify fdt_parse_plicsw_node()
lib: fix fdt_parse_plmt_node()
lib: fix fdt_parse_plicsw_node()
lib: simplify fdt_translate_address()
lib: fix fdt_parse_aclint_node()
lib/utils/fdt/fdt_helper.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
Signature · 1 line
2.37.2
PATCH v2 1/6 lib: simplify fdt_parse_plmt_node()
We should not check !plmt_base || !plmt_size twice.
---
v2:
Reviewed-by added
--- lib/utils/fdt/fdt_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/utils/fdt/fdt_helper.c +1 -1
@@ -814,7 +814,7 @@ int fdt_parse_plmt_node(void *fdt, int nodeoffset, unsigned long *plmt_base, rc =fdt_get_node_addr_size (fdt, nodeoffset,0 , ®_addr, ®_size); -if (rc <0 || !plmt_base || !plmt_size) +if (rc <0 )return SBI_ENODEV ; *plmt_base = reg_addr; *plmt_size = reg_size;
Signature · 1 line
2.37.2
PATCH v2 1/6 lib: simplify fdt_parse_plmt_node()
Quoted 6 lines · Heinrich Schuchardt
We should not check !plmt_base || !plmt_size twice.
Signed-off-by Heinrich Schuchardt <[email protected]>Reviewed-by Xiang W <[email protected]>Reviewed-by Yu Chien Peter Lin <[email protected]>
Quoted 7 lines
---
v2:
Reviewed-by added--- lib/utils/fdt/fdt_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH v2 2/6 lib: simplify fdt_parse_plicsw_node()
In reply to Heinrich SchuchardtWe should not check !plicsw_base || !size twice.
---
v2:
Reviewed-by added
--- lib/utils/fdt/fdt_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/utils/fdt/fdt_helper.c +1 -1
@@ -868,7 +868,7 @@ int fdt_parse_plicsw_node(void *fdt, int nodeoffset, unsigned long *plicsw_base, rc =fdt_get_node_addr_size (fdt, nodeoffset,0 , ®_addr, ®_size); -if (rc <0 || !plicsw_base || !size) +if (rc <0 )return SBI_ENODEV ; *plicsw_base = reg_addr; *size = reg_size;
Signature · 1 line
2.37.2
PATCH v2 2/6 lib: simplify fdt_parse_plicsw_node()
Quoted 6 lines · Heinrich Schuchardt
We should not check !plicsw_base || !size twice.
Signed-off-by Heinrich Schuchardt <[email protected]>Reviewed-by Xiang W <[email protected]>Reviewed-by Yu Chien Peter Lin <[email protected]>
Quoted 7 lines
---
v2:
Reviewed-by added--- lib/utils/fdt/fdt_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH v2 3/6 lib: fix fdt_parse_plmt_node()
In reply to Heinrich Schuchardtcpu_offset, cpu_intc_offset must be int to discover failed invocations of fdt_node_offset_by_phandle() or fdt_parent_offset().
After determining cpu_offset we have to check this value and not cpu_intc_offset.
---
v2:
check correct variable
--- lib/utils/fdt/fdt_helper.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
lib/utils/fdt/fdt_helper.c +4 -2
@@ -805,7 +805,7 @@ int fdt_parse_plmt_node(void *fdt, int nodeoffset, unsigned long *plmt_base, {const fdt32_t *val;int rc, i, count; -uint64_t reg_addr, reg_size, cpu_offset, cpu_intc_offset; +uint64_t reg_addr, reg_size;u32 phandle, hwirq, hartid, hcount; if (nodeoffset < 0 || !fdt || !plmt_base ||
@@ -826,6 +826,8 @@ int fdt_parse_plmt_node(void *fdt, int nodeoffset, unsigned long *plmt_base, hcount =0 ;for (i =0 ; i < (count /2 ); i++) { +int cpu_offset, cpu_intc_offset; + phandle =fdt32_to_cpu (val[2 * i]); hwirq =fdt32_to_cpu (val[2 * i +1 ]);
@@ -834,7 +836,7 @@ int fdt_parse_plmt_node(void *fdt, int nodeoffset, unsigned long *plmt_base,continue ; cpu_offset =fdt_parent_offset (fdt, cpu_intc_offset); -if (cpu_intc_offset <0 ) +if (cpu_offset <0 )continue ; rc =fdt_parse_hart_id (fdt, cpu_offset, &hartid);
Signature · 1 line
2.37.2
PATCH v2 3/6 lib: fix fdt_parse_plmt_node()
? 2022-11-28???? 10:14 +0100?Heinrich Schuchardt???
Quoted 7 lines
cpu_offset,cpu_intc_offsetmust be int to discover failed invocations offdt_node_offset_by_phandle()orfdt_parent_offset().After determining
cpu_offsetwe have to check this value and notcpu_intc_offset.Signed-off-by Heinrich Schuchardt <[email protected]>
Look good to me
Quoted 38 lines
---
v2:
????????check correct variable
---
?lib/utils/fdt/fdt_helper.c | 6 ++++--
?1 file changed, 4 insertions(+), 2 deletions(-)lib/utils/fdt/fdt_helper.c +1
-1@@ -805,7 +805,7 @@ int fdt_parse_plmt_node(void *fdt, int nodeoffset, unsigned long *plmt_base, ?{ ????????const fdt32_t *val; ????????int rc, i, count; -???????uint64_t reg_addr, reg_size, cpu_offset, cpu_intc_offset; +???????uint64_t reg_addr, reg_size; ????????u32 phandle, hwirq, hartid, hcount;?
????????if (nodeoffset < 0 || !fdt || !plmt_base ||lib/utils/fdt/fdt_helper.c +0
-0@@ -826,6 +826,8 @@ int fdt_parse_plmt_node(void *fdt, int nodeoffset, unsigned long *plmt_base,?
????????hcount = 0;
????????for (i = 0; i < (count / 2); i++) { +???????????????intcpu_offset,cpu_intc_offset; +
????????????????phandle =fdt32_to_cpu(val[2 * i]); ????????????????hwirq =fdt32_to_cpu(val[2 * i + 1]); ?lib/utils/fdt/fdt_helper.c +0
-0@@ -834,7 +836,7 @@ int fdt_parse_plmt_node(void *fdt, int nodeoffset, unsigned long *plmt_base, ????????????????????????continue;?
????????????????cpu_offset =fdt_parent_offset(fdt, cpu_intc_offset); -???????????????if (cpu_intc_offset< 0) +???????????????if (cpu_offset< 0) ????????????????????????continue;
?
????????????????rc =fdt_parse_hart_id(fdt, cpu_offset, &hartid);
PATCH v2 3/6 lib: fix fdt_parse_plmt_node()
In reply to Heinrich Schuchardt? 2022-11-28???? 10:14 +0100?Heinrich Schuchardt???
Quoted 7 lines
cpu_offset,cpu_intc_offsetmust be int to discover failed invocations offdt_node_offset_by_phandle()orfdt_parent_offset().After determining
cpu_offsetwe have to check this value and notcpu_intc_offset.Signed-off-by Heinrich Schuchardt <[email protected]>
Look good to me
Quoted 42 lines
---
v2:
????????check correct variable
---
?lib/utils/fdt/fdt_helper.c | 6 ++++--
?1 file changed, 4 insertions(+), 2 deletions(-)lib/utils/fdt/fdt_helper.c +1
-1@@ -805,7 +805,7 @@ int fdt_parse_plmt_node(void *fdt, int nodeoffset, unsigned long *plmt_base, ?{ ????????const fdt32_t *val; ????????int rc, i, count; -???????uint64_t reg_addr, reg_size, cpu_offset, cpu_intc_offset; +???????uint64_t reg_addr, reg_size; ????????u32 phandle, hwirq, hartid, hcount;?
????????if (nodeoffset < 0 || !fdt || !plmt_base ||lib/utils/fdt/fdt_helper.c +0
-0@@ -826,6 +826,8 @@ int fdt_parse_plmt_node(void *fdt, int nodeoffset, unsigned long *plmt_base,?
????????hcount = 0;
????????for (i = 0; i < (count / 2); i++) { +???????????????intcpu_offset,cpu_intc_offset; +
????????????????phandle =fdt32_to_cpu(val[2 * i]); ????????????????hwirq =fdt32_to_cpu(val[2 * i + 1]); ?lib/utils/fdt/fdt_helper.c +0
-0@@ -834,7 +836,7 @@ int fdt_parse_plmt_node(void *fdt, int nodeoffset, unsigned long *plmt_base, ????????????????????????continue;?
????????????????cpu_offset =fdt_parent_offset(fdt, cpu_intc_offset); -???????????????if (cpu_intc_offset< 0) +???????????????if (cpu_offset< 0) ????????????????????????continue;
?
????????????????rc =fdt_parse_hart_id(fdt, cpu_offset, &hartid);Signature · 1 line
2.37.2
PATCH v2 3/6 lib: fix fdt_parse_plmt_node()
In reply to Heinrich SchuchardtQuoted 7 lines · Heinrich Schuchardt
cpu_offset,cpu_intc_offsetmust be int to discover failed invocations offdt_node_offset_by_phandle()orfdt_parent_offset().After determining
cpu_offsetwe have to check this value and notcpu_intc_offset.Signed-off-by Heinrich Schuchardt <[email protected]>
Looks good to me.
PATCH v2 3/6 lib: fix fdt_parse_plmt_node()
In reply to Heinrich SchuchardtQuoted 7 lines · Heinrich Schuchardt
cpu_offset,cpu_intc_offsetmust be int to discover failed invocations offdt_node_offset_by_phandle()orfdt_parent_offset().After determining
cpu_offsetwe have to check this value and notcpu_intc_offset.
Quoted 8 lines
Signed-off-by Heinrich Schuchardt <[email protected]>---
v2:
check correct variable--- lib/utils/fdt/fdt_helper.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
PATCH v2 4/6 lib: fix fdt_parse_plicsw_node()
In reply to Heinrich Schuchardtcpu_offset and cpu_intc_offset must be int to detect failed invocations of fdt_node_offset_by_phandle() or fdt_parent_offset().
After determining cpu_offset we have to check this value and not cpu_intc_offset.
---
v2:
check correct variable
--- lib/utils/fdt/fdt_helper.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
lib/utils/fdt/fdt_helper.c +4 -2
@@ -861,7 +861,7 @@ int fdt_parse_plicsw_node(void *fdt, int nodeoffset, unsigned long *plicsw_base, {const fdt32_t *val;int rc, i, count; -uint64_t reg_addr, reg_size, cpu_offset, cpu_intc_offset; +uint64_t reg_addr, reg_size;u32 phandle, hwirq, hartid, hcount; if (nodeoffset < 0 || !fdt || !plicsw_base ||
@@ -882,6 +882,8 @@ int fdt_parse_plicsw_node(void *fdt, int nodeoffset, unsigned long *plicsw_base, hcount =0 ;for (i =0 ; i < (count /2 ); i++) { +int cpu_offset, cpu_intc_offset; + phandle =fdt32_to_cpu (val[2 * i]); hwirq =fdt32_to_cpu (val[2 * i +1 ]);
@@ -890,7 +892,7 @@ int fdt_parse_plicsw_node(void *fdt, int nodeoffset, unsigned long *plicsw_base,continue ; cpu_offset =fdt_parent_offset (fdt, cpu_intc_offset); -if (cpu_intc_offset <0 ) +if (cpu_offset <0 )continue ; rc =fdt_parse_hart_id (fdt, cpu_offset, &hartid);
Signature · 1 line
2.37.2
PATCH v2 4/6 lib: fix fdt_parse_plicsw_node()
? 2022-11-28???? 10:14 +0100?Heinrich Schuchardt???
Quoted 7 lines
cpu_offsetandcpu_intc_offsetmust be int to detect failed invocations offdt_node_offset_by_phandle()orfdt_parent_offset().After determining
cpu_offsetwe have to check this value and notcpu_intc_offset.Signed-off-by Heinrich Schuchardt <[email protected]>
Look good to me
Quoted 38 lines
---
v2:
????????check correct variable
---
?lib/utils/fdt/fdt_helper.c | 6 ++++--
?1 file changed, 4 insertions(+), 2 deletions(-)lib/utils/fdt/fdt_helper.c +1
-1@@ -861,7 +861,7 @@ int fdt_parse_plicsw_node(void *fdt, int nodeoffset, unsigned long *plicsw_base, ?{ ????????const fdt32_t *val; ????????int rc, i, count; -???????uint64_t reg_addr, reg_size, cpu_offset, cpu_intc_offset; +???????uint64_t reg_addr, reg_size; ????????u32 phandle, hwirq, hartid, hcount;?
????????if (nodeoffset < 0 || !fdt || !plicsw_base ||lib/utils/fdt/fdt_helper.c +0
-0@@ -882,6 +882,8 @@ int fdt_parse_plicsw_node(void *fdt, int nodeoffset, unsigned long *plicsw_base,?
????????hcount = 0;
????????for (i = 0; i < (count / 2); i++) { +???????????????intcpu_offset,cpu_intc_offset; +
????????????????phandle =fdt32_to_cpu(val[2 * i]); ????????????????hwirq =fdt32_to_cpu(val[2 * i + 1]); ?lib/utils/fdt/fdt_helper.c +0
-0@@ -890,7 +892,7 @@ int fdt_parse_plicsw_node(void *fdt, int nodeoffset, unsigned long *plicsw_base, ????????????????????????continue;?
????????????????cpu_offset =fdt_parent_offset(fdt, cpu_intc_offset); -???????????????if (cpu_intc_offset< 0) +???????????????if (cpu_offset< 0) ????????????????????????continue;
?
????????????????rc =fdt_parse_hart_id(fdt, cpu_offset, &hartid);
PATCH v2 4/6 lib: fix fdt_parse_plicsw_node()
In reply to Heinrich Schuchardt? 2022-11-28???? 10:14 +0100?Heinrich Schuchardt???
Quoted 7 lines
cpu_offsetandcpu_intc_offsetmust be int to detect failed invocations offdt_node_offset_by_phandle()orfdt_parent_offset().After determining
cpu_offsetwe have to check this value and notcpu_intc_offset.Signed-off-by Heinrich Schuchardt <[email protected]>
Look good to me
Quoted 42 lines
---
v2:
????????check correct variable
---
?lib/utils/fdt/fdt_helper.c | 6 ++++--
?1 file changed, 4 insertions(+), 2 deletions(-)lib/utils/fdt/fdt_helper.c +1
-1@@ -861,7 +861,7 @@ int fdt_parse_plicsw_node(void *fdt, int nodeoffset, unsigned long *plicsw_base, ?{ ????????const fdt32_t *val; ????????int rc, i, count; -???????uint64_t reg_addr, reg_size, cpu_offset, cpu_intc_offset; +???????uint64_t reg_addr, reg_size; ????????u32 phandle, hwirq, hartid, hcount;?
????????if (nodeoffset < 0 || !fdt || !plicsw_base ||lib/utils/fdt/fdt_helper.c +0
-0@@ -882,6 +882,8 @@ int fdt_parse_plicsw_node(void *fdt, int nodeoffset, unsigned long *plicsw_base,?
????????hcount = 0;
????????for (i = 0; i < (count / 2); i++) { +???????????????intcpu_offset,cpu_intc_offset; +
????????????????phandle =fdt32_to_cpu(val[2 * i]); ????????????????hwirq =fdt32_to_cpu(val[2 * i + 1]); ?lib/utils/fdt/fdt_helper.c +0
-0@@ -890,7 +892,7 @@ int fdt_parse_plicsw_node(void *fdt, int nodeoffset, unsigned long *plicsw_base, ????????????????????????continue;?
????????????????cpu_offset =fdt_parent_offset(fdt, cpu_intc_offset); -???????????????if (cpu_intc_offset< 0) +???????????????if (cpu_offset< 0) ????????????????????????continue;
?
????????????????rc =fdt_parse_hart_id(fdt, cpu_offset, &hartid);Signature · 1 line
2.37.2
PATCH v2 4/6 lib: fix fdt_parse_plicsw_node()
In reply to Heinrich SchuchardtQuoted 7 lines · Heinrich Schuchardt
cpu_offsetandcpu_intc_offsetmust be int to detect failed invocations offdt_node_offset_by_phandle()orfdt_parent_offset().After determining
cpu_offsetwe have to check this value and notcpu_intc_offset.Signed-off-by Heinrich Schuchardt <[email protected]>
Looks good to me
PATCH v2 4/6 lib: fix fdt_parse_plicsw_node()
In reply to Heinrich SchuchardtQuoted 7 lines · Heinrich Schuchardt
cpu_offsetandcpu_intc_offsetmust be int to detect failed invocations offdt_node_offset_by_phandle()orfdt_parent_offset().After determining
cpu_offsetwe have to check this value and notcpu_intc_offset.
Quoted 8 lines
Signed-off-by Heinrich Schuchardt <[email protected]>---
v2:
check correct variable--- lib/utils/fdt/fdt_helper.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
PATCH v2 5/6 lib: simplify fdt_translate_address()
In reply to Heinrich SchuchardtDon't assign a value to offset which is never used.
---
v2:
Reviewed-by added
--- lib/utils/fdt/fdt_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/utils/fdt/fdt_helper.c +1 -1
@@ -124,7 +124,7 @@ static int fdt_translate_address(void *fdt, uint64_t reg, int parent,int i, rlen;int cell_addr, cell_size;const fdt32_t *ranges; -uint64_t offset =0 , caddr =0 , paddr =0 , rsize =0 ; +uint64_t offset, caddr =0 , paddr =0 , rsize =0 ; cell_addr =fdt_address_cells (fdt, parent);if (cell_addr <1 )
Signature · 1 line
2.37.2
PATCH v2 5/6 lib: simplify fdt_translate_address()
Quoted 12 lines · Heinrich Schuchardt
Don't assign a value to offset which is never used.
Signed-off-by Heinrich Schuchardt <[email protected]>Reviewed-by Xiang W <[email protected]>---
v2:
Reviewed-by added--- lib/utils/fdt/fdt_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH v2 6/6 lib: fix fdt_parse_aclint_node()
In reply to Heinrich SchuchardtAfter determining cpu_offset we have to check this variable and not cpu_intc_offset.
---
v2:
new patch
--- lib/utils/fdt/fdt_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/utils/fdt/fdt_helper.c +1 -1
@@ -772,7 +772,7 @@ int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer,continue ; cpu_offset =fdt_parent_offset (fdt, cpu_intc_offset); -if (cpu_intc_offset <0 ) +if (cpu_offset <0 )continue ; rc =fdt_parse_hart_id (fdt, cpu_offset, &hartid);
Signature · 1 line
2.37.2
PATCH v2 6/6 lib: fix fdt_parse_aclint_node()
? 2022-11-28???? 10:14 +0100?Heinrich Schuchardt???
Quoted 4 lines
After determining
cpu_offsetwe have to check this variable and notcpu_intc_offset.Signed-off-by Heinrich Schuchardt <[email protected]>
Look good to me
Quoted 20 lines
---
v2:
????????new patch
---
?lib/utils/fdt/fdt_helper.c | 2 +-
?1 file changed, 1 insertion(+), 1 deletion(-)lib/utils/fdt/fdt_helper.c +0
-0@@ -772,7 +772,7 @@ int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer, ????????????????????????continue;?
????????????????cpu_offset =fdt_parent_offset(fdt, cpu_intc_offset); -???????????????if (cpu_intc_offset< 0) +???????????????if (cpu_offset< 0) ????????????????????????continue;
?
????????????????rc =fdt_parse_hart_id(fdt, cpu_offset, &hartid);
PATCH v2 6/6 lib: fix fdt_parse_aclint_node()
In reply to Heinrich Schuchardt? 2022-11-28???? 10:14 +0100?Heinrich Schuchardt???
Quoted 4 lines
After determining
cpu_offsetwe have to check this variable and notcpu_intc_offset.Signed-off-by Heinrich Schuchardt <[email protected]>
Look good to me
Quoted 24 lines
---
v2:
????????new patch
---
?lib/utils/fdt/fdt_helper.c | 2 +-
?1 file changed, 1 insertion(+), 1 deletion(-)lib/utils/fdt/fdt_helper.c +0
-0@@ -772,7 +772,7 @@ int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer, ????????????????????????continue;?
????????????????cpu_offset =fdt_parent_offset(fdt, cpu_intc_offset); -???????????????if (cpu_intc_offset< 0) +???????????????if (cpu_offset< 0) ????????????????????????continue;
?
????????????????rc =fdt_parse_hart_id(fdt, cpu_offset, &hartid);Signature · 1 line
2.37.2
PATCH v2 6/6 lib: fix fdt_parse_aclint_node()
In reply to Heinrich SchuchardtQuoted 4 lines · Heinrich Schuchardt
After determining
cpu_offsetwe have to check this variable and notcpu_intc_offset.
Quoted 8 lines
Signed-off-by Heinrich Schuchardt <[email protected]>---
v2:
new patch--- lib/utils/fdt/fdt_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Anup Patel
Appliedv2 cover lib: fixes for fdt functions
In reply to Heinrich SchuchardtHi Heinrich,
Quoted 10 lines · Heinrich Schuchardt
* Use correct type for variables used in error checks
* Check correct variables
* Avoid duplicates checks
* Don't assign values that are never used.v2:
check correct variables
fixfdt_parse_aclint_node()too
Quoted 7 lines
Heinrich Schuchardt (6):
lib: simplifyfdt_parse_plmt_node()
lib: simplifyfdt_parse_plicsw_node()
lib: fixfdt_parse_plmt_node()
lib: fixfdt_parse_plicsw_node()
lib: simplifyfdt_translate_address()
lib: fixfdt_parse_aclint_node()
Thanks for catching and fixing all these issues.
Applied this series to the riscv/opensbi repo.
Regards,
Anup
Quoted 7 lines
lib/utils/fdt/fdt_helper.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)--
2.37.2