From: Jean Delvare <jdelvare@suse.de>
To: "Benoît Monin" <benoit.monin@bootlin.com>
Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>,
linux-i2c@vger.kernel.org,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Subject: Re: [PATCH i2c-tools v2 2/2] i2ctransfer: Add optional message modifier flags
Date: Tue, 20 Jan 2026 16:06:57 +0100 [thread overview]
Message-ID: <20260120160657.63de969a@endymion> (raw)
In-Reply-To: <2768446.lGaqSPkdTl@benoit.monin>
Hi Benoît,
On Fri, 16 Jan 2026 14:01:57 +0100, Benoît Monin wrote:
> On Tuesday, 13 January 2026 at 18:33:53 CET, Wolfram Sang wrote:
> [...]
> > > " DATA are LENGTH bytes for a write message. They can be shortened by a suffix:\n"
> > > " = (keep value constant until LENGTH)\n"
> > > " + (increase value by 1 until LENGTH)\n"
> > > @@ -202,12 +209,21 @@ int main(int argc, char *argv[])
> > > case PARSE_GET_DESC:
> > > flags = 0;
> > >
> > > - switch (*arg_ptr++) {
> > > - case 'r': flags |= I2C_M_RD; break;
> > > - case 'w': break;
> > > - default:
> > > - fprintf(stderr, "Error: Invalid direction\n");
> > > - goto err_out_with_arg;
> > > + for (int done = 0; !done; ) {
> > > + switch (*arg_ptr++) {
> > > + /* optional flags */
> > > + case 'i': flags |= I2C_M_IGNORE_NAK; break;
> > > + case 'n': flags |= I2C_M_NO_RD_ACK; break;
> > > + case 'p': flags |= I2C_M_STOP; break;
> > > + case 's': flags |= I2C_M_NOSTART; break;
> > > + case 't': flags |= I2C_M_REV_DIR_ADDR; break;
> >
> > Brainstorming here: maybe a macro could help:
> >
> > case 'i': add_flag_if_supported(flags, I2C_M_IGNORE_NAK);
> >
> > ?
> >
> I am having a hard time coming up with something here. There is the
> __is_defined() macro in the kernel source[1], it only returns 0 or 1, not
> the value of the define.
>
> Maybe defining as zero the flags that are undefined would be acceptable?
> E.g.
>
> #ifndef I2C_M_IGNORE_NAK
> #define I2C_M_IGNORE_NAK 0
> #endif
I don't think that's a good idea, because then you would simply ignore
the flag that was passed by the user if it's not supported? If so, this
is bad user experience. If the user asks for something unsupported, the
tool should report the lack of support, and fail.
> Or you have another idea?
I honestly think that a bunch of ifdefs in this part of the code would
work just fine and be acceptable. We don't plan to add more flags in
the future, and I think that's better than preprocessor magic which may
work or break depending on the compiler.
Something like:
/* optional flags */
case 'i':
#ifdef I2C_M_IGNORE_NAK
flags |= I2C_M_IGNORE_NAK;
#else
fprintf(stderr, "Error: Unsupported flag '%c'\n", 'i');
#endif
break;
case 'n':
#ifdef I2C_M_NO_RD_ACK
flags |= I2C_M_NO_RD_ACK;
#else
fprintf(stderr, "Error: Unsupported flag '%c'\n", 'n');
#endif
break;
case 'p':
#ifdef I2C_M_STOP
flags |= I2C_M_STOP;
#else
fprintf(stderr, "Error: Unsupported flag '%c'\n", 'p');
#endif
break;
case 's':
#ifdef I2C_M_NOSTART
flags |= I2C_M_NOSTART;
#else
fprintf(stderr, "Error: Unsupported flag '%c'\n", 's');
#endif
break;
case 't':
#ifdef I2C_M_REV_DIR_ADDR
flags |= I2C_M_REV_DIR_ADDR;
#else
fprintf(stderr, "Error: Unsupported flag '%c'\n", 't');
#endif
break;
That being said, I think you also need a second level of support check.
The above only checks if the flags are defined in the kernel headers,
which should generally correspond to the flags being supported by the
kernel. But just because the flags are known to the kernel, doesn't
mean that the i2c adapter you are operating on, supports protocol
mangling.
So I believe that you also need to extend check_funcs() to return the
supported functionality, and then check for I2C_FUNC_PROTOCOL_MANGLING
and I2C_FUNC_NOSTART after parsing the optional flags. If mangling
flags are passed by the user but the adapter's driver does not support
protocol mangling, the tool should report the incompatibility and stop.
--
Jean Delvare
SUSE L3 Support
next prev parent reply other threads:[~2026-01-20 15:07 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-23 13:22 [PATCH i2c-tools v2 0/2] Add support for message modifier flags Benoît Monin
2025-12-23 13:22 ` [PATCH i2c-tools v2 1/2] i2cdetect: Display mangling and nostart support Benoît Monin
2026-01-13 17:22 ` Wolfram Sang
2025-12-23 13:22 ` [PATCH i2c-tools v2 2/2] i2ctransfer: Add optional message modifier flags Benoît Monin
2026-01-13 17:33 ` Wolfram Sang
2026-01-16 13:01 ` Benoît Monin
2026-01-20 15:06 ` Jean Delvare [this message]
2026-01-20 14:45 ` Jean Delvare
2026-01-13 17:21 ` [PATCH i2c-tools v2 0/2] Add support for " Wolfram Sang
2026-01-20 14:15 ` Jean Delvare
2026-01-21 10:00 ` Benoît Monin
2026-01-21 18:37 ` Jean Delvare
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=20260120160657.63de969a@endymion \
--to=jdelvare@suse.de \
--cc=benoit.monin@bootlin.com \
--cc=linux-i2c@vger.kernel.org \
--cc=thomas.petazzoni@bootlin.com \
--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