Re: [U-Boot] [PATCH v4 04/13] regmap: Improve error handling

2018-08-06 Thread Anatolij Gustschin
On Fri,  3 Aug 2018 10:01:09 +0200
Mario Six mario@gdsys.cc wrote:

> ofnode_read_simple_addr_cells may fail and return a negative error code.
> Check for this when initializing regmaps.
> 
> Also check if both_len is zero, since this is perfectly possible, and
> would lead to a division-by-zero further down the line.
> 
> Reviewed-by: Anatolij Gustschin 
> Reviewed-by: Simon Glass 
> Signed-off-by: Mario Six 
> 
> ---
> 
> v3 -> v4:
> No changes
> 
> v2 -> v3:
> New in v3
> 
> ---
>  drivers/core/regmap.c | 17 +
>  1 file changed, 17 insertions(+)

Applied to u-boot-staging/ag...@denx.de, thanks!

--
Anatolij
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v4 04/13] regmap: Improve error handling

2018-08-03 Thread Mario Six
ofnode_read_simple_addr_cells may fail and return a negative error code.
Check for this when initializing regmaps.

Also check if both_len is zero, since this is perfectly possible, and
would lead to a division-by-zero further down the line.

Reviewed-by: Anatolij Gustschin 
Reviewed-by: Simon Glass 
Signed-off-by: Mario Six 

---

v3 -> v4:
No changes

v2 -> v3:
New in v3

---
 drivers/core/regmap.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index 77f6f520a06..4ebab233490 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -67,8 +67,25 @@ int regmap_init_mem(ofnode node, struct regmap **mapp)
struct resource r;

addr_len = ofnode_read_simple_addr_cells(ofnode_get_parent(node));
+   if (addr_len < 0) {
+   debug("%s: Error while reading the addr length (ret = %d)\n",
+ ofnode_get_name(node), addr_len);
+   return addr_len;
+   }
+
size_len = ofnode_read_simple_size_cells(ofnode_get_parent(node));
+   if (size_len < 0) {
+   debug("%s: Error while reading the size length: (ret = %d)\n",
+ ofnode_get_name(node), size_len);
+   return size_len;
+   }
+
both_len = addr_len + size_len;
+   if (!both_len) {
+   debug("%s: Both addr and size length are zero\n",
+ ofnode_get_name(node));
+   return -EINVAL;
+   }

len = ofnode_read_size(node, "reg");
if (len < 0)
--
2.11.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot