[PATCH v2 0/3] regmap: handle values wider than val_bits consistently
From: Raffaele Tranfaglia via B4 Relay
Date: Wed Nov 25 2026 - 03:09:58 EST
regmap_write() takes an unsigned int, and what happens to the bits above
val_bits currently depends on the bus and on the cache type. As agreed
on the RFC, mask them in the core, before the cache is updated.
Patch 1 prepares nau8360, which sets val_bits = 16 but writes 32-bit
values to its DSP registers, so it would break with the masking.
Patch 2 adds the masking.
Patch 3 adds the KUnit tests from the RFC, which now pass.
I searched for other drivers whose reg_write() handles more bits than
val_bits and found no other clear case, but the search cannot be
exhaustive. Implementations of reg_update_bits() do not go through
_regmap_write() and are not changed.
The regmap KUnit tests pass on arm64 QEMU. The nau8360 change is only
compile tested.
I prepared these patches with the help of an AI coding assistant, and
reviewed and tested them myself.
---
Changes in v2:
- No longer an RFC.
- New patch masking the values in the regmap core (Andy, Mark).
- New patch preparing nau8360.
- Use be16_to_cpup()/le16_to_cpup() instead of casts in the tests (Andy,
Mark).
- Rebased on regmap for-7.5.
- Link to v1: https://patch.msgid.link/20261117-regmap-kunit-val-bits-v1-1-a1cd02063217@xxxxxxxxx
---
Raffaele Tranfaglia (3):
ASoC: codecs: nau8360: set val_bits to the widest register size
regmap: mask values to val_bits on write
regmap: kunit: add tests for values wider than val_bits
drivers/base/regmap/internal.h | 1 +
drivers/base/regmap/regmap-kunit.c | 60 ++++++++++++++++++++++++++++++++++++++
drivers/base/regmap/regmap.c | 14 ++++++++-
sound/soc/codecs/nau8360.c | 3 +-
sound/soc/codecs/nau8360.h | 3 +-
5 files changed, 77 insertions(+), 4 deletions(-)
---
base-commit: 573c689219af87f6d5a4bbf809c174e7f28a23a1
change-id: 20261117-regmap-kunit-val-bits-6473305e083b
Best regards,
--
Raffaele Tranfaglia <raffaele.tranfaglia@xxxxxxxxx>