Skip to contentSkip to conversation

Bluetooth: btmtksdio: ensure btmtksdio_close is executed before btmtksdio_remove

PATCH Applied Chris Lu 3 participants 6 messages Apr 22, 2025 – May 21, 2025

Subsystems (2)
lore
Share & tools
lore

Chris Lu

author
#0 lore raw

v2 cover Bluetooth: btmtksdio: ensure btmtksdio_close is executed before btmtksdio_remove

If Bluetooth SDIO card is unexpectedly removed due to hardware removal or SDIO issue, it is possible for remove to be called before close. If an interrupt occurs during this process, it may cause kernel panic. Therefore, it is necessary to ensure that close is executed before remove to stop interrupts and cancel txrx workqueue.

Chris Lu (2):
Bluetooth: btmtksdio: Check function enabled before doing close
Bluetooth: btmtksdio: Do close if SDIO card removed without close

 drivers/bluetooth/btmtksdio.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
Signature · 1 line
2.45.2
author
#1 lore raw

PATCH v2 1/2 Bluetooth: btmtksdio: Check function enabled before doing close

Check BTMTKSDIO_FUNC_ENABLED flag before doing close to prevent btmtksdio_close been called twice.

Fixes c4233afb9a ("Bluetooth: btmtksdio: Prevent enabling interrupts after IRQ handler removal")
---
 drivers/bluetooth/btmtksdio.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/bluetooth/btmtksdio.c +4 -0
index 566c136e83bf..3c66e3ee9834 100644
@@ -723,6 +723,10 @@ static int btmtksdio_close(struct hci_dev *hdev)
 {
 	struct btmtksdio_dev *bdev = hci_get_drvdata(hdev);
 
+	/* Skip btmtksdio_close if BTMTKSDIO_FUNC_ENABLED isn't set */
+	if (!test_bit(BTMTKSDIO_FUNC_ENABLED, &bdev->tx_state))
+		return 0;
+
 	sdio_claim_host(bdev->func);
 
 	/* Disable interrupt */
Signature · 1 line
2.45.2
#2 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=955503

---Test result---

Test Summary:

CheckPatch                    PENDING   0.36 seconds
GitLint                       PENDING   0.32 seconds
SubjectPrefix                 PASS      0.13 seconds
BuildKernel                   PASS      25.68 seconds
CheckAllWarning               PASS      28.15 seconds
CheckSparse                   PASS      31.70 seconds
BuildKernel32                 PASS      25.29 seconds
TestRunnerSetup               PASS      478.26 seconds
TestRunner_l2cap-tester       PASS      21.72 seconds
TestRunner_iso-tester         PASS      35.78 seconds
TestRunner_bnep-tester        PASS      4.90 seconds
TestRunner_mgmt-tester        FAIL      126.75 seconds
TestRunner_rfcomm-tester      PASS      8.05 seconds
TestRunner_sco-tester         PASS      12.70 seconds
TestRunner_ioctl-tester       PASS      8.47 seconds
TestRunner_mesh-tester        PASS      6.17 seconds
TestRunner_smp-tester         PASS      7.40 seconds
TestRunner_userchan-tester    PASS      5.05 seconds
IncrementalBuild              PENDING   0.95 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner Output:
Total: 490, Passed: 485 (99.0%), Failed: 1, Not Run: 4

Failed Test Cases
LL Privacy - Set Flags 1 (Add to RL) Failed 0.151 seconds
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:

---
Regards,
Linux Bluetooth

author
#3 lore raw

PATCH v2 2/2 Bluetooth: btmtksdio: Do close if SDIO card removed without close

In reply to Chris Lu

To prevent Bluetooth SDIO card from be physically removed suddenly, driver needs to ensure btmtksdio_close is called before btmtksdio_remove to disable interrupts and txrx workqueue.

Fixes c4233afb9a ("Bluetooth: btmtksdio: Prevent enabling interrupts after IRQ handler removal")
---
 drivers/bluetooth/btmtksdio.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/bluetooth/btmtksdio.c +6 -2
index 3c66e3ee9834..c16a3518b8ff 100644
@@ -1447,11 +1447,15 @@ static void btmtksdio_remove(struct sdio_func *func)
 	if (!bdev)
 		return;
 
+	hdev = bdev->hdev;
+
+	/* Make sure to call btmtksdio_close before removing sdio card */
+	if (test_bit(BTMTKSDIO_FUNC_ENABLED, &bdev->tx_state))
+		btmtksdio_close(hdev);
+
 	/* Be consistent the state in btmtksdio_probe */
 	pm_runtime_get_noresume(bdev->dev);
 
-	hdev = bdev->hdev;
-
 	sdio_set_drvdata(func, NULL);
 	hci_unregister_dev(hdev);
 	hci_free_dev(hdev);
Signature · 1 line
2.45.2
#4 lore raw
In reply to Chris Lu
This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 11 lines · On Tue, 22 Apr 2025 09:21:54 +0800 you wrote:

If Bluetooth SDIO card is unexpectedly removed due to hardware removal or SDIO issue, it is possible for remove to be called before close. If an interrupt occurs during this process, it may cause kernel panic. Therefore, it is necessary to ensure that close is executed before remove to stop interrupts and cancel txrx workqueue.

Chris Lu (2):
Bluetooth: btmtksdio: Check function enabled before doing close
Bluetooth: btmtksdio: Do close if SDIO card removed without close

[...]

Here is the summary with links:
- [v2,1/2] Bluetooth: btmtksdio: Check function enabled before doing close

    https://git.kernel.org/bluetooth/bluetooth-next/c/04c96a7ace25
  - [v2,2/2] Bluetooth: btmtksdio: Do close if SDIO card removed without close
    https://git.kernel.org/bluetooth/bluetooth-next/c/e0af21b30c82

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#5 lore raw
In reply to Chris Lu
This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 11 lines · On Tue, 22 Apr 2025 09:21:54 +0800 you wrote:

If Bluetooth SDIO card is unexpectedly removed due to hardware removal or SDIO issue, it is possible for remove to be called before close. If an interrupt occurs during this process, it may cause kernel panic. Therefore, it is necessary to ensure that close is executed before remove to stop interrupts and cancel txrx workqueue.

Chris Lu (2):
Bluetooth: btmtksdio: Check function enabled before doing close
Bluetooth: btmtksdio: Do close if SDIO card removed without close

[...]

Here is the summary with links:
- [v2,1/2] Bluetooth: btmtksdio: Check function enabled before doing close

    https://git.kernel.org/bluetooth/bluetooth-next/c/07e90048e356
  - [v2,2/2] Bluetooth: btmtksdio: Do close if SDIO card removed without close
    https://git.kernel.org/bluetooth/bluetooth-next/c/0b6d58bc6ea8

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html