Skip to content

Commit 4cc15d7

Browse files
lowlandernashif
authored andcommitted
drivers: dmamux: Remove need for kmalloc
Use file static variable for the channel config data, instead of a dynamic array allocated with kmalloc. Signed-off-by: Erwin Rol <[email protected]>
1 parent 8c4c72d commit 4cc15d7

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

drivers/dma/dmamux_stm32.c

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,6 @@ static int dmamux_stm32_init(const struct device *dev)
172172
return -EIO;
173173
}
174174

175-
int size_stream =
176-
sizeof(struct dmamux_stm32_channel) * config->channel_nb;
177-
data->mux_channels = k_malloc(size_stream);
178-
if (!data->mux_channels) {
179-
LOG_ERR("HEAP_MEM_POOL_SIZE is too small");
180-
return -ENOMEM;
181-
}
182175
for (int i = 0; i < config->channel_nb; i++) {
183176
/*
184177
* associates the dmamux channel
@@ -209,26 +202,29 @@ static const struct dma_driver_api dma_funcs = {
209202
.get_status = dmamux_stm32_get_status,
210203
};
211204

212-
#define DMAMUX_INIT(index) \
213-
\
214-
const struct dmamux_stm32_config dmamux_stm32_config_##index = {\
215-
.pclken = { .bus = DT_INST_CLOCKS_CELL(index, bus), \
216-
.enr = DT_INST_CLOCKS_CELL(index, bits) }, \
217-
.base = DT_INST_REG_ADDR(index), \
218-
.channel_nb = DT_INST_PROP(index, dma_channels), \
219-
.gen_nb = DT_INST_PROP(index, dma_generators), \
220-
.req_nb = DT_INST_PROP(index, dma_requests), \
221-
}; \
222-
\
223-
static struct dmamux_stm32_data dmamux_stm32_data_##index = { \
224-
.mux_channels = NULL, \
225-
}; \
226-
\
227-
DEVICE_DT_INST_DEFINE(index, \
228-
&dmamux_stm32_init, \
229-
device_pm_control_nop, \
205+
#define DMAMUX_INIT(index) \
206+
\
207+
const struct dmamux_stm32_config dmamux_stm32_config_##index = { \
208+
.pclken = { .bus = DT_INST_CLOCKS_CELL(index, bus), \
209+
.enr = DT_INST_CLOCKS_CELL(index, bits) }, \
210+
.base = DT_INST_REG_ADDR(index), \
211+
.channel_nb = DT_INST_PROP(index, dma_channels), \
212+
.gen_nb = DT_INST_PROP(index, dma_generators), \
213+
.req_nb = DT_INST_PROP(index, dma_requests), \
214+
}; \
215+
\
216+
static struct dmamux_stm32_channel \
217+
dmamux_stm32_channels_##index[DT_INST_PROP(index, dma_channels)]; \
218+
\
219+
static struct dmamux_stm32_data dmamux_stm32_data_##index = { \
220+
.mux_channels = dmamux_stm32_channels_##index, \
221+
}; \
222+
\
223+
DEVICE_DT_INST_DEFINE(index, \
224+
&dmamux_stm32_init, \
225+
device_pm_control_nop, \
230226
&dmamux_stm32_data_##index, &dmamux_stm32_config_##index,\
231-
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,\
227+
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
232228
&dma_funcs);
233229

234230
DT_INST_FOREACH_STATUS_OKAY(DMAMUX_INIT)

0 commit comments

Comments
 (0)