Skip to content

Commit d7dfa7f

Browse files
hcodinarobherring
authored andcommitted
of: Fix error path in of_parse_phandle_with_args_map()
The current code uses some 'goto put;' to cancel the parsing operation and can lead to a return code value of 0 even on error cases. Indeed, some goto calls are done from a loop without setting the ret value explicitly before the goto call and so the ret value can be set to 0 due to operation done in previous loop iteration. For instance match can be set to 0 in the previous loop iteration (leading to a new iteration) but ret can also be set to 0 it the of_property_read_u32() call succeed. In that case if no match are found or if an error is detected the new iteration, the return value can be wrongly 0. Avoid those cases setting the ret value explicitly before the goto calls. Fixes: bd6f2fd ("of: Support parsing phandle argument lists through a nexus node") Cc: stable@vger.kernel.org Signed-off-by: Herve Codina <herve.codina@bootlin.com> Link: https://lore.kernel.org/r/20241202165819.158681-1-herve.codina@bootlin.com Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
1 parent 2395217 commit d7dfa7f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

drivers/of/base.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,8 +1471,10 @@ int of_parse_phandle_with_args_map(const struct device_node *np,
14711471
map_len--;
14721472

14731473
/* Check if not found */
1474-
if (!new)
1474+
if (!new) {
1475+
ret = -EINVAL;
14751476
goto put;
1477+
}
14761478

14771479
if (!of_device_is_available(new))
14781480
match = 0;
@@ -1482,17 +1484,20 @@ int of_parse_phandle_with_args_map(const struct device_node *np,
14821484
goto put;
14831485

14841486
/* Check for malformed properties */
1485-
if (WARN_ON(new_size > MAX_PHANDLE_ARGS))
1486-
goto put;
1487-
if (map_len < new_size)
1487+
if (WARN_ON(new_size > MAX_PHANDLE_ARGS) ||
1488+
map_len < new_size) {
1489+
ret = -EINVAL;
14881490
goto put;
1491+
}
14891492

14901493
/* Move forward by new node's #<list>-cells amount */
14911494
map += new_size;
14921495
map_len -= new_size;
14931496
}
1494-
if (!match)
1497+
if (!match) {
1498+
ret = -ENOENT;
14951499
goto put;
1500+
}
14961501

14971502
/* Get the <list>-map-pass-thru property (optional) */
14981503
pass = of_get_property(cur, pass_name, NULL);

0 commit comments

Comments
 (0)