mirror of
https://github.com/apache/nuttx.git
synced 2025-12-11 04:47:47 +08:00
nuttx/can: report error and not EOF at the empty FIFO
The empty FIFO can happen only in two cases. Either there is some inconsistency that made rx_sem ready but buffer is empty (that might happen if multiple reads are blocked in parallel, or just due to the bug in the logic), or if close is used. Until now the 0 would be returned and thus EOF. The error is not EOF and actually it is still possible to read afterwards. Thus we for sure should not signal EOF for the first cause. The second cause for close matches the behavior that is expressed even on glibc for some file descriptors (the waiting read will commonly get error EINVAL there). We can't decide on the real cause of this situation and thus we always report EIO error and thus generic input/output error. Signed-off-by: Karel Kočí <kkoci@elektroline.cz>
This commit is contained in:
@@ -453,6 +453,9 @@ static ssize_t can_read(FAR struct file *filep, FAR char *buffer,
|
||||
|
||||
if (fifo->rx_head == fifo->rx_tail)
|
||||
{
|
||||
/* This happens either due to bug or on reader close. */
|
||||
|
||||
ret = -EIO;
|
||||
canerr("RX FIFO sem posted but FIFO is empty.\n");
|
||||
goto return_with_irqdisabled;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user