@@ -44,6 +44,56 @@ struct comp_dev *module_adapter_new(const struct comp_driver *drv,
4444 return module_adapter_new_ext (drv , config , spec , NULL );
4545}
4646
47+ static struct processing_module * module_adapter_mem_alloc (const struct comp_driver * drv ,
48+ const struct comp_ipc_config * config )
49+ {
50+ struct comp_dev * dev = comp_alloc (drv , sizeof (* dev ));
51+
52+ if (!dev ) {
53+ comp_cl_err (drv , "failed to allocate memory for comp_dev" );
54+ return NULL ;
55+ }
56+
57+ /* allocate module information.
58+ * for DP shared modules this struct must be accessible from all cores
59+ * Unfortunately at this point there's no information of components the module
60+ * will be bound to. So we need to allocate shared memory for each DP module
61+ * To be removed when pipeline 2.0 is ready
62+ */
63+ int flags = config -> proc_domain == COMP_PROCESSING_DOMAIN_DP ?
64+ SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT : SOF_MEM_FLAG_USER ;
65+
66+ struct processing_module * mod = module_driver_heap_rzalloc (drv -> user_heap , flags ,
67+ sizeof (* mod ));
68+
69+ if (!mod ) {
70+ comp_err (dev , "failed to allocate memory for module" );
71+ goto err ;
72+ }
73+
74+ dev -> ipc_config = * config ;
75+ mod -> dev = dev ;
76+ dev -> mod = mod ;
77+
78+ return mod ;
79+
80+ err :
81+ module_driver_heap_free (drv -> user_heap , dev );
82+
83+ return NULL ;
84+ }
85+
86+ static void module_adapter_mem_free (struct processing_module * mod )
87+ {
88+ const struct comp_driver * drv = mod -> dev -> drv ;
89+
90+ #if CONFIG_IPC_MAJOR_4
91+ module_driver_heap_free (drv -> user_heap , mod -> priv .cfg .input_pins );
92+ #endif
93+ module_driver_heap_free (drv -> user_heap , mod -> dev );
94+ module_driver_heap_free (drv -> user_heap , mod );
95+ }
96+
4797/*
4898 * \brief Create a module adapter component.
4999 * \param[in] drv - component driver pointer.
@@ -61,8 +111,6 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
61111 void * mod_priv )
62112{
63113 int ret ;
64- struct comp_dev * dev ;
65- struct processing_module * mod ;
66114 struct module_config * dst ;
67115 const struct module_interface * const interface = drv -> adapter_ops ;
68116
@@ -74,33 +122,16 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
74122 return NULL ;
75123 }
76124
77- dev = comp_alloc (drv , sizeof (* dev ));
78- if (!dev ) {
79- comp_cl_err (drv , "failed to allocate memory for comp_dev" );
80- return NULL ;
81- }
82- dev -> ipc_config = * config ;
83-
84- /* allocate module information.
85- * for DP shared modules this struct must be accessible from all cores
86- * Unfortunately at this point there's no information of components the module
87- * will be bound to. So we need to allocate shared memory for each DP module
88- * To be removed when pipeline 2.0 is ready
89- */
90- int flags = config -> proc_domain == COMP_PROCESSING_DOMAIN_DP ?
91- SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT : SOF_MEM_FLAG_USER ;
125+ struct processing_module * mod = module_adapter_mem_alloc (drv , config );
92126
93- mod = module_driver_heap_rzalloc (drv -> user_heap , flags , sizeof (* mod ));
94- if (!mod ) {
95- comp_err (dev , "failed to allocate memory for module" );
96- goto err ;
97- }
127+ if (!mod )
128+ return NULL ;
98129
99130 dst = & mod -> priv .cfg ;
100131
101132 module_set_private_data (mod , mod_priv );
102- mod -> dev = dev ;
103- dev -> mod = mod ;
133+
134+ struct comp_dev * dev = mod -> dev ;
104135
105136 list_init (& mod -> raw_data_buffers_list );
106137
@@ -178,13 +209,10 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
178209
179210 comp_dbg (dev , "done" );
180211 return dev ;
212+
181213err :
182- #if CONFIG_IPC_MAJOR_4
183- if (mod )
184- module_driver_heap_free (drv -> user_heap , mod -> priv .cfg .input_pins );
185- #endif
186- module_driver_heap_free (drv -> user_heap , mod );
187- module_driver_heap_free (drv -> user_heap , dev );
214+ module_adapter_mem_free (mod );
215+
188216 return NULL ;
189217}
190218EXPORT_SYMBOL (module_adapter_new );
@@ -1282,13 +1310,8 @@ void module_adapter_free(struct comp_dev *dev)
12821310
12831311 mod_free_all (mod );
12841312
1285- #if CONFIG_IPC_MAJOR_4
1286- module_driver_heap_free (dev -> drv -> user_heap , mod -> priv .cfg .input_pins );
1287- #endif
1288-
12891313 rfree (mod -> stream_params );
1290- module_driver_heap_free (dev -> drv -> user_heap , mod );
1291- module_driver_heap_free (dev -> drv -> user_heap , dev );
1314+ module_adapter_mem_free (mod );
12921315}
12931316EXPORT_SYMBOL (module_adapter_free );
12941317
0 commit comments