diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2013-11-10 12:22:01 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2013-11-10 12:22:01 -0600 |
commit | 9336004836dc64aa433b8ec963113604b26ee784 (patch) | |
tree | 7d3b6791754dd788712d95caebb24b05b2683134 /nuttx | |
parent | b66a867a372e917edeb400ddc4385413d784408b (diff) | |
download | px4-nuttx-9336004836dc64aa433b8ec963113604b26ee784.tar.gz px4-nuttx-9336004836dc64aa433b8ec963113604b26ee784.tar.bz2 px4-nuttx-9336004836dc64aa433b8ec963113604b26ee784.zip |
libc/audio/lib_buffer.c must must correct allocation for execution domain
Diffstat (limited to 'nuttx')
-rw-r--r-- | nuttx/libc/audio/lib_buffer.c | 19 | ||||
-rw-r--r-- | nuttx/libc/lib_internal.h | 39 |
2 files changed, 42 insertions, 16 deletions
diff --git a/nuttx/libc/audio/lib_buffer.c b/nuttx/libc/audio/lib_buffer.c index 0cd3bd9a0..036fb0e63 100644 --- a/nuttx/libc/audio/lib_buffer.c +++ b/nuttx/libc/audio/lib_buffer.c @@ -49,10 +49,11 @@ #include <errno.h> #include <debug.h> -#include <nuttx/kmalloc.h> #include <nuttx/audio/audio.h> #include <nuttx/usb/audio.h> +#include "lib_internal.h" + #if defined(CONFIG_AUDIO) /**************************************************************************** @@ -113,7 +114,7 @@ static void apb_semtake(FAR struct ap_buffer_s *apb) * ****************************************************************************/ -int apb_alloc(FAR struct audio_buf_desc_s * bufdesc) +int apb_alloc(FAR struct audio_buf_desc_s *bufdesc) { uint32_t bufsize; int ret; @@ -124,13 +125,15 @@ int apb_alloc(FAR struct audio_buf_desc_s * bufdesc) /* Perform a user mode allocation */ bufsize = sizeof(struct ap_buffer_s) + bufdesc->numbytes; - pBuf = kumalloc(bufsize); + pBuf = lib_umalloc(bufsize); *bufdesc->u.ppBuffer = pBuf; /* Test if the allocation was successful or not */ if (*bufdesc->u.ppBuffer == NULL) - ret = -ENOMEM; + { + ret = -ENOMEM; + } else { /* Populate the buffer contents */ @@ -158,7 +161,7 @@ int apb_alloc(FAR struct audio_buf_desc_s * bufdesc) ****************************************************************************/ void apb_prepare(FAR struct ap_buffer_s *apb, int8_t allocmode, uint8_t format, - uint8_t subformat, apb_samp_t maxsamples) + uint8_t subformat, apb_samp_t maxsamples) { /* Perform a reference count decrement and possibly release the memory */ } @@ -172,7 +175,7 @@ void apb_prepare(FAR struct ap_buffer_s *apb, int8_t allocmode, uint8_t format, void apb_free(FAR struct ap_buffer_s *apb) { - int refcount; + int refcount; /* Perform a reference count decrement and possibly release the memory */ @@ -180,10 +183,10 @@ void apb_free(FAR struct ap_buffer_s *apb) refcount = apb->crefs--; apb_semgive(apb); - if (refcount == 1) + if (refcount <= 1) { auddbg("Freeing %p\n", apb); - kufree(apb); + lib_ufree(apb); } } diff --git a/nuttx/libc/lib_internal.h b/nuttx/libc/lib_internal.h index a85e815ff..c2be50a32 100644 --- a/nuttx/libc/lib_internal.h +++ b/nuttx/libc/lib_internal.h @@ -82,16 +82,39 @@ #if defined(CONFIG_NUTTX_KERNEL) && defined(__KERNEL__) # include <nuttx/kmalloc.h> -# define lib_malloc(s) kmalloc(s) -# define lib_zalloc(s) kzalloc(s) -# define lib_realloc(p,s) krealloc(p,s) -# define lib_free(p) kfree(p) + + /* Domain-specific allocations */ + +# define lib_malloc(s) kmalloc(s) +# define lib_zalloc(s) kzalloc(s) +# define lib_realloc(p,s) krealloc(p,s) +# define lib_memalign(p,s) krealloc(p,s) +# define lib_free(p) kfree(p) + + /* User-accesssible allocations */ + +# define lib_umalloc(s) kumalloc(s) +# define lib_uzalloc(s) kuzalloc(s) +# define lib_urealloc(p,s) kurealloc(p,s) +# define lib_ufree(p) kufree(p) + #else # include <stdlib.h> -# define lib_malloc(s) malloc(s) -# define lib_zalloc(s) zalloc(s) -# define lib_realloc(p,s) realloc(p,s) -# define lib_free(p) free(p) + + /* Domain-specific allocations */ + +# define lib_malloc(s) malloc(s) +# define lib_zalloc(s) zalloc(s) +# define lib_realloc(p,s) realloc(p,s) +# define lib_free(p) free(p) + + /* User-accesssible allocations */ + +# define lib_umalloc(s) malloc(s) +# define lib_uzalloc(s) zalloc(s) +# define lib_urealloc(p,s) realloc(p,s) +# define lib_ufree(p) free(p) + #endif #define LIB_BUFLEN_UNKNOWN INT_MAX |