aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario Six2018-10-04 02:00:43 -0500
committerSimon Glass2018-11-14 11:16:27 -0600
commitb6f58bfd6d2ce35360d3993be8d07e494e33021e (patch)
treec45477f9b91d463c69c7bc4328aab47f882f3e6b /drivers
parent9b076095636b7def91ed6fd3f94383155057e962 (diff)
downloadu-boot-b6f58bfd6d2ce35360d3993be8d07e494e33021e.tar.gz
u-boot-b6f58bfd6d2ce35360d3993be8d07e494e33021e.tar.xz
u-boot-b6f58bfd6d2ce35360d3993be8d07e494e33021e.zip
regmap: Improve error handling
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 <agust@denx.de> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Mario Six <mario.six@gdsys.cc>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/core/regmap.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index 77f6f520a0..4ebab23349 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -67,8 +67,25 @@ int regmap_init_mem(ofnode node, struct regmap **mapp)
67 struct resource r; 67 struct resource r;
68 68
69 addr_len = ofnode_read_simple_addr_cells(ofnode_get_parent(node)); 69 addr_len = ofnode_read_simple_addr_cells(ofnode_get_parent(node));
70 if (addr_len < 0) {
71 debug("%s: Error while reading the addr length (ret = %d)\n",
72 ofnode_get_name(node), addr_len);
73 return addr_len;
74 }
75
70 size_len = ofnode_read_simple_size_cells(ofnode_get_parent(node)); 76 size_len = ofnode_read_simple_size_cells(ofnode_get_parent(node));
77 if (size_len < 0) {
78 debug("%s: Error while reading the size length: (ret = %d)\n",
79 ofnode_get_name(node), size_len);
80 return size_len;
81 }
82
71 both_len = addr_len + size_len; 83 both_len = addr_len + size_len;
84 if (!both_len) {
85 debug("%s: Both addr and size length are zero\n",
86 ofnode_get_name(node));
87 return -EINVAL;
88 }
72 89
73 len = ofnode_read_size(node, "reg"); 90 len = ofnode_read_size(node, "reg");
74 if (len < 0) 91 if (len < 0)