mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] commands: i2c_read: default to reading one byte
@ 2023-11-22 11:06 Roland Hieber
  2023-11-22 15:23 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Roland Hieber @ 2023-11-22 11:06 UTC (permalink / raw)
  To: barebox; +Cc: Roland Hieber

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




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] commands: i2c_read: default to reading one byte
  2023-11-22 11:06 [PATCH] commands: i2c_read: default to reading one byte Roland Hieber
@ 2023-11-22 15:23 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2023-11-22 15:23 UTC (permalink / raw)
  To: Roland Hieber; +Cc: barebox

On Wed, Nov 22, 2023 at 12:06:41PM +0100, Roland Hieber wrote:
> 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(-)

Applied, thanks

Sascha

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

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-11-22 15:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-22 11:06 [PATCH] commands: i2c_read: default to reading one byte Roland Hieber
2023-11-22 15:23 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox