Skip to content

Commit fb65739

Browse files
author
Jyri Sarha
committed
Audio: Copier: All memory allocations through module API
Allocate all memory through module API mod_alloc() and friends and remove all redundant rfree() calls from module unload functions and init error branches. NOTE: copier_dai.c and copier_host.c still have their shared memory allocated through the old API. This is to be fixed once we have decided on how the shared memory allocations should work in user-space. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 262cc41 commit fb65739

5 files changed

Lines changed: 34 additions & 65 deletions

File tree

src/audio/copier/copier.c

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <sof/ipc/topology.h>
1616
#include <rtos/interrupt.h>
1717
#include <rtos/timer.h>
18-
#include <rtos/alloc.h>
1918
#include <rtos/cache.h>
2019
#include <rtos/init.h>
2120
#include <sof/lib/memory.h>
@@ -82,13 +81,12 @@ static void mic_privacy_event(void *arg, enum notify_id type, void *data)
8281
}
8382
}
8483

85-
static int mic_privacy_configure(struct comp_dev *dev, struct copier_data *cd)
84+
static int mic_privacy_configure(struct processing_module *mod, struct copier_data *cd)
8685
{
8786
struct mic_privacy_data *mic_priv_data;
8887
int ret;
8988

90-
mic_priv_data = rzalloc(SOF_MEM_FLAG_USER,
91-
sizeof(struct mic_privacy_data));
89+
mic_priv_data = mod_zalloc(mod, sizeof(struct mic_privacy_data));
9290
if (!mic_priv_data)
9391
return -ENOMEM;
9492

@@ -100,19 +98,15 @@ static int mic_privacy_configure(struct comp_dev *dev, struct copier_data *cd)
10098
uint32_t zeroing_wait_time = (mic_privacy_get_dma_zeroing_wait_time() * 1000) /
10199
ADSP_RTC_FREQUENCY;
102100

103-
ret = copier_gain_set_params(dev, &mic_priv_data->mic_priv_gain_params,
101+
ret = copier_gain_set_params(mod->dev, &mic_priv_data->mic_priv_gain_params,
104102
zeroing_wait_time, SOF_DAI_INTEL_NONE);
105-
if (ret != 0) {
106-
rfree(mic_priv_data);
103+
if (ret != 0)
107104
return ret;
108-
}
109105

110106
cd->mic_priv = mic_priv_data;
111107

112108
ret = notifier_register(cd->mic_priv, NULL, NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE,
113109
mic_privacy_event, 0);
114-
if (ret != 0)
115-
rfree(mic_priv_data);
116110

117111
return ret;
118112
}
@@ -123,8 +117,6 @@ static void mic_privacy_free(struct copier_data *cd)
123117
mic_privacy_enable_dmic_irq(false);
124118

125119
notifier_unregister(cd->mic_priv, NULL, NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE);
126-
127-
rfree(cd->mic_priv);
128120
}
129121
#endif
130122

@@ -144,7 +136,7 @@ __cold static int copier_init(struct processing_module *mod)
144136

145137
assert_can_be_cold();
146138

147-
cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd));
139+
cd = mod_zalloc(mod, sizeof(*cd));
148140
if (!cd)
149141
return -ENOMEM;
150142

@@ -154,10 +146,8 @@ __cold static int copier_init(struct processing_module *mod)
154146
* store it, it's only used during IPC processing, besides we haven't
155147
* allocated space for it, so don't "fix" this!
156148
*/
157-
if (memcpy_s(&cd->config, sizeof(cd->config), copier, sizeof(*copier)) < 0) {
158-
ret = -EINVAL;
159-
goto error_cd;
160-
}
149+
if (memcpy_s(&cd->config, sizeof(cd->config), copier, sizeof(*copier)) < 0)
150+
return -EINVAL;
161151

162152
/* Allocate memory and store gateway_cfg in runtime. Gateway cfg has to
163153
* be kept even after copier is created e.g. during SET_PIPELINE_STATE
@@ -166,18 +156,15 @@ __cold static int copier_init(struct processing_module *mod)
166156
*/
167157
if (copier->gtw_cfg.config_length) {
168158
gtw_cfg_size = copier->gtw_cfg.config_length << 2;
169-
gtw_cfg = rmalloc(SOF_MEM_FLAG_USER,
170-
gtw_cfg_size);
171-
if (!gtw_cfg) {
172-
ret = -ENOMEM;
173-
goto error_cd;
174-
}
159+
gtw_cfg = mod_alloc(mod, gtw_cfg_size);
160+
if (!gtw_cfg)
161+
return -ENOMEM;
175162

176163
ret = memcpy_s(gtw_cfg, gtw_cfg_size, &copier->gtw_cfg.config_data,
177164
gtw_cfg_size);
178165
if (ret) {
179166
comp_err(dev, "Unable to copy gateway config from copier blob");
180-
goto error;
167+
return ret;
181168
}
182169

183170
cd->gtw_cfg = gtw_cfg;
@@ -191,8 +178,7 @@ __cold static int copier_init(struct processing_module *mod)
191178
IPC_COMP_IGNORE_REMOTE);
192179
if (!ipc_pipe) {
193180
comp_err(dev, "pipeline %d is not existed", config->pipeline_id);
194-
ret = -EPIPE;
195-
goto error;
181+
return -EPIPE;
196182
}
197183

