Skip to content

Commit 0c8b0bf

Browse files
Dan Carpenterbroonie
authored andcommitted
regmap: rbtree: Use alloc_flags for memory allocations
The kunit tests discovered a sleeping in atomic bug. The allocations in the regcache-rbtree code should use the map->alloc_flags instead of GFP_KERNEL. [ 5.005510] BUG: sleeping function called from invalid context at include/linux/sched/mm.h:306 [ 5.005960] in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 117, name: kunit_try_catch [ 5.006219] preempt_count: 1, expected: 0 [ 5.006414] 1 lock held by kunit_try_catch/117: [ 5.006590] #0: 833b9010 (regmap_kunit:86:(config)->lock){....}-{2:2}, at: regmap_lock_spinlock+0x14/0x1c [ 5.007493] irq event stamp: 162 [ 5.007627] hardirqs last enabled at (161): [<80786738>] crng_make_state+0x1a0/0x294 [ 5.007871] hardirqs last disabled at (162): [<80c531ec>] _raw_spin_lock_irqsave+0x7c/0x80 [ 5.008119] softirqs last enabled at (0): [<801110ac>] copy_process+0x810/0x2138 [ 5.008356] softirqs last disabled at (0): [<00000000>] 0x0 [ 5.008688] CPU: 0 PID: 117 Comm: kunit_try_catch Tainted: G N 6.4.4-rc3-g0e8d2fdfb188 #1 [ 5.009011] Hardware name: Generic DT based system [ 5.009277] unwind_backtrace from show_stack+0x18/0x1c [ 5.009497] show_stack from dump_stack_lvl+0x38/0x5c [ 5.009676] dump_stack_lvl from __might_resched+0x188/0x2d0 [ 5.009860] __might_resched from __kmem_cache_alloc_node+0x1dc/0x25c [ 5.010061] __kmem_cache_alloc_node from kmalloc_trace+0x30/0xc8 [ 5.010254] kmalloc_trace from regcache_rbtree_write+0x26c/0x468 [ 5.010446] regcache_rbtree_write from _regmap_write+0x88/0x140 [ 5.010634] _regmap_write from regmap_write+0x44/0x68 [ 5.010803] regmap_write from basic_read_write+0x8c/0x270 [ 5.010980] basic_read_write from kunit_try_run_case+0x48/0xa0 Fixes: 28644c8 ("regmap: Add the rbtree cache support") Reported-by: Guenter Roeck <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Dan Carpenter <[email protected]> Tested-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent b0393e1 commit 0c8b0bf

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

drivers/base/regmap/regcache-rbtree.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ static int regcache_rbtree_insert_to_block(struct regmap *map,
277277

278278
blk = krealloc(rbnode->block,
279279
blklen * map->cache_word_size,
280-
GFP_KERNEL);
280+
map->alloc_flags);
281281
if (!blk)
282282
return -ENOMEM;
283283

@@ -286,7 +286,7 @@ static int regcache_rbtree_insert_to_block(struct regmap *map,
286286
if (BITS_TO_LONGS(blklen) > BITS_TO_LONGS(rbnode->blklen)) {
287287
present = krealloc(rbnode->cache_present,
288288
BITS_TO_LONGS(blklen) * sizeof(*present),
289-
GFP_KERNEL);
289+
map->alloc_flags);
290290
if (!present)
291291
return -ENOMEM;
292292

@@ -320,7 +320,7 @@ regcache_rbtree_node_alloc(struct regmap *map, unsigned int reg)
320320
const struct regmap_range *range;
321321
int i;
322322

323-
rbnode = kzalloc(sizeof(*rbnode), GFP_KERNEL);
323+
rbnode = kzalloc(sizeof(*rbnode), map->alloc_flags);
324324
if (!rbnode)
325325
return NULL;
326326

@@ -346,13 +346,13 @@ regcache_rbtree_node_alloc(struct regmap *map, unsigned int reg)
346346
}
347347

348348
rbnode->block = kmalloc_array(rbnode->blklen, map->cache_word_size,
349-
GFP_KERNEL);
349+
map->alloc_flags);
350350
if (!rbnode->block)
351351
goto err_free;
352352

353353
rbnode->cache_present = kcalloc(BITS_TO_LONGS(rbnode->blklen),
354354
sizeof(*rbnode->cache_present),
355-
GFP_KERNEL);
355+
map->alloc_flags);
356356
if (!rbnode->cache_present)
357357
goto err_free_block;
358358

0 commit comments

Comments
 (0)