@@ -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
@@ -465,6 +462,20 @@ static int cadence_codec_apply_config(struct processing_module *mod)
465462 return 0 ;
466463}
467464
465+ static void free_memory_tables (struct processing_module * mod )
466+ {
467+ struct cadence_codec_data * cd = module_get_private_data (mod );
468+ int i ;
469+
470+ if (cd -> mem_to_be_freed )
471+ for (i = 0 ; i < cd -> mem_to_be_freed_len ; i ++ )
472+ mod_free (mod , cd -> mem_to_be_freed [i ]);
473+
474+ mod_free (mod , cd -> mem_to_be_freed );
475+ cd -> mem_to_be_freed = NULL ;
476+ cd -> mem_to_be_freed_len = 0 ;
477+ }
478+
468479static int init_memory_tables (struct processing_module * mod )
469480{
470481 int ret , no_mem_tables , i , mem_type , mem_size , mem_alignment ;
@@ -493,6 +504,11 @@ static int init_memory_tables(struct processing_module *mod)
493504 return ret ;
494505 }
495506
507+ cd -> mem_to_be_freed = mod_zalloc (mod , no_mem_tables * sizeof (* cd -> mem_to_be_freed ));
508+ if (!cd -> mem_to_be_freed )
509+ return - ENOMEM ;
510+ cd -> mem_to_be_freed_len = no_mem_tables ;
511+
496512 /* Initialize each memory table */
497513 for (i = 0 ; i < no_mem_tables ; i ++ ) {
498514 /* Get type of memory - it specifies how the memory will be used */
@@ -526,6 +542,7 @@ static int init_memory_tables(struct processing_module *mod)
526542 ret = - EINVAL ;
527543 goto err ;
528544 }
545+ cd -> mem_to_be_freed [i ] = ptr ;
529546 /* Finally, provide this memory for codec */
530547 API_CALL (cd , XA_API_CMD_SET_MEM_PTR , i , ptr , ret );
531548 if (ret != LIB_NO_ERROR ) {
@@ -562,14 +579,8 @@ static int init_memory_tables(struct processing_module *mod)
562579
563580 return 0 ;
564581err :
565- if (scratch )
566- mod_free (mod , scratch );
567- if (persistent )
568- mod_free (mod , persistent );
569- if (codec -> mpd .in_buff )
570- mod_free (mod , codec -> mpd .in_buff );
571- if (codec -> mpd .out_buff )
572- mod_free (mod , codec -> mpd .out_buff );
582+ free_memory_tables (mod );
583+
573584 return ret ;
574585}
575586
@@ -842,12 +853,8 @@ static int cadence_codec_reset(struct processing_module *mod)
842853 struct cadence_codec_data * cd = codec -> private ;
843854 int ret ;
844855
845- /*
846- * Current CADENCE API doesn't support reset of codec's runtime parameters.
847- * So, free all memory associated with runtime params. These will be reallocated during
848- * prepare.
849- */
850- mod_free_all (mod );
856+ free_memory_tables (mod );
857+ mod_free (mod , cd -> mem_tabs );
851858
852859 /* reset to default params */
853860 API_CALL (cd , XA_API_CMD_INIT , XA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS , NULL , ret );
@@ -856,7 +863,7 @@ static int cadence_codec_reset(struct processing_module *mod)
856863
857864 codec -> mpd .init_done = 0 ;
858865
859- rfree ( cd -> self );
866+ mod_free ( mod , cd -> self );
860867 cd -> self = NULL ;
861868
862869 return ret ;
@@ -866,10 +873,13 @@ static int cadence_codec_free(struct processing_module *mod)
866873{
867874 struct cadence_codec_data * cd = module_get_private_data (mod );
868875
869- rfree (cd -> setup_cfg .data );
870- mod_free_all (mod );
871- rfree (cd -> self );
872- rfree (cd );
876+ mod_free (mod , cd -> setup_cfg .data );
877+
878+ free_memory_tables (mod );
879+ mod_free (mod , cd -> mem_tabs );
880+
881+ mod_free (mod , cd -> self );
882+ mod_free (mod , cd );
873883 return 0 ;
874884}
875885
0 commit comments