Skip to content

Commit

Permalink
module_adapter: Make free and prepare methods optional
Browse files Browse the repository at this point in the history
Simple modules may not need to provide free and prepare functions.
To avoid having to provide dummy methods, added an if to check if a module
implemented these methods. This will prevent null reference if a module
doesn't implement these methods.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
  • Loading branch information
softwarecki committed Nov 29, 2023
1 parent 5c0f8bd commit 37935d3
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/audio/module_adapter/module/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ int module_init(struct processing_module *mod, const struct module_interface *in
return -EIO;
}

/*check interface, there must be one and only one of processing procedure */
if (!interface->init || !interface->prepare ||
!interface->reset || !interface->free ||
/* check interface, there must be one and only one of processing procedure */
if (!interface->init || !interface->reset ||
(!!interface->process + !!interface->process_audio_stream +
!!interface->process_raw_data != 1)) {
comp_err(dev, "module_init(): comp %d is missing mandatory interfaces",
Expand Down Expand Up @@ -211,11 +210,13 @@ int module_prepare(struct processing_module *mod,
if (mod->priv.state < MODULE_INITIALIZED)
return -EPERM;
#endif
ret = md->ops->prepare(mod, sources, num_of_sources, sinks, num_of_sinks);
if (ret) {
comp_err(dev, "module_prepare() error %d: module specific prepare failed, comp_id %d",
ret, dev_comp_id(dev));
return ret;
if (md->ops->prepare) {
ret = md->ops->prepare(mod, sources, num_of_sources, sinks, num_of_sinks);
if (ret) {
comp_err(dev, "module_prepare() error %d: module specific prepare failed, comp_id %d",
ret, dev_comp_id(dev));
return ret;
}
}

/* After prepare is done we no longer need runtime configuration
Expand Down Expand Up @@ -373,13 +374,15 @@ void module_free_all_memory(struct processing_module *mod)

int module_free(struct processing_module *mod)
{
int ret;
int ret = 0;
struct module_data *md = &mod->priv;

ret = md->ops->free(mod);
if (ret)
comp_warn(mod->dev, "module_free(): error: %d for %d",
ret, dev_comp_id(mod->dev));
if (md->ops->free) {
ret = md->ops->free(mod);
if (ret)
comp_warn(mod->dev, "module_free(): error: %d for %d",
ret, dev_comp_id(mod->dev));
}

/* Free all memory shared by module_adapter & module */
md->cfg.avail = false;
Expand Down

0 comments on commit 37935d3

Please sign in to comment.