Skip to content

Commit 503df3e

Browse files
ttwardscfriedt
authored andcommitted
drivers: dma: stm32: add null callback checking
Fix the STM32 DMA driver did not check if the optional dma_callback was set in dma_stm32_configure(). This could lead to a hard fault when an interrupt occurs and the callback is NULL, even though the API allows the callback to be omitted. Fixes #97454 Signed-off-by: Wenxi Xu <[email protected]>
1 parent 2e7ad10 commit 503df3e

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

drivers/dma/dma_stm32.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ static void dma_stm32_irq_handler(const struct device *dev, uint32_t id)
117117
if (!stream->hal_override) {
118118
dma_stm32_clear_ht(dma, id);
119119
}
120-
stream->dma_callback(dev, stream->user_data, callback_arg, DMA_STATUS_BLOCK);
120+
if (stream->dma_callback != NULL) {
121+
stream->dma_callback(dev, stream->user_data, callback_arg,
122+
DMA_STATUS_BLOCK);
123+
}
121124
} else if (stm32_dma_is_tc_irq_active(dma, id)) {
122125
/* Circular buffer never stops receiving as long as peripheral is enabled */
123126
if (!stream->cyclic) {
@@ -127,16 +130,20 @@ static void dma_stm32_irq_handler(const struct device *dev, uint32_t id)
127130
if (!stream->hal_override) {
128131
dma_stm32_clear_tc(dma, id);
129132
}
130-
stream->dma_callback(dev, stream->user_data, callback_arg, DMA_STATUS_COMPLETE);
133+
if (stream->dma_callback != NULL) {
134+
stream->dma_callback(dev, stream->user_data, callback_arg,
135+
DMA_STATUS_COMPLETE);
136+
}
131137
} else if (stm32_dma_is_unexpected_irq_happened(dma, id)) {
132138
/* Let HAL DMA handle flags on its own */
133139
if (!stream->hal_override) {
134140
LOG_ERR("Unexpected irq happened.");
135141
stm32_dma_dump_stream_irq(dma, id);
136142
stm32_dma_clear_stream_irq(dma, id);
137143
}
138-
stream->dma_callback(dev, stream->user_data,
139-
callback_arg, -EIO);
144+
if (stream->dma_callback != NULL) {
145+
stream->dma_callback(dev, stream->user_data, callback_arg, -EIO);
146+
}
140147
} else {
141148
/* Let HAL DMA handle flags on its own */
142149
if (!stream->hal_override) {
@@ -145,8 +152,9 @@ static void dma_stm32_irq_handler(const struct device *dev, uint32_t id)
145152
dma_stm32_dump_stream_irq(dev, id);
146153
dma_stm32_clear_stream_irq(dev, id);
147154
}
148-
stream->dma_callback(dev, stream->user_data,
149-
callback_arg, -EIO);
155+
if (stream->dma_callback != NULL) {
156+
stream->dma_callback(dev, stream->user_data, callback_arg, -EIO);
157+
}
150158
}
151159
}
152160

0 commit comments

Comments
 (0)