acassis commented on code in PR #16466:
URL: https://github.com/apache/nuttx/pull/16466#discussion_r2124055054
##########
drivers/serial/serial.c:
##########
@@ -248,9 +249,26 @@ static int uart_putxmitchar(FAR uart_dev_t *dev, int ch,
bool oktoblock)
nexthead = 0;
}
- /* Check if the TX buffer is full */
+ /* Check if the TX buffer is full
+ *
+ * This method is currently called from uart_readv and uart_writev.
+ * The latter calls it after a call to uart_disabletxint, meaning
+ * transmit interrupt cannot happen. The former, however, runs
+ * with interrupt handling enabled. Interrupt handler can therefore
+ * execute in the middle of loading xmit.tail. If the load isn't
+ * atomic (8bit MCUs), it must run with interrupts disabled because
Review Comment:
This is his reply:
"limiting the buffer size under 256 bytes would work too but there are a
lot of default configurations that use 256 bytes or more so I think
doing it like that may break things for people.
Another option is sort of middle-ground - keep the
CONFIG_ARCH_LD_16BIT_NOT_ATOMIC configuration option and determine
maximum buffer size and type for head/tail variables based on if it is
set. If set, the type changes to uint8_t and maximum buffer size will be
restricted to (let's say) 128.
This way, the risk of introducing some bug would be lower as well too.
However, I expect this is not the only case where such a race condition
exists for 8bit architectures. For example, the circbuf library uses
size_t for head and tail variables so it's likely that a similar change
is needed there as well."
So, let's include it, since it could be used in other areas for 8-bit MCUs
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]