Skip to content

Commit cfe91b8

Browse files
MaochenWang1kartben
authored andcommitted
net: ip: net_pkt: only reserve L2 header for TX case
Only reserve L2 header for TX case when allocating net buffer, as for RX case, all the received headers are already in linear buffer when the driver receives the data, and reserve extra L2 header for RX case may exceed the default buffer size. Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
1 parent e4c5bb9 commit cfe91b8

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

subsys/net/ip/net_pkt.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,16 @@ int net_pkt_alloc_buffer_with_reserve(struct net_pkt *pkt,
13371337
return 0;
13381338
}
13391339

1340+
static bool is_pkt_tx(struct net_pkt *pkt)
1341+
{
1342+
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
1343+
if ((pkt->context != NULL) && (get_tx_slab(pkt->context) != NULL)) {
1344+
return pkt->slab == get_tx_slab(pkt->context);
1345+
}
1346+
#endif
1347+
return pkt->slab == &tx_pkts;
1348+
}
1349+
13401350
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG
13411351
int net_pkt_alloc_buffer_debug(struct net_pkt *pkt,
13421352
size_t size,
@@ -1364,7 +1374,7 @@ int net_pkt_alloc_buffer(struct net_pkt *pkt,
13641374

13651375
iface = net_pkt_iface(pkt);
13661376

1367-
if (iface != NULL && net_if_l2(iface)->alloc != NULL) {
1377+
if (iface != NULL && is_pkt_tx(pkt) && net_if_l2(iface)->alloc != NULL) {
13681378
ret = net_if_l2(iface)->alloc(iface, pkt, size, proto, timeout);
13691379
if (ret != -ENOTSUP) {
13701380
return ret;

0 commit comments

Comments
 (0)