Skip to content

Commit d0a5669

Browse files
Jordan Yatesjhedberg
authored andcommitted
net: buf: document fragment limitations
Document limitations on the FIFO queuing functions when fragments are used. Namely that the `get` functions are not thread-safe when fragments are present. This is due to multiple independent calls to `k_fifo_get/sys_slist_get`. A second thread can interrupt the retrieval before all fragments have been removed. The second thread can then read from the FIFO, obtaining the trailing fragments as a 'new' `net_buf`. The first thread will then either assert or pull in the next `net_buf` on the queue as part of the first `net_buf`. Fixes #28355 Signed-off-by: Jordan Yates <[email protected]>
1 parent 6ab4886 commit d0a5669

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

include/net/buf.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,9 @@ struct net_buf *net_buf_alloc_with_data(struct net_buf_pool *pool,
11311131
/**
11321132
* @brief Get a buffer from a FIFO.
11331133
*
1134+
* This function is NOT thread-safe if the buffers in the FIFO contain
1135+
* fragments.
1136+
*
11341137
* @param fifo Which FIFO to take the buffer from.
11351138
* @param timeout Affects the action taken should the FIFO be empty.
11361139
* If K_NO_WAIT, then return immediately. If K_FOREVER, then wait as
@@ -1197,7 +1200,8 @@ void net_buf_slist_put(sys_slist_t *list, struct net_buf *buf);
11971200
* @brief Get a buffer from a list.
11981201
*
11991202
* If the buffer had any fragments, these will automatically be recovered from
1200-
* the list as well and be placed to the buffer's fragment list.
1203+
* the list as well and be placed to the buffer's fragment list. This function
1204+
* is NOT thread-safe when recovering fragments.
12011205
*
12021206
* @param list Which list to take the buffer from.
12031207
*

0 commit comments

Comments
 (0)