198184
dev->pipeline = ipc_pipe->pipeline;
@@ -205,18 +191,18 @@ __cold static int copier_init(struct processing_module *mod)
205191
switch (node_id.f.dma_type) {
206192
case ipc4_hda_host_output_class:
207193
case ipc4_hda_host_input_class:
208-
ret = copier_host_create(dev, cd, copier, ipc_pipe->pipeline);
194+
ret = copier_host_create(mod, cd, copier, ipc_pipe->pipeline);
209195
if (ret < 0) {
210196
comp_err(dev, "unable to create host");
211-
goto error;
197+
return ret;
212198
}
213199
#if CONFIG_INTEL_ADSP_MIC_PRIVACY
214200
if (cd->direction == SOF_IPC_STREAM_CAPTURE &&
215201
node_id.f.dma_type == ipc4_hda_host_output_class) {
216-
ret = mic_privacy_configure(dev, cd);
202+
ret = mic_privacy_configure(mod, cd);
217203
if (ret < 0) {
218204
comp_err(dev, "unable to configure mic privacy");
219-
goto error;
205+
return ret;
220206
}
221207
}
222208
#endif
@@ -231,32 +217,31 @@ __cold static int copier_init(struct processing_module *mod)
231217
ret = copier_dai_create(dev, cd, copier, ipc_pipe->pipeline);
232218
if (ret < 0) {
233219
comp_err(dev, "unable to create dai");
234-
goto error;
220+
return ret;
235221
}
236222
#if CONFIG_INTEL_ADSP_MIC_PRIVACY
237223
if (cd->direction == SOF_IPC_STREAM_CAPTURE) {
238-
ret = mic_privacy_configure(dev, cd);
224+
ret = mic_privacy_configure(mod, cd);
239225
if (ret < 0) {
240226
comp_err(dev, "unable to configure mic privacy");
241-
goto error;
227+
return ret;
242228
}
243229
}
244230
#endif
245231
break;
246232
#if CONFIG_IPC4_GATEWAY
247233
case ipc4_ipc_output_class:
248234
case ipc4_ipc_input_class:
249-
ret = copier_ipcgtw_create(dev, cd, copier, ipc_pipe->pipeline);
235+
ret = copier_ipcgtw_create(mod, cd, copier, ipc_pipe->pipeline);
250236
if (ret < 0) {
251237
comp_err(dev, "unable to create IPC gateway");
252-
goto error;
238+
return ret;
253239
}
254240
break;
255241
#endif
256242
default:
257243
comp_err(dev, "unsupported dma type %x", (uint32_t)node_id.f.dma_type);
258-
ret = -EINVAL;
259-
goto error;
244+
return -EINVAL;
260245
};
261246

262247
dev->direction_set = true;
@@ -270,11 +255,6 @@ __cold static int copier_init(struct processing_module *mod)
270255
dev->direction = cd->direction;
271256
dev->state = COMP_STATE_READY;
272257
return 0;
273-
error:
274-
rfree(gtw_cfg);
275-
error_cd:
276-
rfree(cd);
277-
return ret;
278258
}
279259

280260
__cold static int copier_free(struct processing_module *mod)
@@ -303,10 +283,6 @@ __cold static int copier_free(struct processing_module *mod)
303283
break;
304284
}
305285

306-
if (cd)
307-
rfree(cd->gtw_cfg);
308-
rfree(cd);
309-
310286
return 0;
311287
}
312288

src/audio/copier/copier_host.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ __cold static int init_pipeline_reg(struct comp_dev *dev)
131131
* Sof host component can support this case so copier reuses host
132132
* component to support host gateway.
133133
*/
134-
__cold int copier_host_create(struct comp_dev *dev, struct copier_data *cd,
134+
__cold int copier_host_create(struct processing_module *mod, struct copier_data *cd,
135135
const struct ipc4_copier_module_cfg *copier_cfg,
136136
struct pipeline *pipeline)
137137
{
138-
struct processing_module *mod = comp_mod(dev);
138+
struct comp_dev *dev = mod->dev;
139139
struct comp_ipc_config *config = &dev->ipc_config;
140140
struct ipc_config_host ipc_host;
141141
struct host_data *hd;
@@ -177,16 +177,17 @@ __cold int copier_host_create(struct comp_dev *dev, struct copier_data *cd,
177177
ipc_host.dma_buffer_size = copier_cfg->gtw_cfg.dma_buffer_size;
178178
ipc_host.feature_mask = copier_cfg->copier_feature_mask;
179179

180-
hd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*hd));
180+
hd = mod_zalloc(mod, sizeof(*hd));
181181
if (!hd)
182182
return -ENOMEM;
183183

184184
ret = host_common_new(hd, dev, &ipc_host, config->id);
185185
if (ret < 0) {
186186
comp_err(dev, "copier: host new failed with exit");
187-
goto e_data;
187+
return ret;
188188
}
189189
#if CONFIG_HOST_DMA_STREAM_SYNCHRONIZATION
190+
/* NOTE: Should use goto e_conv this #if section, not direct return */
190191
/* Size of a configuration without optional parameters. */
191192
const uint32_t basic_size = sizeof(*copier_cfg) +
192193
(copier_cfg->gtw_cfg.config_length - 1) * sizeof(uint32_t);
@@ -248,8 +249,6 @@ __cold int copier_host_create(struct comp_dev *dev, struct copier_data *cd,
248249

249250
e_conv:
250251
host_common_free(hd);
251-
e_data:
252-
rfree(hd);
253252

254253
return ret;
255254
}
@@ -263,7 +262,6 @@ __cold void copier_host_free(struct copier_data *cd)
263262
delete_from_fpi_sync_group(cd->hd);
264263
#endif
265264
host_common_free(cd->hd);
266-
rfree(cd->hd);
267265
}
268266

