lukegluke opened a new issue #1354: URL: https://github.com/apache/incubator-nuttx/issues/1354
nxsem_get_value is absolutely wrongly used in can.c https://github.com/apache/incubator-nuttx/blob/57bc329aace6d816b9a51a368665ea4c7116a9c6/drivers/can/can.c#L1346 it should be `if (nxsem_get_value(&fifo->rx_sem, &sval) == 0 && sval <= 0)` or even better to check first one separately with debug assert and optional error output, if CONFIG_CAN_ERRORS defined, like in other drivers. This bug leads to irreversible increase of fifo->rx_sem with each received msg until finally get into `DEBUGASSERT(sem->semcount<SEM_VALUE_MAX);` in sem_post.c. So in fact without debug can driver get broken after 32767 messages - stopping receiving anything at all (while tx is still working). I wonder why nobody do not encountered this issue yet? I'm not good in kernel stuff, as for me, while digging this it was hard to understand description for nxsem_get_value [here ](https://github.com/apache/incubator-nuttx/blob/57bc329aace6d816b9a51a368665ea4c7116a9c6/libs/libc/semaphore/sem_getvalue.c#L62) ``` If 'sem' is locked, the value return by nxsem_get_value() will either be zero or a negative number whose absolute value represents the number of tasks waiting for the semaphore. ``` It can confuse if not take a look on the code. I would suggest to correct "_the value return by nxsem_get_value()_" to "_the value 'sval' updated by nxsem_get_value()_" **Additionally could somebody please explain why can_read() and can_write() enter_critical_section before accessing the received FIFO, but can_poll doesn't? Is it another bug and can_poll must be wrapped with critical section?** Also probably it's better to recheck if nxsem_get_value used right in other places? p.s. by the way there still one naming inconsistent https://github.com/apache/incubator-nuttx/blob/0e425584b8cd4e28705c6f0cf0da98be067f9ad3/arch/arm/src/stm32h7/stm32_spi_slave.c#L1553 ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org