|
36 | 36 | #include "tcp.h" |
37 | 37 | #include "net_stats.h" |
38 | 38 |
|
| 39 | +#define ALLOC_TIMEOUT 500 |
| 40 | + |
39 | 41 | /* |
40 | 42 | * Each TCP connection needs to be tracked by net_context, so |
41 | 43 | * we need to allocate equal number of control structures here. |
@@ -315,7 +317,10 @@ static struct net_pkt *prepare_segment(struct net_tcp *tcp, |
315 | 317 | tail = pkt->frags; |
316 | 318 | pkt->frags = NULL; |
317 | 319 | } else { |
318 | | - pkt = net_pkt_get_tx(context, K_FOREVER); |
| 320 | + pkt = net_pkt_get_tx(context, ALLOC_TIMEOUT); |
| 321 | + if (!pkt) { |
| 322 | + return NULL; |
| 323 | + } |
319 | 324 | } |
320 | 325 |
|
321 | 326 | #if defined(CONFIG_NET_IPV4) |
@@ -347,7 +352,12 @@ static struct net_pkt *prepare_segment(struct net_tcp *tcp, |
347 | 352 | return NULL; |
348 | 353 | } |
349 | 354 |
|
350 | | - header = net_pkt_get_data(context, K_FOREVER); |
| 355 | + header = net_pkt_get_data(context, ALLOC_TIMEOUT); |
| 356 | + if (!header) { |
| 357 | + net_pkt_unref(pkt); |
| 358 | + return NULL; |
| 359 | + } |
| 360 | + |
351 | 361 | net_pkt_frag_add(pkt, header); |
352 | 362 |
|
353 | 363 | tcphdr = (struct net_tcp_hdr *)net_buf_add(header, NET_TCPH_LEN); |
@@ -740,10 +750,18 @@ int net_tcp_send_pkt(struct net_pkt *pkt) |
740 | 750 | } |
741 | 751 |
|
742 | 752 | if (pkt_in_slist) { |
743 | | - new_pkt = net_pkt_get_tx(ctx, K_FOREVER); |
| 753 | + new_pkt = net_pkt_get_tx(ctx, ALLOC_TIMEOUT); |
| 754 | + if (!new_pkt) { |
| 755 | + return -ENOMEM; |
| 756 | + } |
744 | 757 |
|
745 | 758 | memcpy(new_pkt, pkt, sizeof(struct net_pkt)); |
746 | | - new_pkt->frags = net_pkt_copy_all(pkt, 0, K_FOREVER); |
| 759 | + new_pkt->frags = net_pkt_copy_all(pkt, 0, |
| 760 | + ALLOC_TIMEOUT); |
| 761 | + if (!new_pkt->frags) { |
| 762 | + net_pkt_unref(new_pkt); |
| 763 | + return -ENOMEM; |
| 764 | + } |
747 | 765 |
|
748 | 766 | NET_DBG("Copied %zu bytes from %p to %p", |
749 | 767 | net_pkt_get_len(new_pkt), pkt, new_pkt); |
|
0 commit comments