summaryrefslogtreecommitdiff
path: root/tmk_core/protocol/chibios
diff options
context:
space:
mode:
authorQMK Bot <hello@qmk.fm>2021-04-10 15:04:12 +0000
committerQMK Bot <hello@qmk.fm>2021-04-10 15:04:12 +0000
commitd5a8431af4fa3f64c457eca467ce3e969a08292b (patch)
tree3832a5c2b0cb6cbd89782e62e13285e10d3f1ac0 /tmk_core/protocol/chibios
parent2e2dd3113bb837de3f217dceaf4a0715cf7b3c82 (diff)
parent7d953332e0d7c0394c607156bf4099881bdf3f43 (diff)
downloadqmk_firmware-d5a8431af4fa3f64c457eca467ce3e969a08292b.tar.gz
qmk_firmware-d5a8431af4fa3f64c457eca467ce3e969a08292b.zip
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'tmk_core/protocol/chibios')
-rw-r--r--tmk_core/protocol/chibios/usb_driver.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/tmk_core/protocol/chibios/usb_driver.c b/tmk_core/protocol/chibios/usb_driver.c
index cc0ce7600f..eb72f8ff6d 100644
--- a/tmk_core/protocol/chibios/usb_driver.c
+++ b/tmk_core/protocol/chibios/usb_driver.c
@@ -80,7 +80,19 @@ static bool qmkusb_start_receive(QMKUSBDriver *qmkusbp) {
* Interface implementation.
*/
-static size_t _write(void *ip, const uint8_t *bp, size_t n) { return obqWriteTimeout(&((QMKUSBDriver *)ip)->obqueue, bp, n, TIME_INFINITE); }
+static size_t _write(void *ip, const uint8_t *bp, size_t n) {
+ output_buffers_queue_t *obqueue = &((QMKUSBDriver *)ip)->obqueue;
+ chSysLock();
+ const bool full = obqIsFullI(obqueue);
+ chSysUnlock();
+ if (full || bqIsSuspendedX(obqueue)) {
+ /* Discard any writes while the queue is suspended or full, i.e. the hidraw
+ interface is not open. If we tried to send with an infinite timeout, we
+ would deadlock the keyboard otherwise. */
+ return -1;
+ }
+ return obqWriteTimeout(obqueue, bp, n, TIME_INFINITE);
+}
static size_t _read(void *ip, uint8_t *bp, size_t n) { return ibqReadTimeout(&((QMKUSBDriver *)ip)->ibqueue, bp, n, TIME_INFINITE); }