Skip to content

Commit 76db8a7

Browse files
hcodinagregkh
authored andcommitted
of: Fix error path in of_parse_phandle_with_args_map()
commit d7dfa7fde63dde4d2ec0083133efe2c6686c03ff upstream. 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: [email protected] Signed-off-by: Herve Codina <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Rob Herring (Arm) <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4fa2c63 commit 76db8a7

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
@@ -1597,8 +1597,10 @@ int of_parse_phandle_with_args_map(const struct device_node *np,
15971597
map_len--;
15981598

15991599
/* Check if not found */
1600-
if (!new)
1600+
if (!new) {
1601+
ret = -EINVAL;
16011602
goto put;
1603+
}
16021604

16031605
if (!of_device_is_available(new))
16041606
match = 0;
@@ -1608,17 +1610,20 @@ int of_parse_phandle_with_args_map(const struct device_node *np,
16081610
goto put;
16091611

16101612
/* Check for malformed properties */
1611-
if (WARN_ON(new_size > MAX_PHANDLE_ARGS))
1612-
goto put;
1613-
if (map_len < new_size)
1613+
if (WARN_ON(new_size > MAX_PHANDLE_ARGS) ||
1614+
map_len < new_size) {
1615+
ret = -EINVAL;
16141616
goto put;
1617+
}
16151618

16161619
/* Move forward by new node's #<list>-cells amount */
16171620
map += new_size;
16181621
map_len -= new_size;
16191622
}
1620-
if (!match)
1623+
if (!match) {
1624+
ret = -ENOENT;
16211625
goto put;
1626+
}
16221627

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

0 commit comments

Comments
 (0)