Skip to content

Commit

Permalink
of/selftest: Fix off-by-one error in removal path
Browse files Browse the repository at this point in the history
The removal path for selftest data has an off by one error that causes
the code to dereference beyond the end of the nodes[] array on the first
pass through. The old code only worked by chance on a lot of platforms,
but the bug was recently exposed on aarch64.

The fix is simple. Decrement the node count before dereferencing, not
after.

Reported-by: Kevin Hilman <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Gaurav Minocha <[email protected]>
Cc: <[email protected]> # v3.17+
  • Loading branch information
glikely committed Nov 19, 2014
1 parent a0e27f5 commit c1a2086
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions drivers/of/selftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ static void selftest_data_remove(void)
return;
}

while (last_node_index >= 0) {
while (last_node_index-- > 0) {
if (nodes[last_node_index]) {
np = of_find_node_by_path(nodes[last_node_index]->full_name);
if (strcmp(np->full_name, "/aliases") != 0) {
Expand All @@ -908,7 +908,6 @@ static void selftest_data_remove(void)
}
}
}
last_node_index--;
}
}

Expand Down

0 comments on commit c1a2086

Please sign in to comment.