From: "Brigham Campbell" <me@brighamcampbell.com>
To: "Gero Schwäricke" <gero.schwaericke@sevenlab.de>,
"Brigham Campbell" <me@brighamcampbell.com>,
"Jean Delvare" <jdelvare@suse.de>,
linux-i2c@vger.kernel.org
Cc: "Wolfram Sang" <wsa+renesas@sang-engineering.com>
Subject: Re: [PATCH v4 1/2] i2c-tools: Allow passing device file paths
Date: Thu, 16 Jul 2026 08:49:41 -0600 [thread overview]
Message-ID: <DK02UVSWWGTN.2M4XXGFINRT1V@brighamcampbell.com> (raw)
In-Reply-To: <DJU1QIKM2DNQ.UOLEBWH0U0QQ@sevenlab.de>
Hi Gero,
On Thu Jul 9, 2026 at 6:40 AM MDT, Gero Schwäricke wrote:
> I just finished reviewing your patch. Aaand I saw Wolfram beat me to it
> by 20 minutes. I hope you forgive me for sending it as is even though it
> may now contain duplicates to his findings.
Not at all! I understand that it takes a lot of effort to carefully
review changes. I appreciate your work.
> On Mon Jul 6, 2026 at 6:27 AM CEST, Brigham Campbell wrote:
> [...]
>> @@ -410,7 +406,7 @@ int parse_i2c_address(const char *address_arg, int all_addrs)
>> return address;
>> }
>>
>> -int open_i2c_dev(int i2cbus, char *filename, size_t size, int quiet)
>> +int open_i2c_dev_num(int i2cbus, char *filename, size_t size, int quiet)
>> {
>> int file, len;
>>
>
> The lookup function uses suffix `_by_name`, so for consistency maybe use
> `_by_nr` instead? That is what it's called in `struct i2c_adap`.
I don't have a strong opinion. Happy to change to `_by_nr`.
> This is a minimally invasive change that makes this work, but it also
> spaghettifies the code base a little. `lookup_i2c_bus()` tries to parse
> the input to a bus number or, if that doesn't work, tries to resolve it
> as a bus name. And if that fails we try to open as path. The issue is
> that `lookup_i2c_bus()` is not very descriptive. Without reading the
> code it's not understandable what's happening. Instead I would propose
> to inline `lookup_i2c_bus()` and then have the logic inside
> `open_i2c_dev()` be imparative like:
>
> 1. try to convert input to i2cbus bus number, if it worked
> `return open_i2c_dev_by_nr()` with the bus number, otherwise,
> 2. try `lookup_i2c_bus_by_name()`, if it worked we now have the bus
> number, so we `return open_i2c_dev_by_nr()` with it, otherwise,
> 3. try to open as path.
You make some really good points. I'll make these changes in v5.
> I think we can also inline `open_i2c_dev_path()` and remove it's
> `fprintf()` in the failure case. We're just speculating here that it's a
> path, so printing at the end that the given input could not be found as
> bus number, bus name, or path is sufficient.
I agree that `open_i2c_dev_path()` should be inlined, but I don't think
it would be a good idea to remove its `fprintf()` altogether. How about
something like the following, which would make the error messages more
orthogonal?
if (errno != ENOENT) {
fprintf(stderr, "Error: Could not open file "
"`%s': %s\n", i2cbus_arg, strerror(errno));
if (errno == EACCES)
fprintf(stderr, "Run as root?\n");
return file;
}
fprintf(stderr, "Error: `%s' is not a bus number, name, or device file "
"path!\n", i2cbus_arg);
If the i2cbus_arg parameter didn't appear to be a file (ENOENT), it will
print an error indicating that all three methods failed. If it did
appear to be a file but couldn't open the file for whatever reason, it
will print the error along with a suggestion to run as root if it's a
permissions issue. This behavior reflects the behavior of
`open_i2c_dev_by_nr()`.
> I don't think there's a need to expose _num() and _path(). In fact, you
> can even remove lookup_i2c_bus() as that is not used anymore by any
> tool.
I'll clean up the header and remove unnecessary header exports in v5.
--
Brigham Campbell
https://brighamcampbell.com
next prev parent reply other threads:[~2026-07-16 14:47 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-06 4:27 [PATCH v4 0/2] i2c-tools: Make tools accept bus path Brigham Campbell
2026-07-06 4:27 ` [PATCH v4 1/2] i2c-tools: Allow passing device file paths Brigham Campbell
2026-07-09 12:18 ` Wolfram Sang
2026-07-09 12:40 ` Gero Schwäricke
2026-07-11 19:24 ` Wolfram Sang
2026-07-13 9:23 ` Gero Schwäricke
2026-07-13 15:06 ` Wolfram Sang
2026-07-14 9:30 ` Gero Schwäricke
2026-07-14 10:13 ` Wolfram Sang
2026-07-16 14:49 ` Brigham Campbell [this message]
2026-07-17 13:00 ` Gero Schwäricke
2026-07-19 22:22 ` Brigham Campbell
2026-07-13 9:37 ` Gero Schwäricke
2026-07-13 15:38 ` Brigham Campbell
2026-07-14 9:42 ` Gero Schwäricke
2026-07-16 14:17 ` Brigham Campbell
2026-07-06 4:27 ` [PATCH v4 2/2] i2c-tools: Document device paths as I2CBUS arg Brigham Campbell
2026-07-11 19:43 ` 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=DK02UVSWWGTN.2M4XXGFINRT1V@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