Skip to content

Commit 0efdc02

Browse files
committed
nfc: nci: clear NCI_DATA_EXCHANGE before calling completion callback
Move clear_bit(NCI_DATA_EXCHANGE) before invoking the data exchange callback in nci_data_exchange_complete(). The callback (e.g. rawsock_data_exchange_complete) may immediately schedule another data exchange via schedule_work(tx_work). On a multi-CPU system, tx_work can run and reach nci_transceive() before the current nci_data_exchange_complete() clears the flag, causing test_and_set_bit(NCI_DATA_EXCHANGE) to return -EBUSY and the new transfer to fail. This causes intermittent flakes in nci/nci_dev in NIPA: # # RUN NCI.NCI1_0.t4t_tag_read ... # # t4t_tag_read: Test terminated by timeout # # FAIL NCI.NCI1_0.t4t_tag_read # not ok 3 NCI.NCI1_0.t4t_tag_read Fixes: 38f04c6 ("NFC: protect nci_data_exchange transactions") Reviewed-by: Joe Damato <joe@dama.to> Link: https://patch.msgid.link/20260303162346.2071888-5-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 6608358 commit 0efdc02

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

net/nfc/nci/data.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ void nci_data_exchange_complete(struct nci_dev *ndev, struct sk_buff *skb,
3333
conn_info = nci_get_conn_info_by_conn_id(ndev, conn_id);
3434
if (!conn_info) {
3535
kfree_skb(skb);
36-
goto exit;
36+
clear_bit(NCI_DATA_EXCHANGE, &ndev->flags);
37+
return;
3738
}
3839

3940
cb = conn_info->data_exchange_cb;
@@ -45,6 +46,12 @@ void nci_data_exchange_complete(struct nci_dev *ndev, struct sk_buff *skb,
4546
timer_delete_sync(&ndev->data_timer);
4647
clear_bit(NCI_DATA_EXCHANGE_TO, &ndev->flags);
4748

49+
/* Mark the exchange as done before calling the callback.
50+
* The callback (e.g. rawsock_data_exchange_complete) may
51+
* want to immediately queue another data exchange.
52+
*/
53+
clear_bit(NCI_DATA_EXCHANGE, &ndev->flags);
54+
4855
if (cb) {
4956
/* forward skb to nfc core */
5057
cb(cb_context, skb, err);
@@ -54,9 +61,6 @@ void nci_data_exchange_complete(struct nci_dev *ndev, struct sk_buff *skb,
5461
/* no waiting callback, free skb */
5562
kfree_skb(skb);
5663
}
57-
58-
exit:
59-
clear_bit(NCI_DATA_EXCHANGE, &ndev->flags);
6064
}
6165

6266
/* ----------------- NCI TX Data ----------------- */

0 commit comments

Comments
 (0)