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

regcache: use map->alloc_flags also for allocating cache

Commit fd4ebc07b4df ("regmap: Hold the regmap lock when allocating and
freeing the cache") introduced a locking around the allocating and
freeing a regmap cache, so adjust the memory allocation flags to the ones
given in the regmap configuration instead of the hardcoded GFP_KERNEL.

This fixes the "BUG: sleeping function called from invalid context"
introduced by the mentioned commit.

Fixes: fd4ebc07b4df ("regmap: Hold the regmap lock when allocating and freeing the cache")
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Link: https://patch.msgid.link/20240828122834.3778031-1-m.szyprowski@samsung.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Marek Szyprowski and committed by
Mark Brown
ae0acef3 290d6e5d

+3 -3
+1 -1
drivers/base/regmap/regcache-flat.c
··· 27 27 return -EINVAL; 28 28 29 29 map->cache = kcalloc(regcache_flat_get_index(map, map->max_register) 30 - + 1, sizeof(unsigned int), GFP_KERNEL); 30 + + 1, sizeof(unsigned int), map->alloc_flags); 31 31 if (!map->cache) 32 32 return -ENOMEM; 33 33
+1 -1
drivers/base/regmap/regcache-maple.c
··· 348 348 int ret; 349 349 int range_start; 350 350 351 - mt = kmalloc(sizeof(*mt), GFP_KERNEL); 351 + mt = kmalloc(sizeof(*mt), map->alloc_flags); 352 352 if (!mt) 353 353 return -ENOMEM; 354 354 map->cache = mt;
+1 -1
drivers/base/regmap/regcache-rbtree.c
··· 187 187 int i; 188 188 int ret; 189 189 190 - map->cache = kmalloc(sizeof *rbtree_ctx, GFP_KERNEL); 190 + map->cache = kmalloc(sizeof *rbtree_ctx, map->alloc_flags); 191 191 if (!map->cache) 192 192 return -ENOMEM; 193 193