From nobody Thu Sep 24 21:48:50 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F75A375AB5; Sat, 19 Sep 2026 20:44:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789850645; cv=none; b=M43OXN/Wiug4BPANUfSme9qw4Yjrh+yON6mdnVV0ykGPB8R43CYi2+Lc9xPZbsoF7dTmpAn0WunTxLm1jqLrwkAYSyqdv6cMi5qOfZgKMNM+Ok1Q4Ybg8CuMmrPTtnN+8vfCIveLrXfUFJ7UKr5oeOmxVna5eZGsDU0MW/Lbn1I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789850645; c=relaxed/simple; bh=O4jHspC2Q+PMYWXP+lpP2UpLmRNt60AedDGYqXHhhl4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ci1vRKmaci2KLTi4HwahVM4UG22hE8RSiAkmVEqQWdh1fq/CS/3TmrUyMh3VJ1Wym+ouldqslai93peG2eT2amI14rZnS9o2URbMmq7AY4TNAVF163YaC4aBSYDcdmj9EMcmCVtwba25J0LylX+tZVGtoZ8X3JogzXauz26EQ8k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DJB3PdTu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DJB3PdTu" Received: by smtp.kernel.org (Postfix) with ESMTPS id D8392C2BCF6; Sat, 19 Sep 2026 20:44:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1789850644; bh=O4jHspC2Q+PMYWXP+lpP2UpLmRNt60AedDGYqXHhhl4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=DJB3PdTu91CDnL+nJfDGAZlmNb4hM/prcsUXbLIQwoHPnVA9emSQnOnNzywgc31Bv 9WZ34gBuDoz83eTebm1tVXIGrPC7mL4NvGVCVx9MvRwc8cQ94hxxbWqHdV+/NUvD7i eUMkV97VSGwCGZpXB+GT3eha+lXFEwbcOVSiIoOv5VZPy1Fu8axP/ueuUJ3dL8X6cY Np7V1mU8NqwjcQDUsf5lIjCyWNYGGdnPD73d+4pl/3Vkt0RPip9n2UWOZNAMvnVGbr tJ4USZYZ+/JkT3RwxrpFa6DF5C8K6aacif8gGf52C6DmlE6KVIyZu2fItuJoorOHM4 lRiy+D7UjVsQg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id B97E5C982CC; Sat, 19 Sep 2026 20:44:04 +0000 (UTC) From: Kim Wooseok via B4 Relay Date: Sun, 20 Sep 2026 05:44:04 +0900 Subject: [PATCH rtw-next v3 1/3] wifi: rtl8xxxu: free RX skb when URB submission fails Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260920-codex-rtl-rx-v3-submit-v3-1-883d11351963@khu.ac.kr> References: <20260920-codex-rtl-rx-v3-submit-v3-0-883d11351963@khu.ac.kr> In-Reply-To: <20260920-codex-rtl-rx-v3-submit-v3-0-883d11351963@khu.ac.kr> To: linux-wireless@vger.kernel.org Cc: pkshih@realtek.com, kvalo@kernel.org, linux-kernel@vger.kernel.org, Jes.Sorensen@gmail.com X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1789850643; l=2896; i=5mghybrid@khu.ac.kr; s=kernel-20260913; h=from:subject:message-id; bh=v2NnvT75DMsgHtN+8TES4Q5i+B5ih9gWoiLYF9i+R38=; b=h0UorFHxgw9YQh1jMuFlj1/Q60jdD1CohOrRCrh/RRwWjWDvvdl6vAGo11wragppHxOkdahJc gy4jF4SF3NuBDcSpAuOxwmV+BKXmuVz2XqWflvjlaosMCy0B9WFiScF X-Developer-Key: i=5mghybrid@khu.ac.kr; a=ed25519; pk=1az/6lC8Tmd6BcvyarPc8FWoSxsV/WRr5NLs1v+kjlE= X-Endpoint-Received: by B4 Relay for 5mghybrid@khu.ac.kr/kernel-20260913 with auth_id=1028 X-Original-From: Kim Wooseok <5mghybrid@khu.ac.kr> Reply-To: 5mghybrid@khu.ac.kr From: Kim Wooseok <5mghybrid@khu.ac.kr> When usb_submit_urb() fails, rtl8xxxu_submit_rx_urb() unanchors the URB but leaves the newly allocated skb in urb.context. For ENOMEM/EAGAIN, the RX worker puts the request back on the pending list. The next submission allocates another skb and overwrites that pointer, leaking the previous buffer. Stopping before the retry also leaks it, because pending-list cleanup frees only the URB. Free the skb and clear urb.context in rtl8xxxu_submit_rx_urb() when submission fails. This keeps buffer allocation and failure cleanup in the same function, so a request returned for retry or teardown no longer owns an skb. Remove the corresponding cleanup from start and the RX worker; they only need to decide whether to retry or free the URB. Fixes: 26f1fad29ad9 ("New driver: rtl8xxxu (mac80211)") Reviewed-by: Ping-Ke Shih Assisted-by: GPT-6 Astra Signed-off-by: Kim Wooseok <5mghybrid@khu.ac.kr> --- drivers/net/wireless/realtek/rtl8xxxu/core.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/net/wireless/realtek/rtl8xxxu/core.c b/drivers/net/wir= eless/realtek/rtl8xxxu/core.c index bddbd0990de72..795a5ec2f8cd4 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/core.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/core.c @@ -5864,7 +5864,6 @@ static void rtl8xxxu_rx_urb_work(struct work_struct *= work) struct rtl8xxxu_priv *priv; struct rtl8xxxu_rx_urb *rx_urb, *tmp; struct list_head local; - struct sk_buff *skb; unsigned long flags; int ret; =20 @@ -5896,8 +5895,6 @@ static void rtl8xxxu_rx_urb_work(struct work_struct *= work) default: dev_warn(&priv->udev->dev, "failed to requeue urb with error %i\n", ret); - skb =3D (struct sk_buff *)rx_urb->urb.context; - dev_kfree_skb(skb); usb_free_urb(&rx_urb->urb); } } @@ -6596,8 +6593,11 @@ static int rtl8xxxu_submit_rx_urb(struct rtl8xxxu_pr= iv *priv, skb_size, rtl8xxxu_rx_complete, skb); usb_anchor_urb(&rx_urb->urb, &priv->rx_anchor); ret =3D usb_submit_urb(&rx_urb->urb, GFP_ATOMIC); - if (ret) + if (ret) { usb_unanchor_urb(&rx_urb->urb); + dev_kfree_skb(skb); + rx_urb->urb.context =3D NULL; + } return ret; } =20 @@ -7410,7 +7410,6 @@ static int rtl8xxxu_start(struct ieee80211_hw *hw) struct rtl8xxxu_priv *priv =3D hw->priv; struct rtl8xxxu_rx_urb *rx_urb; struct rtl8xxxu_tx_urb *tx_urb; - struct sk_buff *skb; unsigned long flags; int ret, i; =20 @@ -7461,13 +7460,8 @@ static int rtl8xxxu_start(struct ieee80211_hw *hw) rx_urb->hw =3D hw; =20 ret =3D rtl8xxxu_submit_rx_urb(priv, rx_urb); - if (ret) { - if (ret !=3D -ENOMEM) { - skb =3D (struct sk_buff *)rx_urb->urb.context; - dev_kfree_skb(skb); - } + if (ret) rtl8xxxu_queue_rx_urb(priv, rx_urb); - } } =20 schedule_delayed_work(&priv->ra_watchdog, 2 * HZ); --=20 2.53.0 From nobody Thu Sep 24 21:48:50 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F6CF374E48; Sat, 19 Sep 2026 20:44:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789850645; cv=none; b=H3lBRhoaffk40i/l6vJfUG9efagDP6mhRFlbvmL1xdMc4na7UJJHNvZ3Tocgz9SE65dDNphtXxy7OaIA+5vrqXC/Hbrp79uQbpjqLc5GY4T+s7iCLJj9BNBOzZkJ4ii2j+XpCapRF6aw2rM5FSQ9xc3tDQvSnBdFzHwqsDqY7+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789850645; c=relaxed/simple; bh=4W78FwMWh4CkJw7GIiqqdH7RuAbrFba5NTIWdCi/LyU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Kh6mcRPmTi9HRAW+5q/QkMNa509h/ZsHYYoFsHlon9lzjsunR6nzfLexoQgu8xgXVS182VDp5vk3xE4RDv0vqmX1C+/vURxnS/SXl00pRggzJHpm25TTJ1neC9xzcgr4Dkw/8qhVgvb53a0XSZbN15+75EzTzxbUmfWA2aPT4uQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F8vfZUvY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="F8vfZUvY" Received: by smtp.kernel.org (Postfix) with ESMTPS id E44C8C2BCFA; Sat, 19 Sep 2026 20:44:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1789850645; bh=4W78FwMWh4CkJw7GIiqqdH7RuAbrFba5NTIWdCi/LyU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=F8vfZUvYre9WAhv6mYfyJR5ReD5xJWJSRVVkeDNYQys8vy53VjmNSt3DRt3DMOQj1 XFzD/6QOE4j6AnJN5bZsUTaUjae9lnQ/RRfBu48Zua7DvfQm7xCv+D0rF0NHlfZw5B kc5/wqsyOfY/W7uCeGNpFEah2h6Vy7Ub7GwgG1rBZI3gMOaBXICqE2W5f0YF7fYgSt 0W+mYaruMZkfviJZX6ShEhuGtgF0xhhr8mFHgdcSML9zvyJsy2uh++8oy1gXBmtijU V4kmDypBCnTOkLUWXjWlB0kfLqMZJx4i/UkYNv0zxX4m+ZUyqqM+4wYMiGIYHe3QMO 7GmJkgSh1l5TQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7805C982DF; Sat, 19 Sep 2026 20:44:04 +0000 (UTC) From: Kim Wooseok via B4 Relay Date: Sun, 20 Sep 2026 05:44:05 +0900 Subject: [PATCH rtw-next v3 2/3] wifi: rtl8xxxu: unwind incomplete receive startup Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260920-codex-rtl-rx-v3-submit-v3-2-883d11351963@khu.ac.kr> References: <20260920-codex-rtl-rx-v3-submit-v3-0-883d11351963@khu.ac.kr> In-Reply-To: <20260920-codex-rtl-rx-v3-submit-v3-0-883d11351963@khu.ac.kr> To: linux-wireless@vger.kernel.org Cc: pkshih@realtek.com, kvalo@kernel.org, linux-kernel@vger.kernel.org, Jes.Sorensen@gmail.com X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1789850643; l=6605; i=5mghybrid@khu.ac.kr; s=kernel-20260913; h=from:subject:message-id; bh=OyDx5rqQosEORE8l/erZWFaYVL1RAiawqnAc+isUD8g=; b=AyIU/A7O/gd25EvcDw8HcPXZvk2amnaZxTQiI8/QUnLjF1+cdS8aa2Igk2w7J6cq0qe9YozoV ERUJ/87p5VfBJSWw7dRp39BX6dFeDVxX5l0FYtV/yCCWGoaodwc1X+A X-Developer-Key: i=5mghybrid@khu.ac.kr; a=ed25519; pk=1az/6lC8Tmd6BcvyarPc8FWoSxsV/WRr5NLs1v+kjlE= X-Endpoint-Received: by B4 Relay for 5mghybrid@khu.ac.kr/kernel-20260913 with auth_id=1028 X-Original-From: Kim Wooseok <5mghybrid@khu.ac.kr> Reply-To: 5mghybrid@khu.ac.kr From: Kim Wooseok <5mghybrid@khu.ac.kr> rtl8xxxu_start() allocates and submits RX URBs one at a time. If a later allocation fails, the error path frees the TX pool but leaves earlier RX requests active. A partial TX or RX allocation failure can also leave ret at zero, so start reports success despite the incomplete setup. Allocate the RX pool before submitting any of it, and return ENOMEM whenever a pool allocation fails. Pass start errors through rtl8xxxu_stop(), including interrupt URB submission failures, so the existing stop path cancels work and releases both active requests and partially allocated pools. Share the submission loop with the RX worker. Both callers keep requests that fail with ENOMEM/EAGAIN. For a fatal error during startup, free the rest of the unsubmitted batch and return the error so start can unwind. In the worker, free only the failed request and continue with the rest of the batch. Keep the allocation loop in a small helper so the setup and error paths in start remain easy to follow. Fixes: 26f1fad29ad9 ("New driver: rtl8xxxu (mac80211)") Assisted-by: GPT-6 Astra Signed-off-by: Kim Wooseok <5mghybrid@khu.ac.kr> Reviewed-by: Ping-Ke Shih --- drivers/net/wireless/realtek/rtl8xxxu/core.c | 96 ++++++++++++++++++++++++= ++++++++++++++++++++++++++++++------------------------------------------ 1 file changed, 54 insertions(+), 42 deletions(-) diff --git a/drivers/net/wireless/realtek/rtl8xxxu/core.c b/drivers/net/wir= eless/realtek/rtl8xxxu/core.c index 795a5ec2f8cd4..5ae3dbf5034ac 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/core.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/core.c @@ -58,6 +58,7 @@ MODULE_PARM_DESC(dma_agg_pages, "Set DMA aggregation page= s (range 1-127, 0 to di #define RTL8XXXU_TX_URB_LOW_WATER 25 #define RTL8XXXU_TX_URB_HIGH_WATER 32 =20 +static void rtl8xxxu_stop(struct ieee80211_hw *hw, bool suspend); static int rtl8xxxu_submit_rx_urb(struct rtl8xxxu_priv *priv, struct rtl8xxxu_rx_urb *rx_urb); =20 @@ -5832,6 +5833,27 @@ static void rtl8xxxu_free_rx_resources(struct rtl8xx= xu_priv *priv) spin_unlock_irqrestore(&priv->rx_urb_lock, flags); } =20 +static int rtl8xxxu_alloc_rx_urbs(struct rtl8xxxu_priv *priv) +{ + struct rtl8xxxu_rx_urb *rx_urb; + int i; + + /* No RX work is active until the complete pool has been allocated. */ + for (i =3D 0; i < RTL8XXXU_RX_URBS; i++) { + rx_urb =3D kmalloc_obj(struct rtl8xxxu_rx_urb); + if (!rx_urb) + return -ENOMEM; + + usb_init_urb(&rx_urb->urb); + INIT_LIST_HEAD(&rx_urb->list); + rx_urb->hw =3D priv->hw; + list_add_tail(&rx_urb->list, &priv->rx_urb_pending_list); + priv->rx_urb_pending_count++; + } + + return 0; +} + static void rtl8xxxu_queue_rx_urb(struct rtl8xxxu_priv *priv, struct rtl8xxxu_rx_urb *rx_urb) { @@ -5859,32 +5881,21 @@ static void rtl8xxxu_queue_rx_urb(struct rtl8xxxu_p= riv *priv, spin_unlock_irqrestore(&priv->rx_urb_lock, flags); } =20 -static void rtl8xxxu_rx_urb_work(struct work_struct *work) +static int rtl8xxxu_submit_rx_urbs(struct rtl8xxxu_priv *priv, bool startu= p) { - struct rtl8xxxu_priv *priv; struct rtl8xxxu_rx_urb *rx_urb, *tmp; - struct list_head local; unsigned long flags; + LIST_HEAD(local); int ret; =20 - priv =3D container_of(work, struct rtl8xxxu_priv, rx_urb_wq); - INIT_LIST_HEAD(&local); - spin_lock_irqsave(&priv->rx_urb_lock, flags); - list_splice_init(&priv->rx_urb_pending_list, &local); priv->rx_urb_pending_count =3D 0; - spin_unlock_irqrestore(&priv->rx_urb_lock, flags); =20 list_for_each_entry_safe(rx_urb, tmp, &local, list) { list_del_init(&rx_urb->list); ret =3D rtl8xxxu_submit_rx_urb(priv, rx_urb); - /* - * If out of memory or temporary error, put it back on the - * queue and try again. Otherwise the device is dead/gone - * and we should drop it. - */ switch (ret) { case 0: break; @@ -5893,11 +5904,30 @@ static void rtl8xxxu_rx_urb_work(struct work_struct= *work) rtl8xxxu_queue_rx_urb(priv, rx_urb); break; default: + usb_free_urb(&rx_urb->urb); + if (startup) + goto free_remaining; dev_warn(&priv->udev->dev, "failed to requeue urb with error %i\n", ret); - usb_free_urb(&rx_urb->urb); } } + + return 0; + +free_remaining: + list_for_each_entry_safe(rx_urb, tmp, &local, list) { + list_del(&rx_urb->list); + usb_free_urb(&rx_urb->urb); + } + return ret; +} + +static void rtl8xxxu_rx_urb_work(struct work_struct *work) +{ + struct rtl8xxxu_priv *priv; + + priv =3D container_of(work, struct rtl8xxxu_priv, rx_urb_wq); + rtl8xxxu_submit_rx_urbs(priv, false); } =20 /* @@ -7408,7 +7438,6 @@ static void rtl8xxxu_watchdog_callback(struct work_st= ruct *work) static int rtl8xxxu_start(struct ieee80211_hw *hw) { struct rtl8xxxu_priv *priv =3D hw->priv; - struct rtl8xxxu_rx_urb *rx_urb; struct rtl8xxxu_tx_urb *tx_urb; unsigned long flags; int ret, i; @@ -7423,14 +7452,13 @@ static int rtl8xxxu_start(struct ieee80211_hw *hw) if (priv->usb_interrupts) { ret =3D rtl8xxxu_submit_int_urb(hw); if (ret) - goto exit; + goto error_out; } =20 for (i =3D 0; i < RTL8XXXU_TX_URBS; i++) { tx_urb =3D kmalloc_obj(struct rtl8xxxu_tx_urb); if (!tx_urb) { - if (!i) - ret =3D -ENOMEM; + ret =3D -ENOMEM; =20 goto error_out; } @@ -7441,31 +7469,21 @@ static int rtl8xxxu_start(struct ieee80211_hw *hw) priv->tx_urb_free_count++; } =20 + ret =3D rtl8xxxu_alloc_rx_urbs(priv); + if (ret) + goto error_out; + priv->tx_stopped =3D false; =20 spin_lock_irqsave(&priv->rx_urb_lock, flags); priv->shutdown =3D false; spin_unlock_irqrestore(&priv->rx_urb_lock, flags); =20 - for (i =3D 0; i < RTL8XXXU_RX_URBS; i++) { - rx_urb =3D kmalloc_obj(struct rtl8xxxu_rx_urb); - if (!rx_urb) { - if (!i) - ret =3D -ENOMEM; - - goto error_out; - } - usb_init_urb(&rx_urb->urb); - INIT_LIST_HEAD(&rx_urb->list); - rx_urb->hw =3D hw; - - ret =3D rtl8xxxu_submit_rx_urb(priv, rx_urb); - if (ret) - rtl8xxxu_queue_rx_urb(priv, rx_urb); - } + ret =3D rtl8xxxu_submit_rx_urbs(priv, true); + if (ret) + goto error_out; =20 schedule_delayed_work(&priv->ra_watchdog, 2 * HZ); -exit: /* * Accept all data and mgmt frames */ @@ -7478,13 +7496,7 @@ static int rtl8xxxu_start(struct ieee80211_hw *hw) return ret; =20 error_out: - rtl8xxxu_free_tx_resources(priv); - /* - * Disable all data and mgmt frames - */ - rtl8xxxu_write16(priv, REG_RXFLTMAP2, 0x0000); - rtl8xxxu_write16(priv, REG_RXFLTMAP0, 0x0000); - + rtl8xxxu_stop(hw, false); return ret; } =20 --=20 2.53.0 From nobody Thu Sep 24 21:48:50 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F6123749F0; Sat, 19 Sep 2026 20:44:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789850645; cv=none; b=fh59yssGdx2cZWCI3reXIBosaJXNEbSNg5kPLyc83RCq7Nmo2p4ZZDaV48ZcxQ7VzOfoOvNU3Xpbo7JIB7gwmObry1WE5DrTE3FAsEM4lKt2/bt/+AsdLeXT45Bcb8IQVwaIoNHWIKaonhdUsZhHRd85LhflrRpa7BysQ+EmBek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789850645; c=relaxed/simple; bh=A99WF7XgsH2cfI5/e3IDMa/mJv47ybWr6d8kyD1eMI4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o1DLFyN3YHxsvWDq3T14rn1ceDAbtCdvMCu2uIm4kD07g1KgWMoGHQJNhziDwFlPRAIkldAK5ZpQEIlJoDr3kZPYWNmYeNNHwjwbu3T+8jhahywLBLhpRATAMa1JbiyKLSdEbm+JSU/ppciVGmqIymm9DgwbSA402aqNaIXVjrA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XoUum+sb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XoUum+sb" Received: by smtp.kernel.org (Postfix) with ESMTPS id F1CD0C2BCFB; Sat, 19 Sep 2026 20:44:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1789850645; bh=A99WF7XgsH2cfI5/e3IDMa/mJv47ybWr6d8kyD1eMI4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=XoUum+sbyjnqaOSNY6AUwIN3Lz2TBvGX+J6g1c03PJsqrWDvL5DcYPiBZxyo15+UN pvwn92HEtm9Bb847YXfekuAKR+mpYpLjyUQvHMr2bx2E0MV50ASzi+miM/BoTI7bMo avV/9BqkQYjLKlMjFBaruGrxb1Txn1KCgprQ8MyPd9Bt7F02k2AnmTjAR/w7FX68bS TPuBxc4dzm1Q6hXBTclCFZfjmXPPK0ZFylZ7os3yRt4+CyIYQiCyV8uJPE78236MJi czxB7lrpG+Nxtj6c6y2c8wpgccJk1EDRw0lAqahumbCpE+/QcBIQ4JG+yRZ/9xQNGF S22mb4jNVzEIQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D586DC982D8; Sat, 19 Sep 2026 20:44:04 +0000 (UTC) From: Kim Wooseok via B4 Relay Date: Sun, 20 Sep 2026 05:44:06 +0900 Subject: [PATCH rtw-next v3 3/3] wifi: rtl8xxxu: preserve RX requests across recoverable transfer errors Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260920-codex-rtl-rx-v3-submit-v3-3-883d11351963@khu.ac.kr> References: <20260920-codex-rtl-rx-v3-submit-v3-0-883d11351963@khu.ac.kr> In-Reply-To: <20260920-codex-rtl-rx-v3-submit-v3-0-883d11351963@khu.ac.kr> To: linux-wireless@vger.kernel.org Cc: pkshih@realtek.com, kvalo@kernel.org, linux-kernel@vger.kernel.org, Jes.Sorensen@gmail.com X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1789850643; l=6457; i=5mghybrid@khu.ac.kr; s=kernel-20260913; h=from:subject:message-id; bh=ELcGIj3/1qa+I+rYa4pUTPcIEvRdg4LJVJ6OX7JJaPE=; b=uTxba9X02x6TPEKEvMraKPHDpYmSCZZVbBfHEyNQqaj6HGtwEgU4mEVvLH2CNjwI+uT+7/F3B zPJY7FyWL89D5/gOd1e4l7k4z6Byzyz5oCzbVmkuaAIg5nWyWLo3947 X-Developer-Key: i=5mghybrid@khu.ac.kr; a=ed25519; pk=1az/6lC8Tmd6BcvyarPc8FWoSxsV/WRr5NLs1v+kjlE= X-Endpoint-Received: by B4 Relay for 5mghybrid@khu.ac.kr/kernel-20260913 with auth_id=1028 X-Original-From: Kim Wooseok <5mghybrid@khu.ac.kr> Reply-To: 5mghybrid@khu.ac.kr From: Kim Wooseok <5mghybrid@khu.ac.kr> rtl8xxxu resubmits completed RX requests when more than eight URBs are waiting on the pending list. It starts with 32 URBs, but frees them on completion errors. After enough errors, the remaining pool can no longer reach the submission threshold. Reception then stays stopped even after the errors end. Temporary submission failures can leave a small batch waiting with no further work scheduled, too. Keep the URB when a completion reports EPROTO, EILSEQ, ETIME, EOVERFLOW, ECOMM or ENOSR. Free its receive buffer and return the request to the same pending list used by normal completions. ENOMEM/EAGAIN from startup or worker submission uses this path as well, so a submission failure cannot strand a request during recovery. Use one delayed work item to submit the pending requests. An error queues a retry after 100 ms without moving an existing reservation back. If a normal completion takes the pending count above eight, mod_delayed_work(..., 0) brings the work forward. This limits repeated retries when reception is not progressing, while allowing normal traffic to replenish the pool promptly. The 100 ms delay is therefore not a minimum wait for each failed URB. Keep the shutdown check, queue insertion and scheduling under the RX lock. Stop sets shutdown under that lock, cancels the delayed work synchronously, then drains active and pending requests. Cancellation and device removal continue to free their URBs. Fixes: 26f1fad29ad9 ("New driver: rtl8xxxu (mac80211)") Assisted-by: GPT-6 Astra Signed-off-by: Kim Wooseok <5mghybrid@khu.ac.kr> --- drivers/net/wireless/realtek/rtl8xxxu/core.c | 45 ++++++++++++++++++++= ++++++++----------------- drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h | 2 +- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/drivers/net/wireless/realtek/rtl8xxxu/core.c b/drivers/net/wir= eless/realtek/rtl8xxxu/core.c index 5ae3dbf5034ac..8e513a0cb2e24 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/core.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/core.c @@ -54,6 +54,7 @@ MODULE_PARM_DESC(dma_agg_pages, "Set DMA aggregation page= s (range 1-127, 0 to di #define USB_VENDOR_ID_REALTEK 0x0bda #define RTL8XXXU_RX_URBS 32 #define RTL8XXXU_RX_URB_PENDING_WATER 8 +#define RTL8XXXU_RX_URB_RETRY_DELAY_MS 100 #define RTL8XXXU_TX_URBS 64 #define RTL8XXXU_TX_URB_LOW_WATER 25 #define RTL8XXXU_TX_URB_HIGH_WATER 32 @@ -5855,9 +5856,8 @@ static int rtl8xxxu_alloc_rx_urbs(struct rtl8xxxu_pri= v *priv) } =20 static void rtl8xxxu_queue_rx_urb(struct rtl8xxxu_priv *priv, - struct rtl8xxxu_rx_urb *rx_urb) + struct rtl8xxxu_rx_urb *rx_urb, bool retry) { - struct sk_buff *skb; unsigned long flags; =20 spin_lock_irqsave(&priv->rx_urb_lock, flags); @@ -5865,16 +5865,13 @@ static void rtl8xxxu_queue_rx_urb(struct rtl8xxxu_p= riv *priv, if (!priv->shutdown) { list_add_tail(&rx_urb->list, &priv->rx_urb_pending_list); priv->rx_urb_pending_count++; - /* - * Arm the worker under rx_urb_lock so this is atomic with the - * shutdown check: moving it out of the lock would let a - * completion arm the work after rtl8xxxu_stop() canceled it. - */ - if (priv->rx_urb_pending_count > RTL8XXXU_RX_URB_PENDING_WATER) - schedule_work(&priv->rx_urb_wq); + /* Serialize scheduling with the shutdown check and cancellation. */ + if (retry) + queue_delayed_work(system_wq, &priv->rx_urb_wq, + msecs_to_jiffies(RTL8XXXU_RX_URB_RETRY_DELAY_MS)); + else if (priv->rx_urb_pending_count > RTL8XXXU_RX_URB_PENDING_WATER) + mod_delayed_work(system_wq, &priv->rx_urb_wq, 0); } else { - skb =3D (struct sk_buff *)rx_urb->urb.context; - dev_kfree_skb_irq(skb); usb_free_urb(&rx_urb->urb); } =20 @@ -5901,7 +5898,7 @@ static int rtl8xxxu_submit_rx_urbs(struct rtl8xxxu_pr= iv *priv, bool startup) break; case -ENOMEM: case -EAGAIN: - rtl8xxxu_queue_rx_urb(priv, rx_urb); + rtl8xxxu_queue_rx_urb(priv, rx_urb, true); break; default: usb_free_urb(&rx_urb->urb); @@ -5926,7 +5923,8 @@ static void rtl8xxxu_rx_urb_work(struct work_struct *= work) { struct rtl8xxxu_priv *priv; =20 - priv =3D container_of(work, struct rtl8xxxu_priv, rx_urb_wq); + priv =3D container_of(to_delayed_work(work), struct rtl8xxxu_priv, + rx_urb_wq); rtl8xxxu_submit_rx_urbs(priv, false); } =20 @@ -6585,10 +6583,23 @@ static void rtl8xxxu_rx_complete(struct urb *urb) =20 skb =3D NULL; rx_urb->urb.context =3D NULL; - rtl8xxxu_queue_rx_urb(priv, rx_urb); + rtl8xxxu_queue_rx_urb(priv, rx_urb, false); } else { dev_dbg(dev, "%s: status %i\n", __func__, urb->status); - goto cleanup; + switch (urb->status) { + case -EPROTO: + case -EILSEQ: + case -ETIME: + case -EOVERFLOW: + case -ECOMM: + case -ENOSR: + dev_kfree_skb(skb); + urb->context =3D NULL; + rtl8xxxu_queue_rx_urb(priv, rx_urb, true); + return; + default: + goto cleanup; + } } return; =20 @@ -7519,7 +7530,7 @@ static void rtl8xxxu_stop(struct ieee80211_hw *hw, bo= ol suspend) * it drained via rtl8xxxu_submit_rx_urb(), so a worker still running * after the kill could submit a URB that escapes it. */ - cancel_work_sync(&priv->rx_urb_wq); + cancel_delayed_work_sync(&priv->rx_urb_wq); =20 usb_kill_anchored_urbs(&priv->rx_anchor); usb_kill_anchored_urbs(&priv->tx_anchor); @@ -7832,7 +7843,7 @@ static int rtl8xxxu_probe(struct usb_interface *inter= face, spin_lock_init(&priv->tx_urb_lock); INIT_LIST_HEAD(&priv->rx_urb_pending_list); spin_lock_init(&priv->rx_urb_lock); - INIT_WORK(&priv->rx_urb_wq, rtl8xxxu_rx_urb_work); + INIT_DELAYED_WORK(&priv->rx_urb_wq, rtl8xxxu_rx_urb_work); INIT_DELAYED_WORK(&priv->ra_watchdog, rtl8xxxu_watchdog_callback); INIT_DELAYED_WORK(&priv->update_beacon_work, rtl8xxxu_update_beacon_work_= callback); skb_queue_head_init(&priv->c2hcmd_queue); diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h b/drivers/net= /wireless/realtek/rtl8xxxu/rtl8xxxu.h index eeb18eb0e4c0f..c6953051d9c40 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h @@ -1809,7 +1809,7 @@ struct rtl8xxxu_priv { struct list_head rx_urb_pending_list; int rx_urb_pending_count; bool shutdown; - struct work_struct rx_urb_wq; + struct delayed_work rx_urb_wq; =20 u8 mac_addr[ETH_ALEN]; char chip_name[8]; --=20 2.53.0