net: nbuf: Initialize nbuf memory area after allocation

After commit 71c7c01819 about buf pool, we
started to get spurious behaviors on various places of the code on
different boards (a101, frdm...) BUT on qemu. Basically, outgoing ip/udp
packets were full of garbage. Or sometimes it was the abilitty to parse
incoming packet that was happening.

The difference between qemu and actualy boards is - afaik, at least, let
me know if I am wrong - that qemu provide initialized memory (full of
0s). Following this asssumption, this patch just reset the nbuf right
after it got allocated. And all started to work again as thought.

It's in fact a good thing to reset nbuf memory. Even before the above
commit: after being used more than once, a buffer would have ended up
with old content, and this could have been generating a bug. So let's be
on the safe side and always intialize nbuf content.

Change-Id: I50647d9e9b82a4ed340a5ceb0d69409b0194dddd
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2016-12-16 18:38:06 +01:00
parent 7a19370f84
commit 675277e28d

View file

@ -325,6 +325,8 @@ static struct net_buf *net_nbuf_get_reserve(enum net_nbuf_type type,
case NET_NBUF_RX:
buf = net_buf_alloc(&rx_buffers, K_FOREVER);
memset(net_buf_user_data(buf), 0, sizeof(struct net_nbuf));
NET_ASSERT_INFO(buf->ref, "RX buf %p ref %d", buf, buf->ref);
dec_free_rx_bufs(buf);
@ -333,6 +335,8 @@ static struct net_buf *net_nbuf_get_reserve(enum net_nbuf_type type,
case NET_NBUF_TX:
buf = net_buf_alloc(&tx_buffers, K_FOREVER);
memset(net_buf_user_data(buf), 0, sizeof(struct net_nbuf));
NET_ASSERT_INFO(buf->ref, "TX buf %p ref %d", buf, buf->ref);
dec_free_tx_bufs(buf);
@ -357,17 +361,6 @@ static struct net_buf *net_nbuf_get_reserve(enum net_nbuf_type type,
NET_BUF_CHECK_IF_NOT_IN_USE(buf, buf->ref + 1);
if (type != NET_NBUF_DATA) {
net_nbuf_set_context(buf, NULL);
net_nbuf_ll_dst(buf)->addr = NULL;
net_nbuf_ll_src(buf)->addr = NULL;
/* Let's make sure ll_reserve is not set
* from a previous usage of the buffer.
*/
net_nbuf_set_ll_reserve(buf, 0);
}
NET_DBG("%s [%d] buf %p reserve %u ref %d (%s():%d)",
type2str(type), get_frees(type),
buf, reserve_head, buf->ref, caller, line);