Re: [PATCH] commands: i2c_read: default to reading one byte

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux