nfc_allocate_device() leaves shutting_down clear until unregister begins. A driver which publishes transport callbacks during registration can therefore receive an early request before registration has completed. Initialize the device in the shutting-down state, use one-copy stores when registration opens and closes admission, and only admit requests after the device has been fully registered. Discovered during an AI-assisted source audit using OpenAI Codex, gpt-5.6-sol. The early-publication condition was reproduced by racing NFC_CMD_DEV_UP with NCIUARTSETDRIVER on a pty-backed transport. An earlier high-concurrency pre-fix run also hit a general-protection fault in nfcmrvl_nci_uart_tx_start() with nu->drv_data still NULL. Patch development and test planning used the same assistant. Confirmed with repeated pty-backed NCI UART registration, open, reset, and hangup cycles. No physical NFC controller was available. Fixes: 9674da8759df ("NFC: Add firmware upload netlink command") Assisted-by: LLM (OpenAI Codex, gpt-5.6-sol) Signed-off-by: Shubham Antil --- net/nfc/core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/nfc/core.c b/net/nfc/core.c index f52166929..685d1727d 100644 --- a/net/nfc/core.c +++ b/net/nfc/core.c @@ -1065,6 +1065,9 @@ struct nfc_dev *nfc_allocate_device(const struct nfc_ops *ops, if (!dev) return NULL; + /* Reject requests until registration has finished. */ + dev->shutting_down = true; + rc = ida_alloc(&nfc_index_ida, GFP_KERNEL); if (rc < 0) goto err_free_dev; @@ -1133,7 +1136,7 @@ int nfc_register_device(struct nfc_dev *dev) dev->rfkill = NULL; } } - dev->shutting_down = false; + WRITE_ONCE(dev->shutting_down, false); device_unlock(&dev->dev); rc = nfc_genl_device_added(dev); @@ -1167,7 +1170,7 @@ void nfc_unregister_rfkill(struct nfc_dev *dev) rfk = dev->rfkill; dev->rfkill = NULL; } - dev->shutting_down = true; + WRITE_ONCE(dev->shutting_down, true); device_unlock(&dev->dev); if (rfk) { base-commit: 30c71476d842b094651bd7712f6c8ee8716147d0 prerequisite-patch-id: da5eea669279340f2925f9be0d203fd3bc407cc5 prerequisite-patch-id: 109c531926f84389d8f1d2030160f6113a749142 -- 2.54.0