]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
regcache: Sort the local copy of an unsorted reg_defaults array
authorPeter Ujfalusi <peter.ujfalusi@linux.intel.com>
Wed, 5 Aug 2026 13:22:50 +0000 (16:22 +0300)
committerMark Brown <broonie@kernel.org>
Thu, 6 Aug 2026 12:01:39 +0000 (13:01 +0100)
commit4b05ccb17f92268384d483221a577fccfc291c7a
tree6266d7433d2dc83393b5d6afcede9e2bf3dcb414
parent9ed3d974a26644ad57b3d4d067e279188b2038b6
regcache: Sort the local copy of an unsorted reg_defaults array

regcache_lookup_reg() bsearch()es the reg_defaults array, which requires
it to be sorted by ascending register address.  Entries following a
descending step are never found, so regcache_reg_needs_sync() reports
that they need a sync and they are written to the device on every
regcache_sync() even when they were never touched.

Detect the misordering while reg_defaults is validated against the
register stride and sort the local copy.  The check needs no new loop
and sort() only runs for the affected drivers, which are also warned
about.

Note that sort() is not stable, so for arrays with duplicated register
addresses it remains unspecified which entry is found.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Tested-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Link: https://patch.msgid.link/20260805132250.2637-1-peter.ujfalusi@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/base/regmap/regcache.c