Skip to content

Commit 6a37f32

Browse files
PetervdPerk-NXPkartben
authored andcommitted
drivers: input: sbus: Fix race and infinite loop
Under certain conditions report_lock could already be used by the irq before it was initialized, now we ensure we enable irq after report_lock is initialized. Furthermore in some conditions data->xfer_bytes could be equal SBUS_FRAME_LEN resulting in a infinite loop doing zero reads when fifo is still holding new bytes Signed-off-by: Peter van der Perk <peter.vanderperk@nxp.com>
1 parent 60d933e commit 6a37f32

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/input/input_sbus.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ static void sbus_uart_isr(const struct device *uart_dev, void *user_data)
247247
return;
248248
}
249249

250-
while (uart_irq_rx_ready(uart_dev) && data->xfer_bytes <= SBUS_FRAME_LEN) {
250+
while (uart_irq_rx_ready(uart_dev) && data->xfer_bytes < SBUS_FRAME_LEN) {
251251
if (data->in_sync) {
252252
if (data->xfer_bytes == 0) {
253253
data->last_rx_time = k_uptime_get_32();
@@ -324,10 +324,10 @@ static int input_sbus_init(const struct device *dev)
324324
return ret;
325325
}
326326

327-
uart_irq_rx_enable(config->uart_dev);
328-
329327
k_sem_init(&data->report_lock, 0, 1);
330328

329+
uart_irq_rx_enable(config->uart_dev);
330+
331331
k_thread_create(&data->thread, data->thread_stack,
332332
K_KERNEL_STACK_SIZEOF(data->thread_stack),
333333
(k_thread_entry_t)input_sbus_input_report_thread, (void *)dev, NULL, NULL,

0 commit comments

Comments
 (0)