Skip to content

Commit 310b58f

Browse files
committed
component: split a function into two
Split comp_alloc() into two parts - allocation and initialisation to be able to re-use the initialisation code with a different allocation method. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent e201af7 commit 310b58f

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

src/include/sof/audio/component.h

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,24 @@ static inline enum sof_comp_type dev_comp_type(const struct comp_dev *dev)
847847
return dev->ipc_config.type;
848848
}
849849

850+
/**
851+
* Initialize common part of a component device
852+
* @param drv Parent component driver.
853+
* @param dev Device.
854+
* @param bytes Size of the component device in bytes.
855+
*/
856+
static inline void comp_init(const struct comp_driver *drv,
857+
struct comp_dev *dev, size_t bytes)
858+
{
859+
dev->size = bytes;
860+
dev->drv = drv;
861+
dev->state = COMP_STATE_INIT;
862+
list_init(&dev->bsink_list);
863+
list_init(&dev->bsource_list);
864+
memcpy_s(&dev->tctx, sizeof(struct tr_ctx),
865+
trace_comp_drv_get_tr_ctx(dev->drv), sizeof(struct tr_ctx));
866+
}
867+
850868
/**
851869
* Allocates memory for the component device and initializes common part.
852870
* @param drv Parent component driver.
@@ -856,22 +874,16 @@ static inline enum sof_comp_type dev_comp_type(const struct comp_dev *dev)
856874
static inline struct comp_dev *comp_alloc(const struct comp_driver *drv,
857875
size_t bytes)
858876
{
859-
struct comp_dev *dev = NULL;
860-
861877
/*
862878
* Use uncached address everywhere to access components to rule out
863879
* multi-core failures. TODO: verify if cached alias may be used in some cases
864880
*/
865-
dev = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, bytes);
881+
struct comp_dev *dev = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, bytes);
882+
866883
if (!dev)
867884
return NULL;
868-
dev->size = bytes;
869-
dev->drv = drv;
870-
dev->state = COMP_STATE_INIT;
871-
list_init(&dev->bsink_list);
872-
list_init(&dev->bsource_list);
873-
memcpy_s(&dev->tctx, sizeof(struct tr_ctx),
874-
trace_comp_drv_get_tr_ctx(dev->drv), sizeof(struct tr_ctx));
885+
886+
comp_init(drv, dev, bytes);
875887

876888
return dev;
877889
}

0 commit comments

Comments
 (0)