diff mbox

[API-NEXT,2/5] linux-generic: pool: correct segment head/tail manipulation

Message ID 1461546799-18112-3-git-send-email-bill.fischofer@linaro.org
State New
Headers show

Commit Message

Bill Fischofer April 25, 2016, 1:13 a.m. UTC
Correct the implementation of several internal routines that perform
low-level segment manipulation in support of the extend/trunc APIs.

Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
---
 platform/linux-generic/odp_pool.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/platform/linux-generic/odp_pool.c b/platform/linux-generic/odp_pool.c
index eb12604..93c61ca 100644
--- a/platform/linux-generic/odp_pool.c
+++ b/platform/linux-generic/odp_pool.c
@@ -533,6 +533,7 @@  int seg_alloc_head(odp_buffer_hdr_t *buf_hdr,  int segcount)
 		buf_hdr->addr[i] = newsegs[i];
 
 	buf_hdr->segcount += segcount;
+	buf_hdr->size      = buf_hdr->segcount * pool->s.seg_size;
 	return 0;
 }
 
@@ -543,13 +544,14 @@  void seg_free_head(odp_buffer_hdr_t *buf_hdr, int segcount)
 	int s_cnt = buf_hdr->segcount;
 	int i;
 
-	for (i = 0; i < s_cnt; i++)
+	for (i = 0; i < segcount; i++)
 		ret_blk(&pool->s, buf_hdr->addr[i]);
 
 	for (i = 0; i < s_cnt - segcount; i++)
 		buf_hdr->addr[i] = buf_hdr->addr[i + segcount];
 
 	buf_hdr->segcount -= segcount;
+	buf_hdr->size      = buf_hdr->segcount * pool->s.seg_size;
 }
 
 int seg_alloc_tail(odp_buffer_hdr_t *buf_hdr,  int segcount)
@@ -569,6 +571,7 @@  int seg_alloc_tail(odp_buffer_hdr_t *buf_hdr,  int segcount)
 	}
 
 	buf_hdr->segcount += segcount;
+	buf_hdr->size      = buf_hdr->segcount * pool->s.seg_size;
 	return 0;
 }
 
@@ -579,10 +582,11 @@  void seg_free_tail(odp_buffer_hdr_t *buf_hdr, int segcount)
 	int s_cnt = buf_hdr->segcount;
 	int i;
 
-	for (i = s_cnt - 1; i > s_cnt - segcount; i--)
+	for (i = s_cnt - 1; i >= s_cnt - segcount; i--)
 		ret_blk(&pool->s, buf_hdr->addr[i]);
 
 	buf_hdr->segcount -= segcount;
+	buf_hdr->size      = buf_hdr->segcount * pool->s.seg_size;
 }
 
 odp_buffer_t buffer_alloc(odp_pool_t pool_hdl, size_t size)