[PATCH] commands: spi: fix chip select validation

Stefan Lengfeld s.lengfeld at phytec.de
Mon Nov 7 07:10:56 PST 2016


The chip selects are numbered 0..(max chip selects - 1). Chip select
with number <max chip selects> is invalid. Fix the check for that. Using
the out of bound chip select may hang your board.

Signed-off-by: Stefan Lengfeld <s.lengfeld at phytec.de>
---
 commands/spi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/commands/spi.c b/commands/spi.c
index 21db9ae..6603b34 100644
--- a/commands/spi.c
+++ b/commands/spi.c
@@ -68,8 +68,8 @@ static int do_spi(int argc, char *argv[])
 		return -ENODEV;
 	}
 
-	if (spi.chip_select > spi.master->num_chipselect) {
-		printf("spi chip select (%d)> master num chipselect (%d)\n",
+	if (spi.chip_select >= spi.master->num_chipselect) {
+		printf("spi chip select (%d) >= master num chipselect (%d)\n",
 			spi.chip_select, spi.master->num_chipselect);
 		return -EINVAL;
 	}
-- 
1.9.1




More information about the barebox mailing list