From 247bc10c264aa0287dc58911bb4f34a742d9d784 Mon Sep 17 00:00:00 2001 From: Oleg Evseev Date: Sun, 5 Jul 2020 19:04:47 +0300 Subject: [PATCH] drivers/can: fix wrong use of nxsem_getvalue Bug caused increase of fifo->rx_sem with each received msg until finally after 32767 messages get into DEBUGASSERT(sem->semcountrx_tail = nexttail; - /* The increment the counting semaphore. The maximum value should + sval = 0; + if (nxsem_get_value(&fifo->rx_sem, &sval) < 0) + { + DEBUGASSERT(false); +#ifdef CONFIG_CAN_ERRORS + /* Report unspecified error */ + + dev->cd_error |= CAN_ERROR5_UNSPEC; +#endif + return -EINVAL; + } + + /* Increment the counting semaphore. The maximum value should * be CONFIG_CAN_FIFOSIZE -- one possible count for each allocated * message buffer. */ - sval = 0; - if (nxsem_get_value(&fifo->rx_sem, &sval) <= 0) + if (sval < 0) { can_givesem(&fifo->rx_sem); }