From owner-dev-commits-src-all@freebsd.org Wed May 19 18:58:00 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id BB595648D4F; Wed, 19 May 2021 18:58:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Flhvr4mbZz3mJl; Wed, 19 May 2021 18:58:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8D80917E5B; Wed, 19 May 2021 18:58:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 14JIw0FR000992; Wed, 19 May 2021 18:58:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 14JIw0L1000991; Wed, 19 May 2021 18:58:00 GMT (envelope-from git) Date: Wed, 19 May 2021 18:58:00 GMT Message-Id: <202105191858.14JIw0L1000991@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Poul-Henning Kamp Subject: git: f4583ebabc0d - main - i2c(8): Polish: sort switches, dont confuse address & offset MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: phk X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f4583ebabc0db99992f65bcfb3eb8d8a95921a34 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 May 2021 18:58:00 -0000 The branch main has been updated by phk: URL: https://cgit.FreeBSD.org/src/commit/?id=f4583ebabc0db99992f65bcfb3eb8d8a95921a34 commit f4583ebabc0db99992f65bcfb3eb8d8a95921a34 Author: Poul-Henning Kamp AuthorDate: 2021-05-19 18:47:32 +0000 Commit: Poul-Henning Kamp CommitDate: 2021-05-19 18:47:32 +0000 i2c(8): Polish: sort switches, dont confuse address & offset --- usr.sbin/i2c/i2c.c | 60 +++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/usr.sbin/i2c/i2c.c b/usr.sbin/i2c/i2c.c index ef0ca0e8fda5..099418a5715c 100644 --- a/usr.sbin/i2c/i2c.c +++ b/usr.sbin/i2c/i2c.c @@ -281,7 +281,7 @@ reset_bus(const char *dev, int fd, int verbose) } static const char * -encode_offset(const char *width, unsigned address, uint8_t *dst, size_t *len) +encode_offset(const char *width, unsigned offset, uint8_t *dst, size_t *len) { if (!strcmp(width, "0")) { @@ -289,21 +289,21 @@ encode_offset(const char *width, unsigned address, uint8_t *dst, size_t *len) return (NULL); } if (!strcmp(width, "8")) { - if (address > 0xff) - return ("Invalid 8-bit address\n"); - *dst = address; + if (offset > 0xff) + return ("Invalid 8-bit offset\n"); + *dst = offset; *len = 1; return (NULL); } - if (address > 0xffff) - return ("Invalid 16-bit address\n"); + if (offset > 0xffff) + return ("Invalid 16-bit offset\n"); if (!strcmp(width, "16LE") || !strcmp(width, "16")) { - le16enc(dst, address); + le16enc(dst, offset); *len = 2; return (NULL); } if (!strcmp(width, "16BE")) { - be16enc(dst, address); + be16enc(dst, offset); *len = 2; return (NULL); } @@ -594,26 +594,21 @@ main(int argc, char** argv) usage("Bad -a argument (01..7f)"); i2c_opt.addr <<= 1; break; - case 'f': - dev = optarg; + case 'b': + i2c_opt.binary = 1; + break; + case 'c': + i2c_opt.count = (strtoul(optarg, 0, 10)); + if (i2c_opt.count == 0 && errno == EINVAL) + usage("Bad -c argument (decimal)"); break; case 'd': if (strcmp(optarg, "r") && strcmp(optarg, "w")) usage("Bad -d argument ([r|w])"); i2c_opt.dir = optarg[0]; break; - case 'o': - i2c_opt.off = strtoul(optarg, 0, 16); - if (i2c_opt.off == 0 && errno == EINVAL) - usage("Bad -o argument (hex)"); - break; - case 'w': - i2c_opt.width = optarg; // checked later. - break; - case 'c': - i2c_opt.count = (strtoul(optarg, 0, 10)); - if (i2c_opt.count == 0 && errno == EINVAL) - usage("Bad -c argument (decimal)"); + case 'f': + dev = optarg; break; case 'm': if (!strcmp(optarg, "no")) @@ -630,14 +625,19 @@ main(int argc, char** argv) case 'n': i2c_opt.skip = optarg; break; - case 's': break; - case 'b': - i2c_opt.binary = 1; + case 'o': + i2c_opt.off = strtoul(optarg, 0, 16); + if (i2c_opt.off == 0 && errno == EINVAL) + usage("Bad -o argument (hex)"); break; + case 'r': break; + case 's': break; case 'v': i2c_opt.verbose = 1; break; - case 'r': break; + case 'w': + i2c_opt.width = optarg; // checked later. + break; default: fprintf(stderr, "Illegal -%c option", ch); usage(NULL); @@ -660,7 +660,7 @@ main(int argc, char** argv) i2c_opt.off_buf, &i2c_opt.off_len); if (err_msg != NULL) { fprintf(stderr, "%s", err_msg); - exit(EX_USAGE); + return(EX_USAGE); } if (i2c_opt.verbose) @@ -677,15 +677,15 @@ main(int argc, char** argv) } switch (do_what) { + case 'a': + error = access_bus(fd, i2c_opt); + break; case 's': error = scan_bus(dev, fd, i2c_opt.skip, i2c_opt.verbose); break; case 'r': error = reset_bus(dev, fd, i2c_opt.verbose); break; - case 'a': - error = access_bus(fd, i2c_opt); - break; default: assert("Bad do_what"); }