[PATCH 0/3] regmap: 2nd clean up and improve __regmap_init()
From: Peng Fan
Date: Sat Nov 21 2026 - 07:44:33 EST
This is a re-post of patch 8-10 from [1] with addressing Mark's comments
to patch 8 [2]
[1] https://lore.kernel.org/all/20261113-regmap-improve-v2-0-5dfd6a89078f@xxxxxxx/
[2] https://lore.kernel.org/all/179510759875.116416.1025341724543668395.b4-review@b4/
This series removes the per-device regmap_bus copies used by the I2C and
SPI helpers to override max_raw_read and max_raw_write, converts the
__regmap_init() error unwinding to the scope-based cleanup API, and adds
KUnit coverage for the new init_limits callback.
The first patch replaces regmap_bus::free_on_exit with an optional
init_limits() callback. It is invoked after the bus raw I/O limits have
been copied and before the cache is initialized. The ordering matters
for maps with raw register defaults: regcache_hw_init() reads them back
from the device during initialization and chunks that transfer using
max_raw_read. Following review feedback, the callback takes the bus
context, the config and pointers to the limits instead of struct regmap,
which is private to drivers/base/regmap, so bus implementations outside
the regmap core can use it.
The second patch converts the __regmap_init() error unwinding to the
cleanup API. A dedicated release helper unwinds a partially initialized
map in the same order as the old labels. map->cache_type is now assigned
just before regcache_init() and reset if it fails, which makes
regcache_exit() safe to call from the cleanup path at any point.
The third patch adds a KUnit test that lowers the raw I/O limits from the
init_limits callback and relies on raw register defaults. The test
verifies that the cache readback is split according to the limits and
that the callback runs before regcache_init().
No functional changes.
Signed-off-by: Peng Fan <peng.fan@xxxxxxx>
---
Peng Fan (3):
regmap: drop regmap_bus::free_on_exit
regmap: use cleanup API in __regmap_init()
regmap: kunit: add test for regmap_bus::init_limits
drivers/base/regmap/regmap-i2c.c | 85 ++++++++++++++++++-----------------
drivers/base/regmap/regmap-kunit.c | 91 ++++++++++++++++++++++++++++++++++++++
drivers/base/regmap/regmap-spi.c | 66 +++++++++++----------------
drivers/base/regmap/regmap.c | 77 ++++++++++++++++----------------
include/linux/regmap.h | 10 ++++-
5 files changed, 207 insertions(+), 122 deletions(-)
---
base-commit: 909ef7a9a30fa139e69e555e3606680f5cca7726
change-id: 20261121-regmap-improve-2nd-376762e4d823
Best regards,
--
Peng Fan <peng.fan@xxxxxxx>