From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 1/2] i2c_probe: limit slave addresses to [0x04, 0x77]
Date: Fri, 25 Jan 2019 21:59:34 +0100 [thread overview]
Message-ID: <20190125205935.15135-1-u.kleine-koenig@pengutronix.de> (raw)
Adresses below 0x04 and above 0x77 are reserved in the i2c bus
specification, so don't probe these addresses unless requested
explicitly.
Also do more strict boundary checking:
- ensure start address is greater or equal to zero;
- don't decrease stopaddr after checking it being greater or equal to
startaddr.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
commands/i2c.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/commands/i2c.c b/commands/i2c.c
index 2f7f820d4d55..65ff7378ec14 100644
--- a/commands/i2c.c
+++ b/commands/i2c.c
@@ -44,7 +44,7 @@ static void i2c_probe_range(struct i2c_adapter *adapter, int startaddr, int stop
static int do_i2c_probe(int argc, char *argv[])
{
struct i2c_adapter *adapter = NULL;
- int startaddr = 0, stopaddr = 0x7f;
+ int startaddr = 4, stopaddr = 0x77;
if (argc > 1) {
adapter = i2c_get_adapter(simple_strtoul(argv[1], NULL, 0));
@@ -57,13 +57,15 @@ static int do_i2c_probe(int argc, char *argv[])
if (argc > 3)
stopaddr = simple_strtol(argv[3], NULL, 0);
+ if (stopaddr > 0x7f)
+ stopaddr = 0x7f;
+
+ if (startaddr < 0)
+ startaddr = 0;
if (startaddr > stopaddr)
return COMMAND_ERROR_USAGE;
- if (stopaddr > 0x7F)
- stopaddr = 0x7F;
-
if (adapter) {
i2c_probe_range(adapter, startaddr, stopaddr);
} else {
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next reply other threads:[~2019-01-25 20:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-25 20:59 Uwe Kleine-König [this message]
2019-01-25 20:59 ` [PATCH 2/2] i2c_probe: Use a quick write transfer instead of writing a zero Uwe Kleine-König
2019-01-28 9:01 ` [PATCH 1/2] i2c_probe: limit slave addresses to [0x04, 0x77] 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=20190125205935.15135-1-u.kleine-koenig@pengutronix.de \
--to=u.kleine-koenig@pengutronix.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