linux/drivers/base/regmap
Richard Fitzgerald 7ba822189e
regmap: kunit: Fix array overflow in stride() test
Force the max_register of the test regmap to be one register longer
than the number of test registers, to prevent an array overflow in
the test loop.

The test defines num_reg_defaults = 6. With 6 registers and
stride == 2 the valid register addresses would be 0, 2, 4, 6, 8, 10.
However the loop checks attempting to access the odd address, so on
the final register it accesses address 11, and it writes entry [11]
of the read/written arrays.

Originally this worked because the max_register of the regmap was
hardcoded to be BLOCK_TEST_SIZE (== 12).

commit 710915743d ("regmap: kunit: Run sparse cache tests at non-zero
register addresses")
introduced the ability to start the test address range from any address,
which means adjusting the max_register. If max_register was not forced,
it was calculated either from num_reg_defaults or BLOCK_TEST_SIZE. This
correctly calculated that with num_reg_defaults == 6 and stride == 2 the
final valid address is 10. So the read/written arrays are allocated to
contain entries [0..10]. When stride attempted to access [11] it was
overflowing the array.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Fixes: 710915743d ("regmap: kunit: Run sparse cache tests at non-zero register addresses")
Tested-by: Guenter Roeck <linux@roeck-us.net>
Link: https://msgid.link/r/20240517144703.1200995-1-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2024-05-17 18:23:12 +01:00
..
internal.h regmap: kunit: Create a struct device for the regmap 2024-04-08 16:38:07 +01:00
Kconfig regmap: Provide user selectable option to enable regmap 2023-07-13 16:20:28 +01:00
Makefile regmap: Provide a ram backed regmap with raw support 2023-06-12 14:47:54 +01:00
regcache-flat.c regmap: rework ->max_register handling 2024-02-05 14:32:35 +00:00
regcache-maple.c regmap: kunit: Add some test cases and a few small 2024-04-09 23:27:14 +01:00
regcache-rbtree.c regmap: rbtree: Fix wrong register marked as in-cache when creating new node 2023-09-22 16:54:00 +01:00
regcache.c regmap: rework ->max_register handling 2024-02-05 14:32:35 +00:00
regmap-ac97.c regmap: add proper SPDX identifiers on files that did not have them. 2019-04-25 20:22:15 +01:00
regmap-debugfs.c mm, treewide: rename MAX_ORDER to MAX_PAGE_ORDER 2024-01-08 15:27:15 -08:00
regmap-fsi.c regmap: Add FSI bus support 2022-11-25 19:17:02 +00:00
regmap-i2c.c regmap: Account for register length in SMBus I/O limits 2023-07-17 06:15:15 +01:00
regmap-i3c.c regmap: Drop capitalisation in MODULE_DESCRIPTION() 2024-04-10 22:45:52 +01:00
regmap-irq.c regmap-irq: Fix out-of-bounds access when allocating config buffers 2023-07-12 12:05:10 +01:00
regmap-kunit.c regmap: kunit: Fix array overflow in stride() test 2024-05-17 18:23:12 +01:00
regmap-mdio.c regmap: Drop capitalisation in MODULE_DESCRIPTION() 2024-04-10 22:45:52 +01:00
regmap-mmio.c regmap: mmio: Remove unused 64-bit support code 2023-07-09 22:48:46 +01:00
regmap-ram.c regmap: kunit: Create a struct device for the regmap 2024-04-08 16:38:07 +01:00
regmap-raw-ram.c regmap: kunit: Create a struct device for the regmap 2024-04-08 16:38:07 +01:00
regmap-sccb.c regmap: Constify static regmap_bus structs 2022-04-04 08:41:50 +01:00
regmap-sdw-mbq.c regmap: Drop capitalisation in MODULE_DESCRIPTION() 2024-04-10 22:45:52 +01:00
regmap-sdw.c regmap: Drop capitalisation in MODULE_DESCRIPTION() 2024-04-10 22:45:52 +01:00
regmap-slimbus.c regmap: Constify static regmap_bus structs 2022-04-04 08:41:50 +01:00
regmap-spi-avmm.c regmap: Drop initial version of maximum transfer length fixes 2023-07-17 06:15:14 +01:00
regmap-spi.c regmap: spi: Add missing MODULE_DESCRIPTION() 2024-04-10 22:45:53 +01:00
regmap-spmi.c regmap: add proper SPDX identifiers on files that did not have them. 2019-04-25 20:22:15 +01:00
regmap-w1.c regmap: Constify static regmap_bus structs 2022-04-04 08:41:50 +01:00
regmap.c regmap: Add regmap_read_bypassed() 2024-04-08 14:09:58 +01:00
trace.h regmap: trace: Remove unneeded blank lines 2022-09-05 13:09:45 +01:00