mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Stefan Lengfeld <s.lengfeld@phytec.de>
To: barebox@lists.infradead.org
Subject: [PATCH] commands: spi: fix chip select validation
Date: Mon, 7 Nov 2016 16:10:56 +0100	[thread overview]
Message-ID: <1478531456-11232-1-git-send-email-s.lengfeld@phytec.de> (raw)

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@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


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2016-11-07 15:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-07 15:10 Stefan Lengfeld [this message]
2016-11-08  7:56 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1478531456-11232-1-git-send-email-s.lengfeld@phytec.de \
    --to=s.lengfeld@phytec.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox