Skip to content

Commit d37f42b

Browse files
kv2019ilgirdwood
authored andcommitted
audio: component: add comp_free_device() and use it as pair of comp_alloc()
In commit c49283a ("ptl: mmu: Introduce module driver heap for non-privileged modules"), implementation of comp_alloc() was modified to use module heap alloc functions instead of rzalloc(). The calling functions kept using direct rfree() to free the component device. In commit e8e5ff0 ("module-adapter: fix wrong memory freeing"), some of the callers were modified to use user heap functions for freeing the component device. To make this code safer, introduce comp_free_device() that frees the memory using the method used in comp_alloc() and use comp_free_device() in all places where comp_alloc() is used. The naming is a bit awkward as comp_free() is already taken to invoke the "free" method of the component interface. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 5dc6cb5 commit d37f42b

File tree

12 files changed

+39
-26
lines changed

12 files changed

+39
-26
lines changed

src/audio/chain_dma.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ __cold static struct comp_dev *chain_task_create(const struct comp_driver *drv,
671671

672672
rfree(cd);
673673
error:
674-
rfree(dev);
674+
comp_free_device(dev);
675675
return NULL;
676676
}
677677

@@ -683,7 +683,7 @@ __cold static void chain_task_free(struct comp_dev *dev)
683683

684684
chain_release(dev);
685685
rfree(cd);
686-
rfree(dev);
686+
comp_free_device(dev);
687687
}
688688

689689
static const struct comp_driver comp_chain_dma = {

src/audio/dai-legacy.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static struct comp_dev *dai_new(const struct comp_driver *drv,
196196

197197
dd = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*dd));
198198
if (!dd) {
199-
rfree(dev);
199+
comp_free_device(dev);
200200
return NULL;
201201
}
202202

@@ -211,7 +211,7 @@ static struct comp_dev *dai_new(const struct comp_driver *drv,
211211

212212
error:
213213
rfree(dd);
214-
rfree(dev);
214+
comp_free_device(dev);
215215
return NULL;
216216
}
217217

@@ -248,7 +248,7 @@ static void dai_free(struct comp_dev *dev)
248248
dai_common_free(dd);
249249

250250
rfree(dd);
251-
rfree(dev);
251+
comp_free_device(dev);
252252
}
253253

254254
int dai_common_get_hw_params(struct dai_data *dd, struct comp_dev *dev,

src/audio/dai-zephyr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ __cold static struct comp_dev *dai_new(const struct comp_driver *drv,
589589
error:
590590
rfree(dd);
591591
e_data:
592-
rfree(dev);
592+
comp_free_device(dev);
593593
return NULL;
594594
}
595595

@@ -630,7 +630,7 @@ __cold static void dai_free(struct comp_dev *dev)
630630
dai_common_free(dd);
631631

632632
rfree(dd);
633-
rfree(dev);
633+
comp_free_device(dev);
634634
}
635635

636636
int dai_common_get_hw_params(struct dai_data *dd, struct comp_dev *dev,

src/audio/google/google_hotword_detect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static struct comp_dev *ghd_create(const struct comp_driver *drv,
134134
ipc_msg_free(cd->msg);
135135
rfree(cd);
136136
fail:
137-
rfree(dev);
137+
comp_free_device(dev);
138138
return NULL;
139139
}
140140

@@ -147,7 +147,7 @@ static void ghd_free(struct comp_dev *dev)
147147
comp_data_blob_handler_free(cd->model_handler);
148148
ipc_msg_free(cd->msg);
149149
rfree(cd);
150-
rfree(dev);
150+
comp_free_device(dev);
151151
}
152152

153153
static int ghd_params(struct comp_dev *dev,

src/audio/host-legacy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ static struct comp_dev *host_new(const struct comp_driver *drv,
593593
e_dev:
594594
rfree(hd);
595595
e_data:
596-
rfree(dev);
596+
comp_free_device(dev);
597597
return NULL;
598598
}
599599

@@ -612,7 +612,7 @@ static void host_free(struct comp_dev *dev)
612612
comp_dbg(dev, "entry");
613613
host_common_free(hd);
614614
rfree(hd);
615-
rfree(dev);
615+
comp_free_device(dev);
616616
}
617617

