Re: [PATCH 1/2] iio: light: adux1020: fix interrupt clear value on SMBus-only adapters

From: Raffaele Tranfaglia

Date: Tue Nov 10 2026 - 17:18:13 EST


On Tue, 10 Nov 2026 at 10:17, Andy Shevchenko
<andriy.shevchenko@xxxxxxxxx> wrote:
> Can you give a Kunit test case? Because regmap specifies the val_bits == 16.
> See also [3].

I read your analysis in [3] and I agree with it for the bus it
describes. regmap has two write paths though, selected in
__regmap_init() by what the bus provides [4]:

- a bus with raw .write/.read (regmap_i2c, used when the adapter has
I2C_FUNC_I2C) goes through _regmap_bus_raw_write(), which uses
format_val, so regmap_format_16_be() drops everything above 16 bits,
as you describe;

- a bus with only .reg_write/.reg_read (regmap_smbus_word_swapped, used
when the adapter only has I2C_FUNC_SMBUS_WORD_DATA) skips the format
initialization and goes through _regmap_bus_reg_write() [5], which
passes val to bus->reg_write() unmodified.
regmap_smbus_word_write_swapped() then returns -EINVAL for
val > 0xffff [6].

i2c-stub is SMBus only, so adux1020 takes the second path there.

The existing regmap KUnit buses match these two paths (regmap-ram is
reg_write only, regmap-raw-ram is formatted), so I added a test case for
each, writing 0xffffff0f to a regmap with val_bits = 16 and expecting
0xff0f on the bus:

# raw_write_wider_than_val_bits: pass:10 fail:0 skip:0 total:10
ok 37 raw_write_wider_than_val_bits

# write_wider_than_val_bits: EXPECTATION FAILED at
drivers/base/regmap/regmap-kunit.c:342
Expected 0xff0f == data->vals[param->from_reg], but
0xff0f == 65295 (0xff0f)
data->vals[param->from_reg] == 4294967055 (0xffffff0f)
# write_wider_than_val_bits: pass:0 fail:10 skip:0 total:10
not ok 2 write_wider_than_val_bits

I can send the test to Mark as an RFC, to ask whether regmap_write()
should mask the value to val_bits for reg_write buses, or reject it
consistently.

[4] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/base/regmap/regmap.c?h=v7.4-rc1#n963
[5] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/base/regmap/regmap.c?h=v7.4-rc1#n2153
[6] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/base/regmap/regmap-i2c.c?h=v7.4-rc1#n127

> > However, even if regmap changed, the driver would still be passing a
> > 32-bit value for a 16-bit register.
>
> Is it a problem?

Today it is on SMBus-only adapters, as above. If regmap ends up masking
the value, patch 1 could still be used as the fix for stable releases
since, from my understanding, small self-contained fixes are preferred
for backporting.

Best regards,
Raffaele