Skip to content

Commit 029f542

Browse files
JordanYateskartben
authored andcommitted
net: l2: ethernet: arp: unref pkt if queue add fails
Make it clearer that the `net_buf_ref` is for `k_queue_unique_append`, and reverse the reference if the queue add fails. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent 3546020 commit 029f542

File tree

1 file changed

+6
-2
lines changed
  • subsys/net/l2/ethernet

1 file changed

+6
-2
lines changed

subsys/net/l2/ethernet/arp.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,19 @@ int net_arp_prepare(struct net_pkt *pkt,
423423
/* There is a pending ARP request already, check if this packet is already
424424
* in the pending list and if so, resend the request, otherwise just
425425
* append the packet to the request fifo list.
426+
* Ensure the packet reference is incremented to account for the queue
427+
* holding the reference.
426428
*/
427-
if (k_queue_unique_append(&entry->pending_queue._queue,
428-
net_pkt_ref(pkt))) {
429+
pkt = net_pkt_ref(pkt);
430+
if (k_queue_unique_append(&entry->pending_queue._queue, pkt)) {
429431
NET_DBG("Pending ARP request for %s, queuing pkt %p",
430432
net_sprint_ipv4_addr(addr), pkt);
431433
k_mutex_unlock(&arp_mutex);
432434
return NET_ARP_PKT_QUEUED;
433435
}
434436

437+
/* Queueing the packet failed, undo the net_pkt_ref */
438+
net_pkt_unref(pkt);
435439
entry = NULL;
436440
}
437441

0 commit comments

Comments
 (0)