Linux I2C development
 help / color / mirror / Atom feed
From: "Brigham Campbell" <me@brighamcampbell.com>
To: "Wolfram Sang" <wsa+renesas@sang-engineering.com>,
	"Brigham Campbell" <me@brighamcampbell.com>
Cc: "Jean Delvare" <jdelvare@suse.de>,
	linux-i2c@vger.kernel.org,
	"Gero Schwäricke" <gero.schwaericke@sevenlab.de>
Subject: Re: [PATCH v5 1/2] i2c-tools: Allow passing device file paths
Date: Mon, 16 Nov 2026 00:23:07 -0700	[thread overview]
Message-ID: <DMWGDZA99U2V.ZHHILKEL821X@brighamcampbell.com> (raw)
In-Reply-To: <avB0jS2RfBHgZ6Zi@shikoro>

Wolfram,

Finally getting back to you after a good friend's wedding.

On Sun Nov 8, 2026 at 6:09 AM MST, Wolfram Sang wrote:
> On Wed, Jul 22, 2026 at 02:52:40AM -0600, Brigham Campbell wrote:
>> +	i2cbus_ul = strtoul(i2cbus_arg, &end, 0);
>> +	if (!*end && *i2cbus_arg) {
>> +		if (i2cbus_ul > 0xFFFFF) {
>> +			fprintf(stderr, "Error: I2C bus out of range!\n");
>> +			return -2;
>
> This fails if you use a name/path like "1111111111111". A diff like this
> makes it work:
>
> diff --git a/tools/i2cbusses.c b/tools/i2cbusses.c
> index 40d863f..47ebffa 100644
> --- a/tools/i2cbusses.c
> +++ b/tools/i2cbusses.c
> @@ -436,12 +436,7 @@ int open_i2c_dev(char *i2cbus_arg, char **filename, size_t size, int quiet)
>  	char *end;
>  
>  	i2cbus_ul = strtoul(i2cbus_arg, &end, 0);
> -	if (!*end && *i2cbus_arg) {
> -		if (i2cbus_ul > 0xFFFFF) {
> -			fprintf(stderr, "Error: I2C bus out of range!\n");
> -			return -2;
> -		}
> -
> +	if (!*end && *i2cbus_arg && i2cbus_ul < 0x100000) {
>  		return open_i2c_dev_by_nr(i2cbus_ul, *filename, size, quiet);
>  	}
>  
>
> That should do it, or?

Yes, this looks correct to me. However, the behavior of v5 was
intentional. It's reflective of the behavior of i2c-tools before my
patch: If the i2cbus argument can be parsed as an unsigned long, it will
be treated as the bus number. i2c-tools will never even make an attempt
to interpret it as a bus name.

$ pacman -Q i2c-tools
i2c-tools 4.4-4
$ i2cget -y 1111111111111 0
Error: I2C bus out of range!
...

Printing an error instead of trying to parse the argument as a name or
path is an undercommitment on the part of the user interface. It makes
breaking changes to that 0xFFFFF boundary easier. When we increase the
boundary size, we don't need to worry about users passing
(PREVIOUS_BOUNDARY + 1) and expecting it to be interpreted as a bus name
or device file path.

Even if we know the boundary will never change, I think it would be
better if users can always expect unsigned long values to be interpreted
as bus numbers directly, even if too-big values always result in an
error.

If you disagree, I'm happy to make the change or you can make it
yourself, but I'd like it to be a follow-on patch to this series because
with respect to this particular issue, I made an effort to preserve the
original behavior in this patch.

>> +	fprintf(stderr, "Error: Couldn't interpret `%s' as a bus number, "
>> +		"name, or device file path!\n", i2cbus_arg);
>> +
>
> I think this error message does its job very well. In my book, no need
> to make it more fine-grained.
>
> The rest (including patch 2) looks also good to me.

Thanks again for your thoughtful review!

-- 
Brigham Campbell
https://brighamcampbell.com


  parent reply	other threads:[~2026-11-16  7:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-22  8:52 [PATCH v5 0/2] i2c-tools: Make tools accept bus path Brigham Campbell
2026-07-22  8:52 ` [PATCH v5 1/2] i2c-tools: Allow passing device file paths Brigham Campbell
2026-11-08 13:09   ` Wolfram Sang
2026-11-15 22:34     ` Wolfram Sang
2026-11-16  7:23     ` Brigham Campbell [this message]
2026-11-16  8:00       ` Wolfram Sang
2026-07-22  8:52 ` [PATCH v5 2/2] i2c-tools: Document device paths as I2CBUS arg Brigham Campbell
2026-09-07 21:18 ` [PATCH v5 0/2] i2c-tools: Make tools accept bus path Brigham Campbell
2026-09-27 16:02   ` Wolfram Sang
2026-10-04  2:57     ` Brigham Campbell
2026-11-16  8:04 ` 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=DMWGDZA99U2V.ZHHILKEL821X@brighamcampbell.com \
    --to=me@brighamcampbell.com \
    --cc=gero.schwaericke@sevenlab.de \
    --cc=jdelvare@suse.de \
    --cc=linux-i2c@vger.kernel.org \
    --cc=wsa+renesas@sang-engineering.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox