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 <[email protected]>
  • Loading branch information
softwarecki committed Nov 28, 2023
1 parent 5c0f8bd commit b06a878
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/audio/module_adapter/module/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,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 @@ -376,10 +378,12 @@ int module_free(struct processing_module *mod)
int ret;
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 b06a878

Please sign in to comment.