]> git.baikalelectronics.ru Git - kernel.git/commit
NFC: reorganize the functions in nci_request
authorLin Ma <linma@zju.edu.cn>
Mon, 15 Nov 2021 14:56:00 +0000 (22:56 +0800)
committerJakub Kicinski <kuba@kernel.org>
Thu, 18 Nov 2021 04:16:53 +0000 (20:16 -0800)
commit17681745d98fe54e4d319625762b49e7858731d3
tree993f3eb88e7320334cf6776cf8413263ddb049a3
parentd410729d80e80eadab8cd755addd77c313e77f56
NFC: reorganize the functions in nci_request

There is a possible data race as shown below:

thread-A in nci_request()       | thread-B in nci_close_device()
                                | mutex_lock(&ndev->req_lock);
test_bit(NCI_UP, &ndev->flags); |
...                             | test_and_clear_bit(NCI_UP, &ndev->flags)
mutex_lock(&ndev->req_lock);    |
                                |

This race will allow __nci_request() to be awaked while the device is
getting removed.

Similar to commit a99b2883b977 ("bluetooth: eliminate the potential race
condition when removing the HCI controller"). this patch alters the
function sequence in nci_request() to prevent the data races between the
nci_close_device().

Signed-off-by: Lin Ma <linma@zju.edu.cn>
Fixes: 0a0691f9b3fc ("NFC: basic NCI protocol implementation")
Link: https://lore.kernel.org/r/20211115145600.8320-1-linma@zju.edu.cn
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/nfc/nci/core.c