From d6cf0f5703331f4bd4538ed07e7c4fd558fcd207 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 28 Jun 2014 13:32:42 -0600 Subject: [PATCH] Fix another place where sem_tryalloc may be called from the interrupt level. Thanks Manuel --- net/iob/iob_alloc_qentry.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/net/iob/iob_alloc_qentry.c b/net/iob/iob_alloc_qentry.c index 8f425adb0d5..23bd8712ecb 100644 --- a/net/iob/iob_alloc_qentry.c +++ b/net/iob/iob_alloc_qentry.c @@ -105,7 +105,16 @@ static FAR struct iob_qentry_s *iob_tryalloc_qentry(void) */ g_iob_freeqlist = iobq->qe_flink; - DEBUGVERIFY(sem_trywait(&g_qentry_sem)); + + /* Take a semaphore count. Note that we cannot do this in + * in the orthodox way by calling sem_wait() or sem_trywait() + * because this function may be called from an interrupt + * handler. Fortunately we know at at least one free buffer + * so a simple decrement is all that is needed. + */ + + g_qentry_sem.semcount--; + DEBUGASSERT(g_qentry_sem.semcount >= 0); /* Put the I/O buffer in a known state */