diff mbox series

i2ctransfer: '-f' shouldn't allow all addresses, '-a' does that

Message ID 20180324151524.7407-1-wsa@the-dreams.de
State Accepted
Headers show
Series i2ctransfer: '-f' shouldn't allow all addresses, '-a' does that | expand

Commit Message

Wolfram Sang March 24, 2018, 3:15 p.m. UTC
We now have the flag '-a' for all i2c-tools to allow access for all
addresses. This was tied in i2ctransfer to the '-f' flag. Remove it and
keep that feature to '-a' only. This is also more in sync with the other
i2c-tools which use '-f' only to access already busy devices.

Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
---
 tools/i2ctransfer.8 |  2 +-
 tools/i2ctransfer.c | 23 +++++++----------------
 2 files changed, 8 insertions(+), 17 deletions(-)

Comments

Peter Rosin March 27, 2018, 6:08 p.m. UTC | #1
On 2018-03-24 16:15, Wolfram Sang wrote:
> We now have the flag '-a' for all i2c-tools to allow access for all
> addresses. This was tied in i2ctransfer to the '-f' flag. Remove it and
> keep that feature to '-a' only. This is also more in sync with the other
> i2c-tools which use '-f' only to access already busy devices.
> 
> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>

Reviewed-by: Peter Rosin <peda@axentia.se>

Cheers,
peda

> ---
>  tools/i2ctransfer.8 |  2 +-
>  tools/i2ctransfer.c | 23 +++++++----------------
>  2 files changed, 8 insertions(+), 17 deletions(-)
> 
> diff --git a/tools/i2ctransfer.8 b/tools/i2ctransfer.8
> index 99123fa..5d3cc27 100644
> --- a/tools/i2ctransfer.8
> +++ b/tools/i2ctransfer.8
> @@ -41,7 +41,7 @@ This program helps you to create proper transfers for your needs.
>  Force access to the device even if it is already busy.
>  By default,
>  .B i2ctransfer
> -will refuse to access addresses marked as reserved by the I2C standard or to a device which is already under the control of a kernel driver.
> +will refuse to access a device which is already under the control of a kernel driver.
>  Using this flag is dangerous, it can seriously confuse the kernel driver in question.
>  It can also cause
>  .B i2ctransfer
> diff --git a/tools/i2ctransfer.c b/tools/i2ctransfer.c
> index 8e9ce63..7b95d48 100644
> --- a/tools/i2ctransfer.c
> +++ b/tools/i2ctransfer.c
> @@ -210,22 +210,13 @@ int main(int argc, char *argv[])
>  				 * the address here.
>  				 */
>  
> -				if (!force) {
> -					address = parse_i2c_address(arg_ptr, all_addrs);
> -					if (address < 0)
> -						goto err_out_with_arg;
> -
> -					/* Ensure address is not busy */
> -					if (set_slave_addr(file, address, 0))
> -						goto err_out_with_arg;
> -				} else {
> -					/* 'force' allows whole address range */
> -					address = strtol(arg_ptr, &end, 0);
> -					if (arg_ptr == end || *end || address > 0x7f) {
> -						fprintf(stderr, "Error: Invalid chip address\n");
> -						goto err_out_with_arg;
> -					}
> -				}
> +				address = parse_i2c_address(arg_ptr, all_addrs);
> +				if (address < 0)
> +					goto err_out_with_arg;
> +
> +				/* Ensure address is not busy */
> +				if (!force && set_slave_addr(file, address, 0))
> +					goto err_out_with_arg;
>  			} else {
>  				/* Reuse last address if possible */
>  				if (address < 0) {
>
Wolfram Sang April 4, 2018, 6:54 p.m. UTC | #2
On Sat, Mar 24, 2018 at 04:15:24PM +0100, Wolfram Sang wrote:
> We now have the flag '-a' for all i2c-tools to allow access for all
> addresses. This was tied in i2ctransfer to the '-f' flag. Remove it and
> keep that feature to '-a' only. This is also more in sync with the other
> i2c-tools which use '-f' only to access already busy devices.
> 
> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>

Applied to master. Thanks Peter for the review!
diff mbox series

Patch

diff --git a/tools/i2ctransfer.8 b/tools/i2ctransfer.8
index 99123fa..5d3cc27 100644
--- a/tools/i2ctransfer.8
+++ b/tools/i2ctransfer.8
@@ -41,7 +41,7 @@  This program helps you to create proper transfers for your needs.
 Force access to the device even if it is already busy.
 By default,
 .B i2ctransfer
-will refuse to access addresses marked as reserved by the I2C standard or to a device which is already under the control of a kernel driver.
+will refuse to access a device which is already under the control of a kernel driver.
 Using this flag is dangerous, it can seriously confuse the kernel driver in question.
 It can also cause
 .B i2ctransfer
diff --git a/tools/i2ctransfer.c b/tools/i2ctransfer.c
index 8e9ce63..7b95d48 100644
--- a/tools/i2ctransfer.c
+++ b/tools/i2ctransfer.c
@@ -210,22 +210,13 @@  int main(int argc, char *argv[])
 				 * the address here.
 				 */
 
-				if (!force) {
-					address = parse_i2c_address(arg_ptr, all_addrs);
-					if (address < 0)
-						goto err_out_with_arg;
-
-					/* Ensure address is not busy */
-					if (set_slave_addr(file, address, 0))
-						goto err_out_with_arg;
-				} else {
-					/* 'force' allows whole address range */
-					address = strtol(arg_ptr, &end, 0);
-					if (arg_ptr == end || *end || address > 0x7f) {
-						fprintf(stderr, "Error: Invalid chip address\n");
-						goto err_out_with_arg;
-					}
-				}
+				address = parse_i2c_address(arg_ptr, all_addrs);
+				if (address < 0)
+					goto err_out_with_arg;
+
+				/* Ensure address is not busy */
+				if (!force && set_slave_addr(file, address, 0))
+					goto err_out_with_arg;
 			} else {
 				/* Reuse last address if possible */
 				if (address < 0) {