lib: fixes for fdt functions
cover lib: fixes for fdt functions
* Use correct type for variables used in error checks
* Avoid duplicates checks
* Don't assign values that are never used.
Heinrich Schuchardt (5):
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/utils/fdt/fdt_helper.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
Signature · 1 line
2.37.2
PATCH 1/5 lib: simplify fdt_parse_plmt_node()
We should not check !plmt_base || !plmt_size twice.
--- 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 1/5 lib: simplify fdt_parse_plmt_node()
? 2022-11-25???? 15:08 +0100?Heinrich Schuchardt???
Quoted 3 lines
We should not check !plmt_base || !plmt_size twice.
Signed-off-by Heinrich Schuchardt <[email protected]>
Look good to me
Quoted 21 lines
---
?lib/utils/fdt/fdt_helper.c | 2 +-
?1 file changed, 1 insertion(+), 1 deletion(-)lib/utils/fdt/fdt_helper.c +0
-0@@ -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)
????????????????returnSBI_ENODEV; ????????*plmt_base =reg_addr;
????????*plmt_size =reg_size;Signature · 1 line
2.37.2
PATCH 1/5 lib: simplify fdt_parse_plmt_node()
In reply to Heinrich SchuchardtQuoted 3 lines · Heinrich Schuchardt
We should not check !plmt_base || !plmt_size twice.
Signed-off-by Heinrich Schuchardt <[email protected]>
Looks good to me.
Quoted 19 lines
--- 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 2/5 lib: simplify fdt_parse_plicsw_node()
In reply to Heinrich SchuchardtWe should not check !plicsw_base || !size twice.
--- 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 2/5 lib: simplify fdt_parse_plicsw_node()
? 2022-11-25???? 15:08 +0100?Heinrich Schuchardt???
Quoted 3 lines
We should not check !plicsw_base || !size twice.
Signed-off-by Heinrich Schuchardt <[email protected]>
Look good to me
Quoted 21 lines
---
?lib/utils/fdt/fdt_helper.c | 2 +-
?1 file changed, 1 insertion(+), 1 deletion(-)lib/utils/fdt/fdt_helper.c +0
-0@@ -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)
????????????????returnSBI_ENODEV; ????????*plicsw_base =reg_addr;
????????*size =reg_size;Signature · 1 line
2.37.2
PATCH 2/5 lib: simplify fdt_parse_plicsw_node()
In reply to Heinrich SchuchardtQuoted 3 lines · Heinrich Schuchardt
We should not check !plicsw_base || !size twice.
Signed-off-by Heinrich Schuchardt <[email protected]>
Looks good to me
Quoted 25 lines
--- 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 · 7 lines
2.37.2 -- opensbi mailing list opensbi at lists.infradead.org http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 3/5 lib: fix fdt_parse_plmt_node()
In reply to Heinrich Schuchardtcpu_offset, cpu_intc_offset must int to discover failed invocations of fdt_node_offset_by_phandle() or fdt_parent_offset().
--- lib/utils/fdt/fdt_helper.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/utils/fdt/fdt_helper.c +3 -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 ||
@@ -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 ]);
Signature · 1 line
2.37.2
PATCH 3/5 lib: fix fdt_parse_plmt_node()
? 2022-11-25???? 15:08 +0100?Heinrich Schuchardt???
Quoted 4 lines
cpu_offset,cpu_intc_offsetmust int to discover failed invocations offdt_node_offset_by_phandle()orfdt_parent_offset().Signed-off-by Heinrich Schuchardt <[email protected]>
https://github.com/riscv-software-src/opensbi/blob/master/lib/utils/fdt/fdt_helper.c#L837
if (cpu_intc_offset < 0) should be if (cpu_offset < 0)
Regards,
Xiang W
Quoted 30 lines
---
?lib/utils/fdt/fdt_helper.c | 4 +++-
?1 file changed, 3 insertions(+), 1 deletion(-)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]); ?Signature · 1 line
2.37.2
PATCH 4/5 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().
--- lib/utils/fdt/fdt_helper.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/utils/fdt/fdt_helper.c +3 -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 ||
@@ -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 ]);
Signature · 1 line
2.37.2
PATCH 4/5 lib: fix fdt_parse_plicsw_node()
? 2022-11-25???? 15:08 +0100?Heinrich Schuchardt???
Quoted 4 lines
cpu_offsetandcpu_intc_offsetmust be int to detect failed invocations offdt_node_offset_by_phandle()orfdt_parent_offset().Signed-off-by Heinrich Schuchardt <[email protected]>
https://github.com/riscv-software-src/opensbi/blob/master/lib/utils/fdt/fdt_helper.c#L891
if (cpu_intc_offset < 0) should be if (cpu_offset < 0)
Regards,
Xiang W
Quoted 30 lines
---
?lib/utils/fdt/fdt_helper.c | 4 +++-
?1 file changed, 3 insertions(+), 1 deletion(-)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]); ?Signature · 1 line
2.37.2
PATCH 5/5 lib: simplify fdt_translate_address()
In reply to Heinrich SchuchardtDon't assign a value to offset which is never used.
--- 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 5/5 lib: simplify fdt_translate_address()
? 2022-11-25???? 15:08 +0100?Heinrich Schuchardt???
Quoted 3 lines
Don't assign a value to offset which is never used.
Signed-off-by Heinrich Schuchardt <[email protected]>
Look good to me
Quoted 21 lines
---
?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