mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Roland Hieber <rhi@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Roland Hieber <rhi@pengutronix.de>
Subject: [PATCH] commands: i2c_read: default to reading one byte
Date: Wed, 22 Nov 2023 12:06:41 +0100	[thread overview]
Message-ID: <20231122110641.3683555-1-rhi@pengutronix.de> (raw)

The help text for i2c_read specifies that -c is optional:

    Usage: i2c_read [-bacrwv]

However, using i2c_read without -c falls through in do_i2c_read():

	if ((addr < 0) || (count < 1) || (addr > 0x7F))
		return COMMAND_ERROR_USAGE;

Actually make -c optional by initialising the count to 1.

Signed-off-by: Roland Hieber <rhi@pengutronix.de>
---
 commands/i2c.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/commands/i2c.c b/commands/i2c.c
index 997d49a94916..3a708531ee0a 100644
--- a/commands/i2c.c
+++ b/commands/i2c.c
@@ -195,7 +195,7 @@ static int do_i2c_read(int argc, char *argv[])
 	struct i2c_adapter *adapter = NULL;
 	struct i2c_client client;
 	u8 *buf;
-	int count = -1, addr = -1, reg = -1, verbose = 0, ret, opt, bus = 0, wide = 0;
+	int count = 1, addr = -1, reg = -1, verbose = 0, ret, opt, bus = 0, wide = 0;
 
 	while ((opt = getopt(argc, argv, "a:b:c:r:vw")) > 0) {
 		switch (opt) {
@@ -264,7 +264,7 @@ BAREBOX_CMD_HELP_OPT("-b BUS\t", "i2c bus number (default 0)")
 BAREBOX_CMD_HELP_OPT("-a ADDR\t", "i2c device address")
 BAREBOX_CMD_HELP_OPT("-r START", "start register (optional, master receive mode if none given)")
 BAREBOX_CMD_HELP_OPT("-w\t",       "use word (16 bit) wide access")
-BAREBOX_CMD_HELP_OPT("-c COUNT", "byte count")
+BAREBOX_CMD_HELP_OPT("-c COUNT", "byte count (default 1)")
 BAREBOX_CMD_HELP_OPT("-v\t",       "verbose")
 BAREBOX_CMD_HELP_END
 
-- 
2.39.2




             reply	other threads:[~2023-11-22 11:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-22 11:06 Roland Hieber [this message]
2023-11-22 15:23 ` 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=20231122110641.3683555-1-rhi@pengutronix.de \
    --to=rhi@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