From: "Bilal Yazıcıoğlu" <ahmetbilalyazicioglu@gmail.com>
To: netdev@vger.kernel.org
Cc: "David Heidelberg" <david@ixit.cz>,
oe-linux-nfc@lists.linux.dev, "Simon Horman" <horms@kernel.org>,
"Luiz Augusto von Dentz" <luiz.von.dentz@intel.com>,
"Kyle Pepper" <cochcoder@proton.me>,
linux-kernel@vger.kernel.org,
"Bilal Yazıcıoğlu" <ahmetbilalyazicioglu@gmail.com>
Subject: [PATCH net] nfc: nfcmrvl: free skb of deferred TX URBs
Date: Tue, 1 Dec 2026 10:29:22 +0300 [thread overview]
Message-ID: <20261201072922.16127-1-ahmetbilalyazicioglu@gmail.com> (raw)
While the device is suspended, nfcmrvl_usb_nci_send() does not submit
TX URBs but anchors them on drv_data->deferred, so that
nfcmrvl_play_deferred() submits them on resume. Until then the driver
owns the skb in urb->context, which is normally freed by
nfcmrvl_tx_complete().
When these URBs are dropped instead of submitted, only the URB itself
is freed:
- nfcmrvl_usb_nci_close() and the failed path of nfcmrvl_resume()
discard them with usb_scuttle_anchored_urbs(), leaking the skb.
- nfcmrvl_play_deferred() frees the setup packet but not the skb,
both when usb_submit_urb() fails and for the URBs left on the
anchor after that.
This driver was based on btusb and has the same leak that was fixed
there by "Bluetooth: btusb: free skb and setup packet of deferred TX
URBs" (in bluetooth-next). Commit 8a4d480702b7 ("nfc: nfcmrvl: Fix
memory leak in nfcmrvl_play_deferred") already ported the earlier btusb
play_deferred() fix to this driver, without the skb.
Add nfcmrvl_free_deferred(), which frees the setup packet, the skb and
the URB of every URB on the deferred anchor, and use it in
nfcmrvl_usb_nci_close(), nfcmrvl_resume() and nfcmrvl_play_deferred().
Also free the skb when usb_submit_urb() fails in
nfcmrvl_play_deferred().
Compile tested only, with W=1 and sparse; I do not have the hardware.
The same fix in btusb was verified on a ThinkPad T480 with kmemleak.
Claude Code pointed out that this driver shares the btusb leak. I wrote
the fix.
Fixes: f26e30cc6b50 ("NFC: nfcmrvl: Initial commit for Marvell NFC driver")
Fixes: 8a4d480702b7 ("nfc: nfcmrvl: Fix memory leak in nfcmrvl_play_deferred")
Signed-off-by: Bilal Yazıcıoğlu <ahmetbilalyazicioglu@gmail.com>
---
drivers/nfc/nfcmrvl/usb.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/drivers/nfc/nfcmrvl/usb.c b/drivers/nfc/nfcmrvl/usb.c
index c7f2afe00..3944f0307 100644
--- a/drivers/nfc/nfcmrvl/usb.c
+++ b/drivers/nfc/nfcmrvl/usb.c
@@ -162,6 +162,18 @@ static void nfcmrvl_tx_complete(struct urb *urb)
kfree_skb(skb);
}
+static void nfcmrvl_free_deferred(struct nfcmrvl_usb_drv_data *drv_data)
+{
+ struct urb *urb;
+
+ /* Deferred URBs were never submitted, so their completion won't run. */
+ while ((urb = usb_get_from_anchor(&drv_data->deferred))) {
+ kfree(urb->setup_packet);
+ kfree_skb(urb->context);
+ usb_free_urb(urb);
+ }
+}
+
static int nfcmrvl_usb_nci_open(struct nfcmrvl_private *priv)
{
struct nfcmrvl_usb_drv_data *drv_data = priv->drv_data;
@@ -212,7 +224,7 @@ static int nfcmrvl_usb_nci_close(struct nfcmrvl_private *priv)
usb_autopm_put_interface(drv_data->intf);
failed:
- usb_scuttle_anchored_urbs(&drv_data->deferred);
+ nfcmrvl_free_deferred(drv_data);
return 0;
}
@@ -380,6 +392,7 @@ static void nfcmrvl_play_deferred(struct nfcmrvl_usb_drv_data *drv_data)
err = usb_submit_urb(urb, GFP_ATOMIC);
if (err) {
kfree(urb->setup_packet);
+ kfree_skb(urb->context);
usb_unanchor_urb(urb);
usb_free_urb(urb);
break;
@@ -390,10 +403,7 @@ static void nfcmrvl_play_deferred(struct nfcmrvl_usb_drv_data *drv_data)
}
/* Cleanup the rest deferred urbs. */
- while ((urb = usb_get_from_anchor(&drv_data->deferred))) {
- kfree(urb->setup_packet);
- usb_free_urb(urb);
- }
+ nfcmrvl_free_deferred(drv_data);
}
static int nfcmrvl_resume(struct usb_interface *intf)
@@ -427,7 +437,7 @@ static int nfcmrvl_resume(struct usb_interface *intf)
return 0;
failed:
- usb_scuttle_anchored_urbs(&drv_data->deferred);
+ nfcmrvl_free_deferred(drv_data);
done:
spin_lock_irq(&drv_data->txlock);
clear_bit(NFCMRVL_USB_SUSPENDING, &drv_data->flags);
--
2.56.0
reply other threads:[~2026-12-01 7:29 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201072922.16127-1-ahmetbilalyazicioglu@gmail.com \
--to=ahmetbilalyazicioglu@gmail.com \
--cc=cochcoder@proton.me \
--cc=david@ixit.cz \
--cc=horms@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luiz.von.dentz@intel.com \
--cc=netdev@vger.kernel.org \
--cc=oe-linux-nfc@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®