@@ -849,6 +849,24 @@ static inline enum sof_comp_type dev_comp_type(const struct comp_dev *dev)
849849 return dev -> ipc_config .type ;
850850}
851851
852+ /**
853+ * Initialize common part of a component device
854+ * @param drv Parent component driver.
855+ * @param dev Device.
856+ * @param bytes Size of the component device in bytes.
857+ */
858+ static inline void comp_init (const struct comp_driver * drv ,
859+ struct comp_dev * dev , size_t bytes )
860+ {
861+ dev -> size = bytes ;
862+ dev -> drv = drv ;
863+ dev -> state = COMP_STATE_INIT ;
864+ list_init (& dev -> bsink_list );
865+ list_init (& dev -> bsource_list );
866+ memcpy_s (& dev -> tctx , sizeof (dev -> tctx ),
867+ trace_comp_drv_get_tr_ctx (dev -> drv ), sizeof (struct tr_ctx ));
868+ }
869+
852870/**
853871 * Allocates memory for the component device and initializes common part.
854872 * @param drv Parent component driver.
@@ -857,23 +875,18 @@ static inline enum sof_comp_type dev_comp_type(const struct comp_dev *dev)
857875 */
858876static inline struct comp_dev * comp_alloc (const struct comp_driver * drv , size_t bytes )
859877{
860- struct comp_dev * dev = NULL ;
861-
862878 /*
863879 * Use uncached address everywhere to access components to rule out
864880 * multi-core failures. TODO: verify if cached alias may be used in some cases
865881 */
866- dev = module_driver_heap_rzalloc (drv -> user_heap , SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT ,
867- bytes );
882+ struct comp_dev * dev = module_driver_heap_rzalloc (drv -> user_heap ,
883+ SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT ,
884+ bytes );
885+
868886 if (!dev )
869887 return NULL ;
870- dev -> size = bytes ;
871- dev -> drv = drv ;
872- dev -> state = COMP_STATE_INIT ;
873- list_init (& dev -> bsink_list );
874- list_init (& dev -> bsource_list );
875- memcpy_s (& dev -> tctx , sizeof (struct tr_ctx ),
876- trace_comp_drv_get_tr_ctx (dev -> drv ), sizeof (struct tr_ctx ));
888+
889+ comp_init (drv , dev , bytes );
877890
878891 return dev ;
879892}
0 commit comments