]> git.baikalelectronics.ru Git - kernel.git/commit
NFC: hci: fix sleep in atomic context bugs in nfc_hci_hcp_message_tx
authorDuoming Zhou <duoming@zju.edu.cn>
Wed, 18 May 2022 11:57:33 +0000 (19:57 +0800)
committerJakub Kicinski <kuba@kernel.org>
Fri, 20 May 2022 00:54:02 +0000 (17:54 -0700)
commitf434c36ca9264800a235d74c963061a7a280c1b7
tree714c44985ca40de1a3b9a2299dcc424578ae81b8
parentbd295d3ac8fce830a23cc2421441f24ce35225fe
NFC: hci: fix sleep in atomic context bugs in nfc_hci_hcp_message_tx

There are sleep in atomic context bugs when the request to secure
element of st21nfca is timeout. The root cause is that kzalloc and
alloc_skb with GFP_KERNEL parameter and mutex_lock are called in
st21nfca_se_wt_timeout which is a timer handler. The call tree shows
the execution paths that could lead to bugs:

   (Interrupt context)
st21nfca_se_wt_timeout
  nfc_hci_send_event
    nfc_hci_hcp_message_tx
      kzalloc(..., GFP_KERNEL) //may sleep
      alloc_skb(..., GFP_KERNEL) //may sleep
      mutex_lock() //may sleep

This patch moves the operations that may sleep into a work item.
The work item will run in another kernel thread which is in
process context to execute the bottom half of the interrupt.
So it could prevent atomic context from sleeping.

Fixes: 736af51f6c13 ("NFC: st21nfca: Adding support for secure element")
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20220518115733.62111-1-duoming@zju.edu.cn
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/nfc/st21nfca/se.c
drivers/nfc/st21nfca/st21nfca.h