diff --git a/mm/iob/iob_alloc_qentry.c b/mm/iob/iob_alloc_qentry.c index e81d63327dc..b9d23db5463 100644 --- a/mm/iob/iob_alloc_qentry.c +++ b/mm/iob/iob_alloc_qentry.c @@ -200,7 +200,7 @@ FAR struct iob_qentry_s *iob_alloc_qentry(void) { /* Were we called from the interrupt level? */ - if (up_interrupt_context()) + if (up_interrupt_context() || sched_idletask()) { /* Yes, then try to allocate an I/O buffer without waiting */ diff --git a/mm/iob/iob_clone.c b/mm/iob/iob_clone.c index cfa8150f102..529de70bc6a 100644 --- a/mm/iob/iob_clone.c +++ b/mm/iob/iob_clone.c @@ -1,5 +1,5 @@ /**************************************************************************** - * mm/iob/iob_copy.c + * mm/iob/iob_clone.c * * Copyright (C) 2014, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt diff --git a/mm/iob/iob_concat.c b/mm/iob/iob_concat.c index 4829c3b0724..5435fe66395 100644 --- a/mm/iob/iob_concat.c +++ b/mm/iob/iob_concat.c @@ -59,6 +59,11 @@ void iob_concat(FAR struct iob_s *iob1, FAR struct iob_s *iob2) { + /* Combine the total packet size */ + + iob1->io_pktlen += iob2->io_pktlen; + iob2->io_pktlen = 0; + /* Find the last buffer in the iob1 buffer chain */ while (iob1->io_flink) @@ -69,8 +74,4 @@ void iob_concat(FAR struct iob_s *iob1, FAR struct iob_s *iob2) /* Then connect iob2 buffer chain to the end of the iob1 chain */ iob1->io_flink = iob2; - - /* Combine the total packet size */ - - iob1->io_pktlen += iob2->io_pktlen; } diff --git a/mm/iob/iob_contig.c b/mm/iob/iob_contig.c index ee71ec05fc4..2e77127ed5e 100644 --- a/mm/iob/iob_contig.c +++ b/mm/iob/iob_contig.c @@ -113,7 +113,7 @@ int iob_contig(FAR struct iob_s *iob, unsigned int len) /* Get the next I/O buffer in the chain */ next = iob->io_flink; - DEBUGASSERT(next != NULL && next->io_len > 0); + DEBUGASSERT(next != NULL); /* Copy what we need or what we can from the next buffer */ diff --git a/mm/iob/iob_free.c b/mm/iob/iob_free.c index c92a7465685..57d858ac856 100644 --- a/mm/iob/iob_free.c +++ b/mm/iob/iob_free.c @@ -115,12 +115,11 @@ FAR struct iob_s *iob_free(FAR struct iob_s *iob) } else { - /* This can only happen if the next entry is last entry in the - * chain... and if it is empty + /* This can only happen if the free entry isn't first entry in the + * chain... */ next->io_pktlen = 0; - DEBUGASSERT(next->io_len == 0 && next->io_flink == NULL); } iobinfo("next=%p io_pktlen=%u io_len=%u\n", diff --git a/mm/iob/iob_free_qentry.c b/mm/iob/iob_free_qentry.c index 559753ea984..e08daeeb943 100644 --- a/mm/iob/iob_free_qentry.c +++ b/mm/iob/iob_free_qentry.c @@ -76,13 +76,13 @@ FAR struct iob_qentry_s *iob_free_qentry(FAR struct iob_qentry_s *iobq) flags = enter_critical_section(); - /* Which list? If there is a task waiting for an IOB, then put - * the IOB on either the free list or on the committed list where + /* Which list? If there is a task waiting for an IOB chain, then put + * the IOB chain on either the free list or on the committed list where * it is reserved for that allocation (and not available to - * iob_tryalloc()). + * iob_tryalloc_qentry()). */ - if (g_iob_sem.semcount < 0) + if (g_qentry_sem.semcount < 0) { iobq->qe_flink = g_iob_qcommitted; g_iob_qcommitted = iobq; diff --git a/mm/iob/iob_navail.c b/mm/iob/iob_navail.c index 2c3b157083f..75926131342 100644 --- a/mm/iob/iob_navail.c +++ b/mm/iob/iob_navail.c @@ -77,12 +77,12 @@ int iob_navail(bool throttled) if (throttled) { ret -= CONFIG_IOB_THROTTLE; - if (ret < 0) - { - ret = 0; - } } #endif + if (ret < 0) + { + ret = 0; + } } #else @@ -112,6 +112,10 @@ int iob_qentry_navail(void) if (ret >= 0) { ret = navail; + if (ret < 0) + { + ret = 0; + } } #else diff --git a/mm/iob/iob_pack.c b/mm/iob/iob_pack.c index 62799b2238b..011652c99d5 100644 --- a/mm/iob/iob_pack.c +++ b/mm/iob/iob_pack.c @@ -45,14 +45,6 @@ #include "iob.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifndef MIN -# define MIN(a,b) ((a) < (b) ? (a) : (b)) -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -79,6 +71,10 @@ FAR struct iob_s *iob_pack(FAR struct iob_s *iob) while (iob->io_len <= 0) { iob = iob_free(iob); + if (iob == NULL) + { + return NULL; + } } /* Now remember the head of the chain (for the return value) */