Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regcache: flat: Require max_registers to be set

If max_register is unset, regcache_flat_get_index will return 0 and only
memory for 1 unsigned int will be allocated, resulting in writing out
of bounds.

Signed-off-by: Alexander Stein <alexander.stein@systec-electronic.com>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Alexander Stein and committed by
Mark Brown
6e4f2878 f55532a0

+1 -1
+1 -1
drivers/base/regmap/regcache-flat.c
··· 27 27 int i; 28 28 unsigned int *cache; 29 29 30 - if (!map || map->reg_stride_order < 0) 30 + if (!map || map->reg_stride_order < 0 || !map->max_register) 31 31 return -EINVAL; 32 32 33 33 map->cache = kcalloc(regcache_flat_get_index(map, map->max_register)