From: Bin Luo via B4 Relay <devnull+luob87709.gmail.com@kernel.org>
To: David Heidelberg <david@ixit.cz>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>
Cc: Krzysztof Kozlowski <krzk@kernel.org>,
oe-linux-nfc@lists.linux.dev, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH net v2 3/3] nfc: digital: stop works and drain commands before nfc_remove_device()
Date: Fri, 04 Dec 2026 14:06:59 +0800 [thread overview]
Message-ID: <20261204060656.503-4-luob87709@gmail.com> (raw)
In-Reply-To: <20261204060656.503-1-luob87709@gmail.com>
From: "Bin Luo (University of Electronic Science and Technology of China)" <luob87709@gmail.com>
nfc_digital_unregister_device() currently calls nfc_unregister_device()
before cancelling poll_work, cmd_work, and cmd_complete_work and before
draining ddev->cmd_queue.
nfc_unregister_device() calls nfc_llcp_unregister_device(), which
tears down and releases struct nfc_llcp_local (dropping its reference
and scheduling local_release_work() to kfree(local)). Afterwards,
still-running cmd_complete_work or the cmd_queue drain loop invokes
cmd->cmd_cb(ddev, cmd->cb_context, ...) -> nfc_llcp_recv(local, ...),
passing a struct nfc_llcp_local pointer that has already been
unregistered and may already be freed. In addition,
digital_wq_cmd_complete() can re-schedule cmd_work after
cancel_work_sync(&ddev->cmd_work) returns.
Mirror nci_unregister_device(): call nfc_unregister_rfkill() first to
set dev->shutting_down and prevent new core operations, permanently
stop poll_work, cmd_work, and cmd_complete_work with
disable_delayed_work_sync()/disable_work_sync(), drain cmd_queue while
LLCP is still registered, and finally call nfc_remove_device().
Discovered by AI-assisted code review after observing nfc_llcp_recv()
callbacks running after nfc_llcp_unregister_device() during nfcsim
module unload; regression-tested in QEMU KVM (KASAN, LOCKDEP,
DEBUG_OBJECTS) across 200 nfcsim load/unload cycles and against
tools/testing/selftests/nci/nci_dev (8/8 passed).
Fixes: 4b10884eb428 ("NFC: Digital Protocol stack implementation")
Fixes: 82e57952869f ("NFC: digital: Call pending command callbacks at device unregister")
Cc: stable@vger.kernel.org
Signed-off-by: Bin Luo (University of Electronic Science and Technology of China) <luob87709@gmail.com>
---
Changes in v2:
- Resend cleanly via b4 web relay (v1 patch was line-wrapped by Gmail)
and include all three NFC teardown fixes as a threaded series.
net/nfc/digital_core.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/net/nfc/digital_core.c b/net/nfc/digital_core.c
index 1823622..7b8d72f 100644
--- a/net/nfc/digital_core.c
+++ b/net/nfc/digital_core.c
@@ -836,15 +836,15 @@ void nfc_digital_unregister_device(struct nfc_digital_dev *ddev)
{
struct digital_cmd *cmd, *n;
- nfc_unregister_device(ddev->nfc_dev);
+ nfc_unregister_rfkill(ddev->nfc_dev);
mutex_lock(&ddev->poll_lock);
ddev->poll_tech_count = 0;
mutex_unlock(&ddev->poll_lock);
- cancel_delayed_work_sync(&ddev->poll_work);
- cancel_work_sync(&ddev->cmd_work);
- cancel_work_sync(&ddev->cmd_complete_work);
+ disable_delayed_work_sync(&ddev->poll_work);
+ disable_work_sync(&ddev->cmd_work);
+ disable_work_sync(&ddev->cmd_complete_work);
list_for_each_entry_safe(cmd, n, &ddev->cmd_queue, queue) {
list_del(&cmd->queue);
@@ -859,6 +859,8 @@ void nfc_digital_unregister_device(struct nfc_digital_dev *ddev)
kfree(cmd->mdaa_params);
kfree(cmd);
}
+
+ nfc_remove_device(ddev->nfc_dev);
}
EXPORT_SYMBOL(nfc_digital_unregister_device);
--
2.43.0
prev parent reply other threads:[~2026-12-04 6:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 6:06 [PATCH net v2 0/3] nfc: fix LLCP, nfcsim, and digital device teardown ordering Bin Luo via B4 Relay
2026-12-04 6:06 ` [PATCH net v2 1/3] nfc: llcp: fix work and timer teardown order in local_cleanup() Bin Luo via B4 Relay
2026-12-04 6:06 ` [PATCH net v2 2/3] nfc: nfcsim: stop link and works before unregistering digital device Bin Luo via B4 Relay
2026-12-04 6:06 ` Bin Luo via B4 Relay [this message]
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=20261204060656.503-4-luob87709@gmail.com \
--to=devnull+luob87709.gmail.com@kernel.org \
--cc=davem@davemloft.net \
--cc=david@ixit.cz \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=krzk@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luob87709@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=oe-linux-nfc@lists.linux.dev \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
/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