From 4c9b316e6b318cf8332cf9d6a53eb77a100b3ef4 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 27 Apr 2017 00:10:52 +0800 Subject: [PATCH] pbuf: Fix allocate zero length pbuf Current code fails to allocate zero length pbuf (e.g. for PBUF_RAW PBUF_POOL), fix it. Fixes: eb269e61b5d3 ("First step to clean up pbuf implementation: add pbuf_alloc_reference() to allocate pbufs referencing external payload; move member initialization to common function; simplify PBUF_POOL chain allocator") Signed-off-by: Axel Lin Signed-off-by: goldsimon --- src/core/pbuf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/pbuf.c b/src/core/pbuf.c index 8e9bcd06..2ee5efcb 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -305,7 +305,7 @@ pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type) p = NULL; last = NULL; rem_len = length; - while (rem_len > 0) { + do { q = (struct pbuf *)memp_malloc(MEMP_PBUF_POOL); if (q == NULL) { PBUF_POOL_IS_EMPTY(); @@ -332,7 +332,7 @@ pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type) last = q; rem_len -= q->len; offset = 0; - } + } while (rem_len > 0); break; } case PBUF_RAM: