net: buf: Include user data when cloning

net_buf_user_data() is supposed to copy any data, which includes the
user data.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
This commit is contained in:
Reto Schneider 2024-03-20 22:16:18 +01:00 committed by Maureen Helm
parent 2759a35a18
commit da676d2e01
2 changed files with 6 additions and 1 deletions

View file

@ -1536,7 +1536,7 @@ struct net_buf * __must_check net_buf_ref(struct net_buf *buf);
/**
* @brief Clone buffer
*
* Duplicate given buffer including any data and headers currently stored.
* Duplicate given buffer including any (user) data and headers currently stored.
*
* @param buf A valid pointer on a buffer
* @param timeout Affects the action taken should the pool be empty.

View file

@ -539,6 +539,11 @@ struct net_buf *net_buf_clone(struct net_buf *buf, k_timeout_t timeout)
net_buf_add_mem(clone, buf->data, buf->len);
}
/* user_data_size should be the same for buffers from the same pool */
__ASSERT(buf->user_data_size == clone->user_data_size, "Unexpected user data size");
memcpy(clone->user_data, buf->user_data, clone->user_data_size);
return clone;
}