@@ -235,7 +235,7 @@ static int cadence_codec_post_init(struct processing_module *mod)
235235 return ret ;
236236 }
237237 /* Allocate space for codec object */
238- cd -> self = rballoc ( SOF_MEM_FLAG_USER , obj_size );
238+ cd -> self = mod_balloc ( mod , obj_size );
239239 if (!cd -> self ) {
240240 comp_err (dev , "failed to allocate space for lib object" );
241241 return - ENOMEM ;
@@ -247,7 +247,7 @@ static int cadence_codec_post_init(struct processing_module *mod)
247247 API_CALL (cd , XA_API_CMD_INIT , XA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS ,
248248 NULL , ret );
249249 if (ret != LIB_NO_ERROR ) {
250- rfree ( cd -> self );
250+ mod_free ( mod , cd -> self );
251251 return ret ;
252252 }
253253
@@ -268,7 +268,7 @@ static int cadence_codec_init(struct processing_module *mod)
268268
269269 comp_dbg (dev , "cadence_codec_init() start" );
270270
271- cd = rzalloc ( SOF_MEM_FLAG_USER , sizeof (struct cadence_codec_data ));
271+ cd = mod_zalloc ( mod , sizeof (struct cadence_codec_data ));
272272 if (!cd ) {
273273 comp_err (dev , "failed to allocate memory for cadence codec data" );
274274 return - ENOMEM ;
@@ -284,17 +284,15 @@ static int cadence_codec_init(struct processing_module *mod)
284284 cfg = (const struct ipc4_cadence_module_cfg * )codec -> cfg .init_data ;
285285
286286 /* allocate memory for set up config */
287- setup_cfg -> data = rmalloc (SOF_MEM_FLAG_USER ,
288- cfg -> param_size );
287+ setup_cfg -> data = mod_alloc (mod , cfg -> param_size );
289288 if (!setup_cfg -> data ) {
290289 comp_err (dev , "failed to alloc setup config" );
291290 ret = - ENOMEM ;
292291 goto free ;
293292 }
294293
295294 /* allocate memory for runtime set up config */
296- codec -> cfg .data = rmalloc (SOF_MEM_FLAG_USER ,
297- cfg -> param_size );
295+ codec -> cfg .data = mod_alloc (mod , cfg -> param_size );
298296 if (!codec -> cfg .data ) {
299297 comp_err (dev , "failed to alloc runtime setup config" );
300298 ret = - ENOMEM ;
@@ -326,11 +324,11 @@ static int cadence_codec_init(struct processing_module *mod)
326324 return 0 ;
327325
328326free_cfg2 :
329- rfree ( codec -> cfg .data );
327+ mod_free ( mod , codec -> cfg .data );
330328free_cfg :
331- rfree ( setup_cfg -> data );
329+ mod_free ( mod , setup_cfg -> data );
332330free :
333- rfree ( cd );
331+ mod_free ( mod , cd );
334332 return ret ;
335333}
336334
@@ -345,7 +343,7 @@ static int cadence_codec_init(struct processing_module *mod)
345343
346344 comp_dbg (dev , "cadence_codec_init() start" );
347345
348- cd = rzalloc ( SOF_MEM_FLAG_USER , sizeof (struct cadence_codec_data ));
346+ cd = mod_zalloc ( mod , sizeof (struct cadence_codec_data ));
349347 if (!cd ) {
350348 comp_err (dev , "failed to allocate memory for cadence codec data" );
351349 return - ENOMEM ;
@@ -359,8 +357,7 @@ static int cadence_codec_init(struct processing_module *mod)
359357 setup_cfg = & cd -> setup_cfg ;
360358
361359 /* allocate memory for set up config */
362- setup_cfg -> data = rmalloc (SOF_MEM_FLAG_USER ,
363- codec -> cfg .size );
360+ setup_cfg -> data = mod_alloc (mod , codec -> cfg .size );
364361 if (!setup_cfg -> data ) {
365362 comp_err (dev , "failed to alloc setup config" );
366363 ret = - ENOMEM ;
@@ -383,9 +380,9 @@ static int cadence_codec_init(struct processing_module *mod)
383380 return 0 ;
384381
385382free_cfg :
386- rfree ( setup_cfg -> data );
383+ mod_free ( mod , setup_cfg -> data );
387384free :
388- rfree ( cd );
385+ mod_free ( mod , cd );
389386 return ret ;
390387}
391388
@@ -673,6 +670,18 @@ static int cadence_codec_prepare(struct processing_module *mod,
673670 if (ret )
674671 return ret ;
675672
673+ /*
674+ * The reason why lvl2 init is called here and before is
675+ * because earlier the cd->self was not allocated with
676+ * mod_balloc(), but directly from heap with rballoc(). So the
677+ * idea is to keep line between the two levels of allocation in
678+ * the same place. However, it would make sense to move
679+ * mod_alloc_lvl2_init() before cadence_codec_post_init()
680+ * call, so that all memory in prepare()/reset() cycle would
681+ * be allocated from lvl2.
682+ */
683+ mod_alloc_lvl2_init (mod );
684+
676685 ret = cadence_codec_apply_config (mod );
677686 if (ret ) {
678687 comp_err (dev , "cadence_codec_prepare() error %x: failed to apply config" ,
@@ -847,7 +856,7 @@ static int cadence_codec_reset(struct processing_module *mod)
847856 * So, free all memory associated with runtime params. These will be reallocated during
848857 * prepare.
849858 */
850- mod_free_all (mod );
859+ mod_free_all_lvl2 (mod );
851860
852861 /* reset to default params */
853862 API_CALL (cd , XA_API_CMD_INIT , XA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS , NULL , ret );
@@ -856,7 +865,7 @@ static int cadence_codec_reset(struct processing_module *mod)
856865
857866 codec -> mpd .init_done = 0 ;
858867
859- rfree ( cd -> self );
868+ mod_free ( mod , cd -> self );
860869 cd -> self = NULL ;
861870
862871 return ret ;
@@ -866,10 +875,10 @@ static int cadence_codec_free(struct processing_module *mod)
866875{
867876 struct cadence_codec_data * cd = module_get_private_data (mod );
868877
869- rfree ( cd -> setup_cfg .data );
870- mod_free_all (mod );
871- rfree ( cd -> self );
872- rfree ( cd );
878+ mod_free ( mod , cd -> setup_cfg .data );
879+ mod_free_all_lvl2 (mod );
880+ mod_free ( mod , cd -> self );
881+ mod_free ( mod , cd );
873882 return 0 ;
874883}
875884
0 commit comments