Re: [PATCH v2] NFC: nxp-nci: fix deadlock between firmware download and IRQ handler
From: Ziyu Zhang
Date: Mon Nov 23 2026 - 10:37:19 EST
Hi Ian and David,
Thanks for the patch and review.
For the timeout/late-response race David pointed out, I suggest checking
info->mode at the start of nxp_nci_fw_work(), after taking info_lock.
On timeout, nxp_nci_fw_work_complete() sets the mode to NXP_NCI_MODE_COLD
and releases the firmware while the worker holds info_lock. When the
work queued by a late response runs after this cleanup, the mode check
makes it exit before accessing the released firmware data.
The diff below combines Ian's unlock/wait/relock fix with this additional
check and applies to the original code before v2.
I have not fixed the other two issues yet. I think these would be best addressed in separate
patches.
Signed-off-by: Ziyu Zhang <ziyuzhang201@xxxxxxxxx>
---
drivers/nfc/nxp-nci/firmware.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/nfc/nxp-nci/firmware.c b/drivers/nfc/nxp-nci/firmware.c
index a953397..33193fe 100644
--- a/drivers/nfc/nxp-nci/firmware.c
+++ b/drivers/nfc/nxp-nci/firmware.c
@@ -154,8 +154,10 @@ static int nxp_nci_fw_send(struct nxp_nci_info *info)
if (fw_info->fw)
schedule_work(&fw_info->work);
} else {
+ mutex_unlock(&info->info_lock);
completion_rc = wait_for_completion_interruptible_timeout(
&fw_info->cmd_completion, NXP_NCI_FW_ANSWER_TIMEOUT);
+ mutex_lock(&info->info_lock);
if (completion_rc == 0)
return -ETIMEDOUT;
}
@@ -174,6 +176,9 @@ void nxp_nci_fw_work(struct work_struct *work)
mutex_lock(&info->info_lock);
+ if (info->mode != NXP_NCI_MODE_FW)
+ goto out_unlock;
+
r = fw_info->cmd_result;
if (r < 0)
goto exit_work;
@@ -190,6 +195,7 @@ void nxp_nci_fw_work(struct work_struct *work)
exit_work:
if (r < 0 || fw_info->size == 0)
nxp_nci_fw_work_complete(info, r);
+out_unlock:
mutex_unlock(&info->info_lock);
}
--
2.34.1