Skip to content

Commit 1d170fc

Browse files
lyakhlgirdwood
authored andcommitted
module: add an allocation function with flags
Add a new mod_alloc_ext() allocation function with support for allocator flags. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent 0910951 commit 1d170fc

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/audio/module_adapter/module/generic.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,16 @@ void *mod_balloc_align(struct processing_module *mod, size_t size, size_t alignm
218218
EXPORT_SYMBOL(mod_balloc_align);
219219

220220
/**
221-
* Allocates aligned memory block for module.
221+
* Allocates aligned memory block with flags for module.
222222
* @param mod Pointer to the module this memory block is allocatd for.
223+
* @param flags Allocator flags.
223224
* @param bytes Size in bytes.
224225
* @param alignment Alignment in bytes.
225226
* @return Pointer to the allocated memory or NULL if failed.
226227
*
227228
* The allocated memory is automatically freed when the module is unloaded.
228229
*/
229-
void *mod_alloc_align(struct processing_module *mod, size_t size, size_t alignment)
230+
void *mod_alloc_ext(struct processing_module *mod, uint32_t flags, size_t size, size_t alignment)
230231
{
231232
struct module_resources *res = &mod->priv.resources;
232233
struct module_resource *container;
@@ -245,7 +246,7 @@ void *mod_alloc_align(struct processing_module *mod, size_t size, size_t alignme
245246
}
246247

247248
/* Allocate memory for module */
248-
ptr = rmalloc_align(SOF_MEM_FLAG_USER, size, alignment);
249+
ptr = rmalloc_align(flags, size, alignment);
249250

250251
if (!ptr) {
251252
comp_err(mod->dev, "Failed to alloc %zu bytes %zu alignment for comp %#x.",
@@ -265,7 +266,7 @@ void *mod_alloc_align(struct processing_module *mod, size_t size, size_t alignme
265266

266267
return ptr;
267268
}
268-
EXPORT_SYMBOL(mod_alloc_align);
269+
EXPORT_SYMBOL(mod_alloc_ext);
269270

270271
/**
271272
* Creates a blob handler and releases it when the module is unloaded

src/include/sof/audio/module_adapter/module/generic.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,27 @@ struct module_processing_data {
189189
int module_load_config(struct comp_dev *dev, const void *cfg, size_t size);
190190
int module_init(struct processing_module *mod);
191191
void *mod_balloc_align(struct processing_module *mod, size_t size, size_t alignment);
192+
void *mod_alloc_ext(struct processing_module *mod, uint32_t flags, size_t size, size_t alignment);
193+
194+
/**
195+
* Allocates aligned memory block for module.
196+
* @param mod Pointer to the module this memory block is allocated for.
197+
* @param bytes Size in bytes.
198+
* @param alignment Alignment in bytes.
199+
* @return Pointer to the allocated memory or NULL if failed.
200+
*
201+
* The allocated memory is automatically freed when the module is unloaded.
202+
*/
203+
static inline void *mod_alloc_align(struct processing_module *mod, size_t size, size_t alignment)
204+
{
205+
return mod_alloc_ext(mod, 0, size, alignment);
206+
}
207+
192208
static inline void *mod_balloc(struct processing_module *mod, size_t size)
193209
{
194210
return mod_balloc_align(mod, size, 0);
195211
}
196212

197-
void *mod_alloc_align(struct processing_module *mod, size_t size, size_t alignment);
198213
static inline void *mod_alloc(struct processing_module *mod, size_t size)
199214
{
200215
return mod_alloc_align(mod, size, 0);

test/cmocka/src/common_mocks.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,12 @@ void WEAK *mod_balloc_align(struct processing_module *mod, size_t size, size_t a
102102
return ret;
103103
}
104104

105-
void WEAK *mod_alloc_align(struct processing_module *mod, size_t size, size_t alignment)
105+
void WEAK *mod_alloc_ext(struct processing_module *mod, uint32_t flags, size_t size,
106+
size_t alignment)
106107
{
107108
void *ret;
108109
(void)mod;
110+
(void)flags;
109111
(void)alignment;
110112

111113
ret = malloc(size);

0 commit comments

Comments
 (0)