269267
/* This is called by DMA driver every time when DMA completes its current

src/audio/copier/copier_ipcgtw.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//
33
// Copyright 2023 Intel Corporation. All rights reserved.
44

5+
#include <sof/audio/module_adapter/module/generic.h>
56
#include <sof/audio/component_ext.h>
67
#include <sof/trace/trace.h>
78
#include <sof/lib/memory.h>
@@ -207,15 +208,15 @@ void copier_ipcgtw_reset(struct comp_dev *dev)
207208
}
208209
}
209210

210-
__cold int copier_ipcgtw_create(struct comp_dev *dev, struct copier_data *cd,
211+
__cold int copier_ipcgtw_create(struct processing_module *mod, struct copier_data *cd,
211212
const struct ipc4_copier_module_cfg *copier,
212213
struct pipeline *pipeline)
213214
{
215+
struct comp_dev *dev = mod->dev;
214216
struct comp_ipc_config *config = &dev->ipc_config;
215217
struct ipcgtw_data *ipcgtw_data;
216218
const struct ipc4_copier_gateway_cfg *gtw_cfg;
217219
const struct ipc4_ipc_gateway_config_blob *blob;
218-
int ret;
219220

220221
assert_can_be_cold();
221222

@@ -231,7 +232,7 @@ __cold int copier_ipcgtw_create(struct comp_dev *dev, struct copier_data *cd,
231232
config->type = SOF_COMP_HOST;
232233
cd->gtw_type = ipc4_gtw_host;
233234

234-
ipcgtw_data = rzalloc(SOF_MEM_FLAG_USER, sizeof(*ipcgtw_data));
235+
ipcgtw_data = mod_zalloc(mod, sizeof(*ipcgtw_data));
235236
if (!ipcgtw_data)
236237
return -ENOMEM;
237238

@@ -254,8 +255,7 @@ __cold int copier_ipcgtw_create(struct comp_dev *dev, struct copier_data *cd,
254255
if (!cd->converter[IPC4_COPIER_GATEWAY_PIN]) {
255256
comp_err(dev, "failed to get converter for IPC gateway, dir %d",
256257
cd->direction);
257-
ret = -EINVAL;
258-
goto e_ipcgtw;
258+
return -EINVAL;
259259
}
260260

261261
if (cd->direction == SOF_IPC_STREAM_PLAYBACK) {
@@ -271,16 +271,11 @@ __cold int copier_ipcgtw_create(struct comp_dev *dev, struct copier_data *cd,
271271
cd->endpoint_num++;
272272

273273
return 0;
274-
275-
e_ipcgtw:
276-
rfree(ipcgtw_data);
277-
return ret;
278274
}
279275

280276
__cold void copier_ipcgtw_free(struct copier_data *cd)
281277
{
282278
assert_can_be_cold();
283279

284280
list_item_del(&cd->ipcgtw_data->item);
285-
rfree(cd->ipcgtw_data);
286281
}

src/audio/copier/host_copier.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static inline int host_common_copy(struct host_data *hd, struct comp_dev *dev, c
129129
}
130130
void host_common_update(struct host_data *hd, struct comp_dev *dev, uint32_t bytes);
131131
void host_common_one_shot(struct host_data *hd, uint32_t bytes);
132-
int copier_host_create(struct comp_dev *dev, struct copier_data *cd,
132+
int copier_host_create(struct processing_module *mod, struct copier_data *cd,
133133
const struct ipc4_copier_module_cfg *copier_cfg,
134134
struct pipeline *pipeline);
135135
void copier_host_free(struct copier_data *cd);

src/audio/copier/ipcgtw_copier.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct ipc4_ipc_gateway_cmd_data_reply {
9595
int copier_ipcgtw_process(const struct ipc4_ipcgtw_cmd *cmd,
9696
void *reply_payload, uint32_t *reply_payload_size);
9797

98-
int copier_ipcgtw_create(struct comp_dev *dev, struct copier_data *cd,
98+
int copier_ipcgtw_create(struct processing_module *mod, struct copier_data *cd,
9999
const struct ipc4_copier_module_cfg *copier, struct pipeline *pipeline);
100100

101101
#if CONFIG_IPC4_GATEWAY

0 commit comments

Comments
 (0)