Skip to content

Commit b0393e1

Browse files
groeckbroonie
authored andcommitted
regmap: maple: Use alloc_flags for memory allocations
REGCACHE_MAPLE needs to allocate memory for regmap operations. This results in lockdep splats if used with fast_io since fast_io uses spinlocks for locking. BUG: sleeping function called from invalid context at include/linux/sched/mm.h:306 in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 167, name: kunit_try_catch preempt_count: 1, expected: 0 1 lock held by kunit_try_catch/167: #0: 838e9c10 (regmap_kunit:86:(config)->lock){....}-{2:2}, at: regmap_lock_spinlock+0x14/0x1c irq event stamp: 146 hardirqs last enabled at (145): [<8078bfa8>] crng_make_state+0x1a0/0x294 hardirqs last disabled at (146): [<80c5f62c>] _raw_spin_lock_irqsave+0x7c/0x80 softirqs last enabled at (0): [<80110cc4>] copy_process+0x810/0x216c softirqs last disabled at (0): [<00000000>] 0x0 CPU: 0 PID: 167 Comm: kunit_try_catch Tainted: G N 6.5.0-rc1-00028-gc4be22597a36-dirty #6 Hardware name: Generic DT based system unwind_backtrace from show_stack+0x18/0x1c show_stack from dump_stack_lvl+0x38/0x5c dump_stack_lvl from __might_resched+0x188/0x2d0 __might_resched from __kmem_cache_alloc_node+0x1f4/0x258 __kmem_cache_alloc_node from __kmalloc+0x48/0x170 __kmalloc from regcache_maple_write+0x194/0x248 regcache_maple_write from _regmap_write+0x88/0x140 _regmap_write from regmap_write+0x44/0x68 regmap_write from basic_read_write+0x8c/0x27c basic_read_write from kunit_generic_run_threadfn_adapter+0x1c/0x28 kunit_generic_run_threadfn_adapter from kthread+0xf8/0x120 kthread from ret_from_fork+0x14/0x3c Exception stack(0x881a5fb0 to 0x881a5ff8) 5fa0: 00000000 00000000 00000000 00000000 5fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 5fe0: 00000000 00000000 00000000 00000000 00000013 00000000 Use map->alloc_flags instead of GFP_KERNEL for memory allocations to fix the problem. Fixes: f033c26 ("regmap: Add maple tree based register cache") Cc: Dan Carpenter <[email protected]> Signed-off-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent ee43f5b commit b0393e1

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

drivers/base/regmap/regcache-maple.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static int regcache_maple_write(struct regmap *map, unsigned int reg,
7474
rcu_read_unlock();
7575

7676
entry = kmalloc((last - index + 1) * sizeof(unsigned long),
77-
GFP_KERNEL);
77+
map->alloc_flags);
7878
if (!entry)
7979
return -ENOMEM;
8080

@@ -92,7 +92,7 @@ static int regcache_maple_write(struct regmap *map, unsigned int reg,
9292
mas_lock(&mas);
9393

9494
mas_set_range(&mas, index, last);
95-
ret = mas_store_gfp(&mas, entry, GFP_KERNEL);
95+
ret = mas_store_gfp(&mas, entry, map->alloc_flags);
9696

9797
mas_unlock(&mas);
9898

@@ -134,7 +134,7 @@ static int regcache_maple_drop(struct regmap *map, unsigned int min,
134134

135135
lower = kmemdup(entry, ((min - mas.index) *
136136
sizeof(unsigned long)),
137-
GFP_KERNEL);
137+
map->alloc_flags);
138138
if (!lower) {
139139
ret = -ENOMEM;
140140
goto out_unlocked;
@@ -148,7 +148,7 @@ static int regcache_maple_drop(struct regmap *map, unsigned int min,
148148
upper = kmemdup(&entry[max + 1],
149149
((mas.last - max) *
150150
sizeof(unsigned long)),
151-
GFP_KERNEL);
151+
map->alloc_flags);
152152
if (!upper) {
153153
ret = -ENOMEM;
154154
goto out_unlocked;
@@ -162,15 +162,15 @@ static int regcache_maple_drop(struct regmap *map, unsigned int min,
162162
/* Insert new nodes with the saved data */
163163
if (lower) {
164164
mas_set_range(&mas, lower_index, lower_last);
165-
ret = mas_store_gfp(&mas, lower, GFP_KERNEL);
165+
ret = mas_store_gfp(&mas, lower, map->alloc_flags);
166166
if (ret != 0)
167167
goto out;
168168
lower = NULL;
169169
}
170170

171171
if (upper) {
172172
mas_set_range(&mas, upper_index, upper_last);
173-
ret = mas_store_gfp(&mas, upper, GFP_KERNEL);
173+
ret = mas_store_gfp(&mas, upper, map->alloc_flags);
174174
if (ret != 0)
175175
goto out;
176176
upper = NULL;
@@ -320,7 +320,7 @@ static int regcache_maple_insert_block(struct regmap *map, int first,
320320
unsigned long *entry;
321321
int i, ret;
322322

323-
entry = kcalloc(last - first + 1, sizeof(unsigned long), GFP_KERNEL);
323+
entry = kcalloc(last - first + 1, sizeof(unsigned long), map->alloc_flags);
324324
if (!entry)
325325
return -ENOMEM;
326326

@@ -331,7 +331,7 @@ static int regcache_maple_insert_block(struct regmap *map, int first,
331331

332332
mas_set_range(&mas, map->reg_defaults[first].reg,
333333
map->reg_defaults[last].reg);
334-
ret = mas_store_gfp(&mas, entry, GFP_KERNEL);
334+
ret = mas_store_gfp(&mas, entry, map->alloc_flags);
335335

336336
mas_unlock(&mas);
337337

0 commit comments

Comments
 (0)