Browse Source

i2ctransfer: replace broken "force" handling

Probably because of a bad rebase, the old and bogus handling (v1) of "force"
slipped into the latest version of the patch (v3). Apply the better
version from v2 which does the error handling correct and makes the code
a lot easier to understand.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
tags/v4.0
Wolfram Sang 8 years ago
committed by Wolfram Sang
parent
commit
1ed92ae76a
  1. 18
      tools/i2ctransfer.c

18
tools/i2ctransfer.c

@ -199,8 +199,6 @@ int main(int argc, char *argv[])
arg_ptr = end; arg_ptr = end;
if (*arg_ptr) { if (*arg_ptr) {
int whole_range_ok;
if (*arg_ptr++ != '@') { if (*arg_ptr++ != '@') {
fprintf(stderr, "Error: Unknown separator after length\n"); fprintf(stderr, "Error: Unknown separator after length\n");
goto err_out_with_arg; goto err_out_with_arg;
@ -211,16 +209,22 @@ int main(int argc, char *argv[])
* the address here. * the address here.
*/ */
if (!force) {
address = parse_i2c_address(arg_ptr); address = parse_i2c_address(arg_ptr);
/* With 'force', allow whole address range */
whole_range_ok = force && address == -2;
if (address < 0 && !whole_range_ok)
if (address < 0)
goto err_out_with_arg; goto err_out_with_arg;
/* Ensure address is not busy */ /* Ensure address is not busy */
if (!force && set_slave_addr(file, address, 0))
if (set_slave_addr(file, address, 0))
goto err_out_with_arg; 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;
}
}
} else { } else {
/* Reuse last address if possible */ /* Reuse last address if possible */
if (address < 0) { if (address < 0) {

Loading…
Cancel
Save