From: Meng Li <meng...@windriver.com>

When kernel boots up, there is call trace as below:
BUG: sleeping function called from invalid context at mm/slab.h:513
in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 1, name: swapper/0
......
CPU: 3 PID: 1 Comm: swapper/0 Not tainted 5.10.69-yocto-standard #1
Hardware name: LS1043A RDB Board (DT)
Call trace:
 dump_backtrace+0x0/0x1b0
 show_stack+0x24/0x30
 dump_stack+0xf0/0x13c
 ___might_sleep+0x1a0/0x24c
 __might_sleep+0x60/0xa0
 kmem_cache_alloc_trace+0x2cc/0x3b0
 dpa_alloc_new+0x1b0/0x290
 ......
 fm_port_load+0x1c/0x50
 do_one_initcall+0xbc/0x470
 kernel_init_freeable+0x30c/0x378
 kernel_init+0x20/0x128
 ret_from_fork+0x10/0x38

The call trace is caused by allocating used_node with GFP_KERNEL
parameter in atomic environment. It is not necessary to do the allocation
in atomic environment, so move it out the lock/unlock section.

Signed-off-by: Meng Li <meng...@windriver.com>
---
 drivers/staging/fsl_qbman/dpa_alloc.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/fsl_qbman/dpa_alloc.c 
b/drivers/staging/fsl_qbman/dpa_alloc.c
index 44db3e1ed5c2..a98779bf26da 100644
--- a/drivers/staging/fsl_qbman/dpa_alloc.c
+++ b/drivers/staging/fsl_qbman/dpa_alloc.c
@@ -455,6 +455,13 @@ int dpa_alloc_new(struct dpa_alloc *alloc, u32 *result, 
u32 count, u32 align,
                kfree(margin_left);
                goto err;
        }
+       /* Add the allocation to the used list */
+       used_node = kmalloc(sizeof(*used_node), GFP_KERNEL);
+       if (!used_node) {
+               kfree(margin_right);
+               kfree(margin_left);
+               goto err;
+       }
        spin_lock_irq(&alloc->lock);
        list_for_each_entry(i, &alloc->free, list) {
                base = (i->base + align - 1) / align;
@@ -502,6 +509,7 @@ int dpa_alloc_new(struct dpa_alloc *alloc, u32 *result, u32 
count, u32 align,
                spin_unlock_irq(&alloc->lock);
                kfree(margin_left);
                kfree(margin_right);
+               kfree(used_node);
        }
 
 err:
@@ -510,12 +518,7 @@ int dpa_alloc_new(struct dpa_alloc *alloc, u32 *result, 
u32 count, u32 align,
        if (!i)
                return -ENOMEM;
 
-       /* Add the allocation to the used list with a refcount of 1 */
-       used_node = kmalloc(sizeof(*used_node), GFP_KERNEL);
-       if (!used_node) {
-               spin_unlock_irq(&alloc->lock);
-               return -ENOMEM;
-       }
+       /* Set the used list with a refcount of 1 */
        used_node->base = *result;
        used_node->num = num;
        used_node->refcount = 1;
-- 
2.17.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#10504): 
https://lists.yoctoproject.org/g/linux-yocto/message/10504
Mute This Topic: https://lists.yoctoproject.org/mt/85967380/21656
Group Owner: linux-yocto+ow...@lists.yoctoproject.org
Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub 
[arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to