devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of/selftest: Fix off-by-one error in removal path
@ 2014-11-19 17:18 Grant Likely
  0 siblings, 0 replies; only message in thread
From: Grant Likely @ 2014-11-19 17:18 UTC (permalink / raw)
  To: linux-kernel, devicetree
  Cc: Kevin Hilman, Grant Likely, Rob Herring, Gaurav Minocha, stable

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 <khilman@linaro.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Gaurav Minocha <gaurav.minocha.os@gmail.com>
Cc: <stable@vger.kernel.org> # v3.17+
---
 drivers/of/selftest.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c
index 11b873c54a77..e6c14dc400e9 100644
--- a/drivers/of/selftest.c
+++ b/drivers/of/selftest.c
@@ -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) {
@@ -908,7 +908,6 @@ static void selftest_data_remove(void)
 				}
 			}
 		}
-		last_node_index--;
 	}
 }
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2014-11-19 17:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-19 17:18 [PATCH] of/selftest: Fix off-by-one error in removal path Grant Likely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).