Skip to content

Commit 0f03221

Browse files
jfischer-nofabiobaltieri
authored andcommitted
usb: device: avoid starving other threads in CDC ACM UART fifo_fill
The check for the device being configured or suspended in the fifo_fill implementation can starve other threads, because the early return does not change the state of the TX path, and fifo_fill is called again from the callback loop. The ringbuffer that emulates the TX FIFO can be filled and marked ready as long as the space is available. Signed-off-by: Johann Fischer <[email protected]>
1 parent fe4d8a6 commit 0f03221

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

subsys/usb/device/class/cdc_acm.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -526,19 +526,18 @@ static int cdc_acm_fifo_fill(const struct device *dev,
526526
LOG_DBG("dev_data %p len %d tx_ringbuf space %u",
527527
dev_data, len, ring_buf_space_get(dev_data->tx_ringbuf));
528528

529-
if (!dev_data->configured || dev_data->suspended) {
530-
LOG_INF("Device suspended or not configured");
531-
return 0;
532-
}
533-
534-
dev_data->tx_ready = false;
535-
536529
lock = irq_lock();
537530
wrote = ring_buf_put(dev_data->tx_ringbuf, tx_data, len);
538531
irq_unlock(lock);
539532
LOG_DBG("Wrote %zu of %d bytes to TX ringbuffer", wrote, len);
540533

541-
k_work_schedule_for_queue(&USB_WORK_Q, &dev_data->tx_work, K_NO_WAIT);
534+
if (!ring_buf_space_get(dev_data->tx_ringbuf)) {
535+
dev_data->tx_ready = false;
536+
}
537+
538+
if (wrote) {
539+
k_work_schedule_for_queue(&USB_WORK_Q, &dev_data->tx_work, K_NO_WAIT);
540+
}
542541

543542
/* Return written to ringbuf data len */
544543
return wrote;

0 commit comments

Comments
 (0)