Re: [PATCH RFC] regmap: kunit: add tests for values wider than val_bits
From: Raffaele Tranfaglia
Date: Tue Nov 24 2026 - 02:29:51 EST
On Wed, 18 Nov 2026 at 11:30, Mark Brown <broonie@xxxxxxxxxx> wrote:
> On Wed, Nov 18, 2026 at 11:04:56AM +0200, Andy Shevchenko wrote:
> > Do we really need those explicit castings? I think they are already inside
> > the byteorder macros. Also we have be16_to_cpup() and le16_to_cpup() which
> > might help.
> If we do need the casts that probably indicates a problem.
Yes, the buffer was declared as u16 * while it holds __be16/__le16
data. I will use be16_to_cpup()/le16_to_cpup() on a void pointer in v2,
which needs no casts.
On the main question, Andy wrote:
> It means we can't enable this test cases without addressing the underneath
> implementation(s) of the regmap. I think the proper solution is to cut upper
> bits on the regmap level, so the cache and HW will see it as expected.
Mark, would you be ok with masking in the core? I would mask val at the
start of _regmap_write(), before the cache is updated, so that the cache
and the bus see the same value, and document it for regmap_write().
Some regmaps leave val_bits at 0 (e.g. ad4130, ad4170-4 and
phy-cadence-sierra), so masking has to be skipped for those. The
reg_update_bits() and reg_noinc_write() callbacks do not go through
_regmap_write(), so I would check them separately.
The alternative is to reject such values with -EINVAL for all buses, but
that could break drivers that currently rely on the formatters dropping
the upper bits.
If masking is fine, v2 will be a series with the regmap change first and
the tests after it, so that they pass.
Best regards,
Raffaele