Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

call k_malloc or k_mem_slab_alloc allowed or not #28020

Closed
lanvis opened this issue Sep 3, 2020 · 3 comments · Fixed by #28445
Closed

call k_malloc or k_mem_slab_alloc allowed or not #28020

lanvis opened this issue Sep 3, 2020 · 3 comments · Fixed by #28445
Assignees
Labels
area: Documentation area: Kernel bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug

Comments

@lanvis
Copy link

lanvis commented Sep 3, 2020

We are calling k_malloc() and k_mem_slab_alloc() from our timer and uart ISRs and were not experiencing any issues that we knew of. We noticed that the documentation does not say it can't be called from an ISR but it doesn't say we can either (like other kernel APIs do).

Can they be called from an ISR?

Thanks

@andrewboie
Copy link
Contributor

These APIs use spinlocks for syncrhonization and should be ISR safe, but the timeout value must be K_NO_WAIT for k_mem_slab_alloc() as you can't sleep in an ISR.

don't use libc malloc() though ;)

@andrewboie andrewboie added area: Documentation bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug labels Sep 4, 2020
@andrewboie
Copy link
Contributor

converting this to a minor documentation issue

@andrewboie andrewboie assigned andrewboie and unassigned andyross Sep 5, 2020
@nashif nashif assigned laurenmurphyx64 and unassigned andrewboie Sep 9, 2020
@rljordan rljordan assigned aasthagr and yerabolu and unassigned laurenmurphyx64 and aasthagr Sep 9, 2020
@nashif nashif removed the question label Sep 11, 2020
@andyross
Copy link
Contributor

Note that k_mem_pool_alloc() (soon to be deprecated) and k_heap_alloc() both have the same documentation bug. They're safe to call in an interrupt as long as the timeout is K_NO_WAIT

yerabolu added a commit to yerabolu/zephyr that referenced this issue Sep 16, 2020
Added a note in documentation for k_mem_slab_alloc(),
k_mem_pool_alloc() and k_heap_alloc() are safe
to call in an interrupt with the timeout K_NO_WAIT.

Fixes: zephyrproject-rtos#28020

Signed-off-by: Spoorthy Priya Yerabolu <spoorthy.priya.yerabolu@intel.com>
carlescufi pushed a commit that referenced this issue Sep 17, 2020
Added a note in documentation for k_mem_slab_alloc(),
k_mem_pool_alloc() and k_heap_alloc() are safe
to call in an interrupt with the timeout K_NO_WAIT.

Fixes: #28020

Signed-off-by: Spoorthy Priya Yerabolu <spoorthy.priya.yerabolu@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Documentation area: Kernel bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants