Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/audio/codec/dts/dts.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static void *dts_effect_allocate_codec_memory(void *mod_void, unsigned int lengt

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit doesn't say why these are renamed. Just to make them shorter?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, simply to make the names shorter and not to trigger line wrapping storm all around the place when all modules are changed to use module API for memory allocations.

comp_dbg(dev, "dts_effect_allocate_codec_memory() start");

pMem = module_allocate_memory(mod, (uint32_t)length, (uint32_t)alignment);
pMem = mod_alloc(mod, (uint32_t)length, (uint32_t)alignment);
Comment thread
lgirdwood marked this conversation as resolved.
Outdated

if (pMem == NULL)
comp_err(dev,
Expand All @@ -42,10 +42,10 @@ static void dts_effect_free_codec_memory(void *mod_void, void *pMem)

comp_dbg(dev, "dts_effect_free_codec_memory() start");

int ret = module_free_memory(mod, pMem);
int ret = mod_free(mod, pMem);

if (ret)
comp_err(dev, "dts_effect_free_codec_memory() module_free_memory failed %d", ret);
comp_err(dev, "dts_effect_free_codec_memory() mod_free failed %d", ret);

comp_dbg(dev, "dts_effect_free_codec_memory() done");
}
Expand Down
14 changes: 7 additions & 7 deletions src/audio/module_adapter/module/cadence.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ static int init_memory_tables(struct processing_module *mod)
goto err;
}
/* Allocate memory for this type, taking alignment into account */
ptr = module_allocate_memory(mod, mem_size, mem_alignment);
ptr = mod_alloc(mod, mem_size, mem_alignment);
if (!ptr) {
comp_err(dev, "init_memory_tables() error %x: failed to allocate memory for %d",
ret, mem_type);
Expand Down Expand Up @@ -563,13 +563,13 @@ static int init_memory_tables(struct processing_module *mod)
return 0;
err:
if (scratch)
module_free_memory(mod, scratch);
mod_free(mod, scratch);
if (persistent)
module_free_memory(mod, persistent);
mod_free(mod, persistent);
if (codec->mpd.in_buff)
module_free_memory(mod, codec->mpd.in_buff);
mod_free(mod, codec->mpd.in_buff);
if (codec->mpd.out_buff)
module_free_memory(mod, codec->mpd.out_buff);
mod_free(mod, codec->mpd.out_buff);
return ret;
}

Expand Down Expand Up @@ -688,7 +688,7 @@ static int cadence_codec_prepare(struct processing_module *mod,
return ret;
}

cd->mem_tabs = module_allocate_memory(mod, mem_tabs_size, 4);
cd->mem_tabs = mod_alloc(mod, mem_tabs_size, 4);
if (!cd->mem_tabs) {
comp_err(dev, "cadence_codec_prepare() error: failed to allocate space for memtabs");
return -ENOMEM;
Expand Down Expand Up @@ -732,7 +732,7 @@ static int cadence_codec_prepare(struct processing_module *mod,
comp_dbg(dev, "cadence_codec_prepare() done");
return 0;
free:
module_free_memory(mod, cd->mem_tabs);
mod_free(mod, cd->mem_tabs);
return ret;
}

Expand Down
14 changes: 8 additions & 6 deletions src/audio/module_adapter/module/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,22 @@ int module_init(struct processing_module *mod)
return 0;
}

void *module_allocate_memory(struct processing_module *mod, uint32_t size, uint32_t alignment)
void *mod_alloc(struct processing_module *mod, uint32_t size, uint32_t alignment)
{
struct comp_dev *dev = mod->dev;
struct module_memory *container;
void *ptr;

if (!size) {
comp_err(dev, "module_allocate_memory: requested allocation of 0 bytes.");
comp_err(dev, "mod_alloc: requested allocation of 0 bytes.");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to include the function name in the error message? Zephyr automatically prefixes log entries with the function name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but I do not want to mess with this commit that is strictly replace-string operation on the source tree. Maybe I should go through all our modules in another commit, in the next PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, now that we are Zephyr only, we should use LOG(), but this can be another PR.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lgirdwood didn't we already conclude that no, we want to keep audio specific macros for audio codes that add audio topology information (component and pipe ids) to the log messages. For generic code outside modules, using plain Zephyr LOG is then ok (when not in module context).

return NULL;
}

/* Allocate memory container */
container = rzalloc(SOF_MEM_FLAG_USER,
sizeof(struct module_memory));
if (!container) {
comp_err(dev, "module_allocate_memory: failed to allocate memory container.");
comp_err(dev, "mod_alloc: failed to allocate memory container.");
return NULL;
}

Expand All @@ -136,7 +136,7 @@ void *module_allocate_memory(struct processing_module *mod, uint32_t size, uint3
ptr = rballoc(SOF_MEM_FLAG_USER, size);

if (!ptr) {
comp_err(dev, "module_allocate_memory: failed to allocate memory for comp %x.",
comp_err(dev, "mod_alloc: failed to allocate memory for comp %x.",
dev_comp_id(dev));
Comment thread
jsarha marked this conversation as resolved.
return NULL;
}
Expand All @@ -146,8 +146,9 @@ void *module_allocate_memory(struct processing_module *mod, uint32_t size, uint3

return ptr;
}
EXPORT_SYMBOL(mod_alloc);

int module_free_memory(struct processing_module *mod, void *ptr)
int mod_free(struct processing_module *mod, void *ptr)
{
struct module_memory *mem;
struct list_item *mem_list;
Expand All @@ -167,11 +168,12 @@ int module_free_memory(struct processing_module *mod, void *ptr)
}
}

comp_err(mod->dev, "module_free_memory: error: could not find memory pointed by %p",
comp_err(mod->dev, "mod_free: error: could not find memory pointed by %p",
ptr);

return -EINVAL;
}
EXPORT_SYMBOL(mod_free);

int module_prepare(struct processing_module *mod,
struct sof_source **sources, int num_of_sources,
Expand Down
26 changes: 13 additions & 13 deletions src/audio/module_adapter/module/waves/waves.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ static int waves_effect_allocate(struct processing_module *mod)
return -EINVAL;
}

waves_codec->effect = (MaxxEffect_t *)module_allocate_memory(mod,
waves_codec->effect = (MaxxEffect_t *)mod_alloc(mod,
waves_codec->effect_size, 16);

if (!waves_codec->effect) {
Expand Down Expand Up @@ -376,15 +376,15 @@ static int waves_effect_buffers(struct processing_module *mod)

comp_dbg(dev, "waves_effect_buffers() start");

i_buffer = module_allocate_memory(mod, waves_codec->buffer_bytes, 16);
i_buffer = mod_alloc(mod, waves_codec->buffer_bytes, 16);
if (!i_buffer) {
comp_err(dev, "waves_effect_buffers() failed to allocate %d bytes for i_buffer",
waves_codec->buffer_bytes);
ret = -ENOMEM;
goto err;
}

o_buffer = module_allocate_memory(mod, waves_codec->buffer_bytes, 16);
o_buffer = mod_alloc(mod, waves_codec->buffer_bytes, 16);
if (!o_buffer) {
comp_err(dev, "waves_effect_buffers() failed to allocate %d bytes for o_buffer",
waves_codec->buffer_bytes);
Expand All @@ -407,9 +407,9 @@ static int waves_effect_buffers(struct processing_module *mod)

err:
if (i_buffer)
module_free_memory(mod, i_buffer);
mod_free(mod, i_buffer);
if (o_buffer)
module_free_memory(mod, o_buffer);
mod_free(mod, o_buffer);
return ret;
}

Expand Down Expand Up @@ -475,13 +475,13 @@ static int waves_effect_save_config_blob_to_cache(struct processing_module *mod,
/* release old cached config blob*/
if (waves_codec->config_blob && size != waves_codec->config_blob_size) {
comp_info(dev, "waves_effect_save_config_blob_to_cache() release blob");
module_free_memory(mod, waves_codec->config_blob);
mod_free(mod, waves_codec->config_blob);
waves_codec->config_blob = NULL;
waves_codec->config_blob_size = 0;
}

if (!waves_codec->config_blob) {
waves_codec->config_blob = module_allocate_memory(mod, size, 16);
waves_codec->config_blob = mod_alloc(mod, size, 16);
if (!waves_codec->config_blob) {
comp_err(dev,
"waves_effect_save_config_blob_to_cache() failed to allocate %d bytes for config blob",
Expand All @@ -497,7 +497,7 @@ static int waves_effect_save_config_blob_to_cache(struct processing_module *mod,
comp_err(dev,
"waves_effect_save_config_blob_to_cache(): failed to copy config blob %d",
ret);
module_free_memory(mod, waves_codec->config_blob);
mod_free(mod, waves_codec->config_blob);
waves_codec->config_blob = NULL;
waves_codec->config_blob_size = 0;
return ret;
Expand Down Expand Up @@ -668,7 +668,7 @@ static int waves_codec_init(struct processing_module *mod)

comp_dbg(dev, "waves_codec_init() start");

waves_codec = module_allocate_memory(mod, sizeof(struct waves_codec_data), 16);
waves_codec = mod_alloc(mod, sizeof(struct waves_codec_data), 16);
if (!waves_codec) {
comp_err(dev, "waves_codec_init() failed to allocate %d bytes for waves_codec_data",
sizeof(struct waves_codec_data));
Expand All @@ -678,7 +678,7 @@ static int waves_codec_init(struct processing_module *mod)
codec->private = waves_codec;
ret = waves_effect_allocate(mod);
if (ret) {
module_free_memory(mod, waves_codec);
mod_free(mod, waves_codec);
codec->private = NULL;
}
}
Expand All @@ -696,7 +696,7 @@ static int waves_codec_init(struct processing_module *mod)
return -EINVAL;
}

response = module_allocate_memory(mod, waves_codec->response_max_bytes, 16);
response = mod_alloc(mod, waves_codec->response_max_bytes, 16);
if (!response) {
comp_err(dev, "waves_codec_init() failed to allocate %d bytes for response",
waves_codec->response_max_bytes);
Expand Down Expand Up @@ -850,10 +850,10 @@ static int waves_codec_reset(struct processing_module *mod)
comp_err(dev, "waves_codec_reset() failed %d", ret);

if (codec->mpd.in_buff)
module_free_memory(mod, codec->mpd.in_buff);
mod_free(mod, codec->mpd.in_buff);

if (codec->mpd.out_buff)
module_free_memory(mod, codec->mpd.out_buff);
mod_free(mod, codec->mpd.out_buff);

waves_codec->initialized = false;
comp_dbg(dev, "waves_codec_reset() done");
Expand Down
4 changes: 2 additions & 2 deletions src/include/sof/audio/module_adapter/module/generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ struct module_processing_data {
/*****************************************************************************/
int module_load_config(struct comp_dev *dev, const void *cfg, size_t size);
int module_init(struct processing_module *mod);
void *module_allocate_memory(struct processing_module *mod, uint32_t size, uint32_t alignment);
int module_free_memory(struct processing_module *mod, void *ptr);
void *mod_alloc(struct processing_module *mod, uint32_t size, uint32_t alignment);
int mod_free(struct processing_module *mod, void *ptr);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure we don't have out-of-tree modules that use current generic.h naming? Should we add compatibility macros for the old names?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of tree need to adapt.

void module_free_all_memory(struct processing_module *mod);
int module_prepare(struct processing_module *mod,
struct sof_source **sources, int num_of_sources,
Expand Down