diff --git a/include/net/buf.h b/include/net/buf.h index 442ebce399da44..778a42600717af 100644 --- a/include/net/buf.h +++ b/include/net/buf.h @@ -889,15 +889,6 @@ static inline void net_buf_simple_restore(struct net_buf_simple *buf, buf->len = state->len; } -/** - * Flag indicating that the buffer has associated fragments. Only used - * internally by the buffer handling code while the buffer is inside a - * FIFO, meaning this never needs to be explicitly set or unset by the - * net_buf API user. As long as the buffer is outside of a FIFO, i.e. - * in practice always for the user for this API, the buf->frags pointer - * should be used instead. - */ -#define NET_BUF_FRAGS BIT(0) /** * Flag indicating that the buffer's associated data pointer, points to * externally allocated memory. Therefore once ref goes down to zero, the @@ -907,7 +898,7 @@ static inline void net_buf_simple_restore(struct net_buf_simple *buf, * Reference count mechanism however will behave the same way, and ref * count going to 0 will free the net_buf but no the data pointer in it. */ -#define NET_BUF_EXTERNAL_DATA BIT(1) +#define NET_BUF_EXTERNAL_DATA BIT(0) /** * @brief Network buffer representation. @@ -917,13 +908,11 @@ static inline void net_buf_simple_restore(struct net_buf_simple *buf, * using the net_buf_alloc() API. */ struct net_buf { - union { - /** Allow placing the buffer into sys_slist_t */ - sys_snode_t node; + /** Allow placing the buffer into sys_slist_t */ + sys_snode_t node; - /** Fragments associated with this buffer. */ - struct net_buf *frags; - }; + /** Fragments associated with this buffer. */ + struct net_buf *frags; /** Reference count. */ uint8_t ref; diff --git a/subsys/net/buf.c b/subsys/net/buf.c index b7401ba53d5563..d65015c35fcfc0 100644 --- a/subsys/net/buf.c +++ b/subsys/net/buf.c @@ -405,7 +405,7 @@ struct net_buf *net_buf_get_debug(struct k_fifo *fifo, k_timeout_t timeout, struct net_buf *net_buf_get(struct k_fifo *fifo, k_timeout_t timeout) #endif { - struct net_buf *buf, *frag; + struct net_buf *buf; NET_BUF_DBG("%s():%d: fifo %p", func, line, fifo); @@ -416,18 +416,6 @@ struct net_buf *net_buf_get(struct k_fifo *fifo, k_timeout_t timeout) NET_BUF_DBG("%s():%d: buf %p fifo %p", func, line, buf, fifo); - /* Get any fragments belonging to this buffer */ - for (frag = buf; (frag->flags & NET_BUF_FRAGS); frag = frag->frags) { - frag->frags = k_fifo_get(fifo, K_NO_WAIT); - __ASSERT_NO_MSG(frag->frags); - - /* The fragments flag is only for FIFO-internal usage */ - frag->flags &= ~NET_BUF_FRAGS; - } - - /* Mark the end of the fragment list */ - frag->frags = NULL; - return buf; } @@ -451,24 +439,19 @@ void net_buf_simple_reserve(struct net_buf_simple *buf, size_t reserve) void net_buf_slist_put(sys_slist_t *list, struct net_buf *buf) { - struct net_buf *tail; unsigned int key; __ASSERT_NO_MSG(list); __ASSERT_NO_MSG(buf); - for (tail = buf; tail->frags; tail = tail->frags) { - tail->flags |= NET_BUF_FRAGS; - } - key = irq_lock(); - sys_slist_append_list(list, &buf->node, &tail->node); + sys_slist_append(list, &buf->node); irq_unlock(key); } struct net_buf *net_buf_slist_get(sys_slist_t *list) { - struct net_buf *buf, *frag; + struct net_buf *buf; unsigned int key; __ASSERT_NO_MSG(list); @@ -477,40 +460,15 @@ struct net_buf *net_buf_slist_get(sys_slist_t *list) buf = (void *)sys_slist_get(list); irq_unlock(key); - if (!buf) { - return NULL; - } - - /* Get any fragments belonging to this buffer */ - for (frag = buf; (frag->flags & NET_BUF_FRAGS); frag = frag->frags) { - key = irq_lock(); - frag->frags = (void *)sys_slist_get(list); - irq_unlock(key); - - __ASSERT_NO_MSG(frag->frags); - - /* The fragments flag is only for list-internal usage */ - frag->flags &= ~NET_BUF_FRAGS; - } - - /* Mark the end of the fragment list */ - frag->frags = NULL; - return buf; } void net_buf_put(struct k_fifo *fifo, struct net_buf *buf) { - struct net_buf *tail; - __ASSERT_NO_MSG(fifo); __ASSERT_NO_MSG(buf); - for (tail = buf; tail->frags; tail = tail->frags) { - tail->flags |= NET_BUF_FRAGS; - } - - k_fifo_put_list(fifo, buf, tail); + k_fifo_put(fifo, buf); } #if defined(CONFIG_NET_BUF_LOG)