Skip to content

Commit bd13751

Browse files
author
Jyri Sarha
committed
audio: volume: Memory, blob, and fast_get allocs to module API
Allocate all memory, blob handlers, and fast_get() buffers through module API mod_alloc() and friends and remove all redundant rfree(), comp_data_blob_handler_free(), and fast_put() calls from module unload functions and init error branches. When resources are allocated through module API functions they are automatically freed when the module is unloaded. This simplifies error handling and unloading process. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent cb65c6a commit bd13751

File tree

3 files changed

+5
-19
lines changed

3 files changed

+5
-19
lines changed

src/audio/volume/volume.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <sof/common.h>
2525
#include <rtos/panic.h>
2626
#include <sof/ipc/msg.h>
27-
#include <rtos/alloc.h>
2827
#include <rtos/init.h>
2928
#include <sof/lib/cpu.h>
3029
#include <sof/lib/uuid.h>
@@ -775,11 +774,7 @@ static int volume_free(struct processing_module *mod)
775774
struct vol_data *cd = module_get_private_data(mod);
776775

777776
comp_dbg(mod->dev, "volume_free()");
778-
779777
volume_peak_free(cd);
780-
rfree(cd->vol);
781-
rfree(cd);
782-
783778
return 0;
784779
}
785780

src/audio/volume/volume_ipc3.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <sof/common.h>
1515
#include <rtos/panic.h>
1616
#include <sof/ipc/msg.h>
17-
#include <rtos/alloc.h>
1817
#include <rtos/init.h>
1918
#include <sof/lib/cpu.h>
2019
#include <sof/lib/uuid.h>
@@ -81,17 +80,16 @@ int volume_init(struct processing_module *mod)
8180
return -EINVAL;
8281
}
8382

84-
cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(struct vol_data));
83+
cd = mod_zalloc(mod, sizeof(struct vol_data));
8584
if (!cd)
8685
return -ENOMEM;
8786

8887
/*
8988
* malloc memory to store current volume 4 times to ensure the address
9089
* is 8-byte aligned for multi-way xtensa intrinsic operations.
9190
*/
92-
cd->vol = rmalloc(SOF_MEM_FLAG_USER, vol_size);
91+
cd->vol = mod_alloc(mod, vol_size);
9392
if (!cd->vol) {
94-
rfree(cd);
9593
comp_err(dev, "Failed to allocate %zu", vol_size);
9694
return -ENOMEM;
9795
}
@@ -158,8 +156,6 @@ int volume_init(struct processing_module *mod)
158156
break;
159157
default:
160158
comp_err(dev, "invalid ramp type %d", vol->ramp);
161-
rfree(cd);
162-
rfree(cd->vol);
163159
return -EINVAL;
164160
}
165161

src/audio/volume/volume_ipc4.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <sof/common.h>
1515
#include <rtos/panic.h>
1616
#include <sof/ipc/msg.h>
17-
#include <rtos/alloc.h>
1817
#include <rtos/init.h>
1918
#include <sof/lib/cpu.h>
2019
#include <sof/lib/uuid.h>
@@ -128,28 +127,25 @@ int volume_init(struct processing_module *mod)
128127
return -EINVAL;
129128
}
130129

131-
cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(struct vol_data));
130+
cd = mod_zalloc(mod, sizeof(struct vol_data));
132131
if (!cd)
133132
return -ENOMEM;
134133

135134
/*
136135
* malloc memory to store current volume 4 times to ensure the address
137136
* is 8-byte aligned for multi-way xtensa intrinsic operations.
138137
*/
139-
cd->vol = rmalloc(SOF_MEM_FLAG_USER, vol_size);
138+
cd->vol = mod_alloc(mod, vol_size);
140139
if (!cd->vol) {
141-
rfree(cd);
142140
comp_err(dev, "Failed to allocate %d", vol_size);
143141
return -ENOMEM;
144142
}
145143

146144
/* malloc memory to store temp peak volume 4 times to ensure the address
147145
* is 8-byte aligned for multi-way xtensa intrinsic operations.
148146
*/
149-
cd->peak_vol = rzalloc(SOF_MEM_FLAG_USER, vol_size);
147+
cd->peak_vol = mod_zalloc(mod, vol_size);
150148
if (!cd->peak_vol) {
151-
rfree(cd->vol);
152-
rfree(cd);
153149
comp_err(dev, "Failed to allocate %d for peak_vol", vol_size);
154150
return -ENOMEM;
155151
}
@@ -196,7 +192,6 @@ void volume_peak_free(struct vol_data *cd)
196192
/* clear mailbox */
197193
memset_s(&regs, sizeof(regs), 0, sizeof(regs));
198194
mailbox_sw_regs_write(cd->mailbox_offset, &regs, sizeof(regs));
199-
rfree(cd->peak_vol);
200195
}
201196

202197
static int volume_set_volume(struct processing_module *mod, const uint8_t *data, int data_size)

0 commit comments

Comments
 (0)