Description
Introduction
We can initialize a net_buf's user_data
member with a known pattern.
Just like the CONFIG_INIT_STACKS
option.
Problem description
It is not clear who owns user_data
.
Is it the module that allocates it, the API that consumes it, something else?
With a known (non-null) initialized value, it will be possible to perform some checks and avoid head-scratching debug sessions. We've had some of those sessions in Bluetooth/L2CAP.
Proposed change
Call memset(buf->user_data, 0xAA, buf->user_data_size)
in net_buf_alloc()
right before returning buf
.
Can be locked behind a kconfig, just like the stacks option.
Concerns and Unresolved Questions
Other users (maybe out of tree too) could break due to NULL
checks on user_data not working anymore.
E.g. the pattern of casting cb
from user_data
and having a block like this one:
if (cb) {
cb(some_param);
}
Alternatives
- APIs that consume
net_buf
s enforce clearing by the application
Metadata
Metadata
Assignees
Labels
Type
Projects
Status