comp: provide comp_alloc for device alloc and init

This short helper not only groups and hides some infrastructure level
initialization steps but also guarantees that none of it is
missed in the component implementation.
It is easier to group the steps in internal function rather
then explain them and remember to add to every new component
(especially that initialized comp_dev members are used internally).

Signed-off-by: Marcin Maka <marcin.maka@linux.intel.com>
This commit is contained in:
Marcin Maka 2020-04-06 19:39:27 +02:00 committed by Daniel Baluta
parent de085f22f5
commit e66b40a5b4
1 changed files with 20 additions and 0 deletions

View File

@ -527,6 +527,26 @@ static inline struct sof_ipc_comp_config *dev_comp_config(struct comp_dev *dev)
return (struct sof_ipc_comp_config *)(&dev->comp + 1);
}
/**
* Allocates memory for the component device and initializes common part.
* @param drv Parent component driver.
* @param bytes Size of the component device in bytes.
* @return Pointer to the component device.
*/
static inline struct comp_dev *comp_alloc(const struct comp_driver *drv,
size_t bytes)
{
struct comp_dev *dev = NULL;
dev = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, bytes);
if (!dev)
return NULL;
dev->size = bytes;
dev->drv = drv;
return dev;
}
/**
* Retrieves component config data from component ipc.
* @param comp Component ipc data.