net: buf: Add net_buf_reset

This adds net_buf_reset which can be used to reset the state of a buffer.

Change-Id: I4b7c89dfd1a23a2ec8dfa3c99d5b02b9bcbceef3
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2017-04-18 14:43:04 +03:00 committed by Johan Hedberg
commit 1885edf424
2 changed files with 19 additions and 2 deletions

View file

@ -598,6 +598,15 @@ static inline void net_buf_destroy(struct net_buf *buf)
k_lifo_put(&buf->pool->free, buf);
}
/**
* @brief Reset buffer
*
* Reset buffer data and flags so it can be reused for other purposes.
*
* @param buf Buffer to reset.
*/
void net_buf_reset(struct net_buf *buf);
/**
* @brief Initialize buffer with the given headroom.
*

View file

@ -64,6 +64,15 @@ static inline struct net_buf *pool_get_uninit(struct net_buf_pool *pool,
return buf;
}
void net_buf_reset(struct net_buf *buf)
{
NET_BUF_ASSERT(buf->flags == 0);
NET_BUF_ASSERT(buf->frags == NULL);
buf->len = 0;
buf->data = buf->__buf;
}
#if defined(CONFIG_NET_BUF_LOG)
struct net_buf *net_buf_alloc_debug(struct net_buf_pool *pool, int32_t timeout,
const char *func, int line)
@ -148,10 +157,9 @@ success:
NET_BUF_DBG("allocated buf %p", buf);
buf->ref = 1;
buf->len = 0;
buf->data = buf->__buf;
buf->flags = 0;
buf->frags = NULL;
net_buf_reset(buf);
#if defined(CONFIG_NET_BUF_POOL_USAGE)
buf->pool->avail_count--;