618618
static int host_elements_reset(struct host_data *hd, struct comp_dev *dev)

src/audio/host-zephyr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ __cold static struct comp_dev *host_new(const struct comp_driver *drv,
775775
e_dev:
776776
rfree(hd);
777777
e_data:
778-
rfree(dev);
778+
comp_free_device(dev);
779779
return NULL;
780780
}
781781

@@ -798,7 +798,7 @@ __cold static void host_free(struct comp_dev *dev)
798798
comp_dbg(dev, "entry");
799799
host_common_free(hd);
800800
rfree(hd);
801-
rfree(dev);
801+
comp_free_device(dev);
802802
}
803803

804804
static int host_elements_reset(struct host_data *hd, int direction)

src/audio/kpb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,15 +501,15 @@ static struct comp_dev *kpb_new(const struct comp_driver *drv,
501501

502502
kpb = rzalloc(SOF_MEM_FLAG_USER, sizeof(*kpb));
503503
if (!kpb) {
504-
rfree(dev);
504+
comp_free_device(dev);
505505
return NULL;
506506
}
507507

508508
comp_set_drvdata(dev, kpb);
509509

510510
ret = kpb_set_verify_ipc_params(dev, ipc_process);
511511
if (ret) {
512-
rfree(dev);
512+
comp_free_device(dev);
513513
return NULL;
514514
}
515515

@@ -544,7 +544,7 @@ static struct comp_dev *kpb_new(const struct comp_driver *drv,
544544
/* retrieve params from the base config for IPC4 */
545545
ret = kpb_params(dev, &params);
546546
if (ret < 0) {
547-
rfree(dev);
547+
comp_free_device(dev);
548548
return NULL;
549549
}
550550
#endif
@@ -720,7 +720,7 @@ static void kpb_free(struct comp_dev *dev)
720720

721721
/* Free KPB */
722722
rfree(kpb);
723-
rfree(dev);
723+
comp_free_device(dev);
724724
}
725725

726726
/**

src/audio/selector/selector.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static struct comp_dev *selector_new(const struct comp_driver *drv,
163163

164164
cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd));
165165
if (!cd) {
166-
rfree(dev);
166+
comp_free_device(dev);
167167
return NULL;
168168
}
169169

@@ -172,7 +172,7 @@ static struct comp_dev *selector_new(const struct comp_driver *drv,
172172
ret = memcpy_s(&cd->config, sizeof(cd->config), ipc_process->data, bs);
173173
if (ret) {
174174
rfree(cd);
175-
rfree(dev);
175+
comp_free_device(dev);
176176
return NULL;
177177
}
178178

@@ -191,7 +191,7 @@ static void selector_free(struct comp_dev *dev)
191191
comp_dbg(dev, "entry");
192192

193193
rfree(cd);
194-
rfree(dev);
194+
comp_free_device(dev);
195195
}
196196

197197
/**

src/audio/tone/tone-ipc3.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static struct comp_dev *tone_new(const struct comp_driver *drv,
5858

5959
cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd));
6060
if (!cd) {
61-
rfree(dev);
61+
comp_free_device(dev);
6262
return NULL;
6363
}
6464

@@ -82,7 +82,7 @@ static void tone_free(struct comp_dev *dev)
8282
comp_info(dev, "entry");
8383

8484
rfree(td);
85-
rfree(dev);
85+
comp_free_device(dev);
8686
}
8787

8888
/* set component audio stream parameters */

src/include/sof/audio/component.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,19 @@ static inline struct comp_dev *comp_alloc(const struct comp_driver *drv, size_t
892892
return dev;
893893
}
894894

895+
/**
896+
* Frees memory allocated for component device.
897+
*
898+
* This is a counterpart to comp_alloc() and not to be confused with
899+
* comp_free().
900+
*
901+
* @param dev Pointer to the component device.
902+
*/
903+
static inline void comp_free_device(struct comp_dev *dev)
904+
{
905+
sof_heap_free(dev->drv->user_heap, dev);
906+
}
907+
895908
/**
896909
* \brief Module adapter associated with a component
897910
* @param dev Component device

0 commit comments

Comments
 (0)