From: "Nuno Sá" <noname.nuno@gmail.com>
To: "Uwe Kleine-König" <u.kleine-koenig@baylibre.com>,
"Andy Shevchenko" <andy@kernel.org>
Cc: Cosmin Tanislav <cosmin.tanislav@analog.com>,
Lars-Peter Clausen <lars@metafoo.de>,
Michael Hennerich <Michael.Hennerich@analog.com>,
Jonathan Cameron <jic23@kernel.org>,
Michael Walle <michael@walle.cc>, Nuno Sa <nuno.sa@analog.com>,
Dumitru Ceclan <mitrutzceclan@gmail.com>,
linux-iio@vger.kernel.org
Subject: Re: [PATCH 1/2] iio: adc: ad4130: Fix comparison of channel setups
Date: Thu, 13 Feb 2025 14:14:08 +0000 [thread overview]
Message-ID: <a6737423fea51af836f28dcb67d4bf3a1892f38e.camel@gmail.com> (raw)
In-Reply-To: <ewed75ppixxpbo4tgifnaqcbfp4gkqht6p42hx3usizs7zg5cl@mln2ul5fxrgk>
On Wed, 2025-02-12 at 10:01 +0100, Uwe Kleine-König wrote:
> On Thu, Jan 30, 2025 at 08:14:39PM +0200, Andy Shevchenko wrote:
> > On Thu, Jan 30, 2025 at 06:45:01PM +0100, Uwe Kleine-König wrote:
> >
> > ...
> >
> > > + BUILD_BUG_ON(sizeof(*a) !=
> > > + sizeof(struct {
> > > + unsigned int iout0_val;
> > > + unsigned int iout1_val;
> > > + unsigned int burnout;
> > > + unsigned int pga;
> > > + unsigned int fs;
> > > + u32 ref_sel;
> > > + enum ad4130_filter_mode filter_mode;
> > > + bool ref_bufp;
> > > + bool ref_bufm;
> > > + }));
> >
> > Is I shuffle the fields (for whatever reason) this may give false positive
> > warnings.
>
> That's fine in by book. Whenever the struct is changed it's a good
> opportunity to check if the cmp function needs adaption, too.
>
In practise I think shuffling the fields is unlikely...
> > I think this BUILD_BUG_ON() is unreliable and ugly looking
> > (static_assert() won't help much here either), so on the second though I
> > think
> > it's better to simply add a comments in both places (here and near to the
> > structure definition) to explain that these needs to be in sync.
>
> The nice thing about BUILD_BUG_ON (or static assert) is that the
> compiler quite reliably enforces the two being in sync. A comment
> doesn't.
>
Agreed... I guess we could also add a comment on top of the affected struct so
that if someone messes with it, is also aware of this comparison.
- Nuno Sá
next prev parent reply other threads:[~2025-02-13 14:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-30 17:45 [PATCH 0/2] iio: adc: ad*: Fix comparisons using memcmp Uwe Kleine-König
2025-01-30 17:45 ` [PATCH 1/2] iio: adc: ad4130: Fix comparison of channel setups Uwe Kleine-König
2025-01-30 18:08 ` Andy Shevchenko
2025-01-30 18:14 ` Andy Shevchenko
2025-02-12 9:01 ` Uwe Kleine-König
2025-02-13 14:14 ` Nuno Sá [this message]
2025-01-30 17:45 ` [PATCH 2/2] iio: adc: ad7173: Fix comparison of channel configs Uwe Kleine-König
2025-01-30 18:11 ` Andy Shevchenko
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=a6737423fea51af836f28dcb67d4bf3a1892f38e.camel@gmail.com \
--to=noname.nuno@gmail.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=cosmin.tanislav@analog.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=michael@walle.cc \
--cc=mitrutzceclan@gmail.com \
--cc=nuno.sa@analog.com \
--cc=u.kleine-koenig@baylibre.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 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.