All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wolfram Sang <wsa+renesas@sang-engineering.com>
To: linux-i2c@vger.kernel.org
Cc: linux-renesas-soc@vger.kernel.org,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Wolfram Sang" <wsa+renesas@sang-engineering.com>
Subject: [PATCH i2c-tools 1/2] i2ctransfer: replace broken "force" handling
Date: Mon,  3 Apr 2017 19:36:12 +0200	[thread overview]
Message-ID: <20170403173613.2238-1-wsa+renesas@sang-engineering.com> (raw)

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>
---
 tools/i2ctransfer.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

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

             reply	other threads:[~2017-04-03 17:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-03 17:36 Wolfram Sang [this message]
2017-04-03 17:36 ` [PATCH i2c-tools 2/2] i2ctransfer: grammar fixes in manpage Wolfram Sang
2017-04-04  7:31   ` Geert Uytterhoeven
2017-04-07 12:13     ` Wolfram Sang
2017-04-07 12:13 ` [PATCH i2c-tools 1/2] i2ctransfer: replace broken "force" handling Wolfram Sang

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=20170403173613.2238-1-wsa+renesas@sang-engineering.com \
    --to=wsa+renesas@sang-engineering.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=u.kleine-koenig@pengutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.