Skip to content

Commit

Permalink
drivers: wifi: esp: Fix bug with net_pkt_unref in tx path
Browse files Browse the repository at this point in the history
The driver should only call net_pkt_unref on packets that get
successfully handled, ie where send/sendto return 0. If the packet
cannot be handled, net_context layer still owns the packet and should
take care or the unref.

Signed-off-by: Tobias Svehagen <[email protected]>
  • Loading branch information
tsvehagen authored and nashif committed Jul 2, 2020
1 parent ddb9f29 commit edcee97
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions drivers/wifi/esp/esp_offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,6 @@ static int _sock_send(struct esp_data *dev, struct esp_socket *sock)
NULL, 0U, false);
k_sem_give(&dev->cmd_handler_data.sem_tx_lock);

net_pkt_unref(sock->tx_pkt);
sock->tx_pkt = NULL;

return ret;
}

Expand All @@ -316,6 +313,9 @@ static void esp_send_work(struct k_work *work)
ret);
}

net_pkt_unref(sock->tx_pkt);
sock->tx_pkt = NULL;

if (sock->send_cb) {
sock->send_cb(sock->context, ret, sock->send_user_data);
}
Expand Down Expand Up @@ -392,11 +392,15 @@ static int esp_sendto(struct net_pkt *pkt,
ret = _sock_send(dev, sock);
k_sched_unlock();

if (ret < 0) {
if (ret == 0) {
net_pkt_unref(sock->tx_pkt);
} else {
LOG_ERR("Failed to send data: link %d, ret %d", sock->link_id,
ret);
}

sock->tx_pkt = NULL;

if (cb) {
cb(context, ret, user_data);
}
Expand Down

0 comments on commit edcee97

Please sign in to comment.