Skip to content

wifi: nrf_wifi: net_if: allocate memory before mutex #88783

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions drivers/wifi/nrf_wifi/src/net_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ int nrf_wifi_if_send(const struct device *dev,
struct nrf_wifi_sys_fmac_dev_ctx *sys_dev_ctx = NULL;
struct rpu_host_stats *host_stats = NULL;
void *nbuf = NULL;
bool locked = false;

if (!dev || !pkt) {
LOG_ERR("%s: vif_ctx_zep is NULL", __func__);
Expand All @@ -371,24 +372,27 @@ int nrf_wifi_if_send(const struct device *dev,
goto out;
}

/* Allocate packet before locking mutex (blocks until allocation success) */
nbuf = net_pkt_to_nbuf(pkt);

ret = k_mutex_lock(&vif_ctx_zep->vif_lock, K_FOREVER);
if (ret != 0) {
LOG_ERR("%s: Failed to lock vif_lock", __func__);
goto out;
goto drop;
}
locked = true;

rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep;
if (!rpu_ctx_zep || !rpu_ctx_zep->rpu_ctx) {
goto unlock;
goto drop;
}

sys_dev_ctx = wifi_dev_priv(rpu_ctx_zep->rpu_ctx);
host_stats = &sys_dev_ctx->host_stats;
nbuf = net_pkt_to_nbuf(pkt);
if (!nbuf) {
LOG_DBG("Failed to allocate net_pkt");
host_stats->total_tx_drop_pkts++;
goto out;

if (nbuf == NULL) {
LOG_ERR("%s: allocation failed", __func__);
goto drop;
}

#ifdef CONFIG_NRF70_RAW_DATA_TX
Expand All @@ -415,10 +419,16 @@ int nrf_wifi_if_send(const struct device *dev,
#endif /* CONFIG_NRF70_RAW_DATA_TX */
goto unlock;
drop:
host_stats->total_tx_drop_pkts++;
nrf_wifi_osal_nbuf_free(nbuf);
if (host_stats != NULL) {
host_stats->total_tx_drop_pkts++;
}
if (nbuf != NULL) {
nrf_wifi_osal_nbuf_free(nbuf);
}
unlock:
k_mutex_unlock(&vif_ctx_zep->vif_lock);
if (locked) {
k_mutex_unlock(&vif_ctx_zep->vif_lock);
}
#else
ARG_UNUSED(dev);
ARG_UNUSED(pkt);
Expand Down
8 changes: 6 additions & 2 deletions samples/net/zperf/Kconfig
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Copyright 2023 NXP
# SPDX-License-Identifier: Apache-2.0

source "Kconfig.zephyr"

config NET_SAMPLE_CODE_RELOCATE
bool "Relocate networking code into RAM"
select CODE_DATA_RELOCATION
Expand All @@ -27,3 +25,9 @@ if USB_DEVICE_STACK_NEXT
# tree, you cannot use them in your own application.
source "samples/subsys/usb/common/Kconfig.sample_usbd"
endif

configdefault NRF_WIFI_DATA_HEAP_SIZE
default 30000 if NRF_WIFI_ZERO_COPY_TX
default 50000

source "Kconfig.zephyr"
1 change: 0 additions & 1 deletion samples/net/zperf/boards/nrf7002dk_nrf5340_cpuapp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ CONFIG_NET_PKT_TX_COUNT=28
CONFIG_NET_BUF_RX_COUNT=28
CONFIG_NET_BUF_TX_COUNT=28
CONFIG_NRF70_RX_NUM_BUFS=16
CONFIG_NRF_WIFI_DATA_HEAP_SIZE=30000
CONFIG_NET_PKT_BUF_TX_DATA_POOL_SIZE=20000
CONFIG_NRF70_MAX_TX_AGGREGATION=4
CONFIG_NRF70_QSPI_LOW_POWER=n
Expand Down