diff --git a/libc/audio/lib_buffer.c b/libc/audio/lib_buffer.c index 0cd3bd9a0a..036fb0e63a 100644 --- a/libc/audio/lib_buffer.c +++ b/libc/audio/lib_buffer.c @@ -49,10 +49,11 @@ #include #include -#include #include #include +#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/libc/lib_internal.h b/libc/lib_internal.h index a85e815ff9..c2be50a32f 100644 --- a/libc/lib_internal.h +++ b/libc/lib_internal.h @@ -82,16 +82,39 @@ #if defined(CONFIG_NUTTX_KERNEL) && defined(__KERNEL__) # include -# 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 -# 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