* [PATCH v1 0/2] Bluetooth: btmtksdio: ensure btmtksdio_close is executed before btmtksdio_remove
@ 2025-04-21 7:29 Chris Lu
2025-04-21 7:29 ` [PATCH v1 1/2] Bluetooth: btmtksdio: Check function enabled before doing close Chris Lu
2025-04-21 7:29 ` [PATCH v1 2/2] Bluetooth: btmtksdio: Do close if SDIO card removed without close Chris Lu
0 siblings, 2 replies; 5+ messages in thread
From: Chris Lu @ 2025-04-21 7:29 UTC (permalink / raw)
To: Marcel Holtmann, Johan Hedberg, Luiz Von Dentz
Cc: Sean Wang, Jiande Lu, Will Lee, SS Wu, Steve Lee, linux-bluetooth,
linux-kernel, linux-mediatek, Chris Lu
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(-)
--
2.45.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v1 1/2] Bluetooth: btmtksdio: Check function enabled before doing close
2025-04-21 7:29 [PATCH v1 0/2] Bluetooth: btmtksdio: ensure btmtksdio_close is executed before btmtksdio_remove Chris Lu
@ 2025-04-21 7:29 ` Chris Lu
2025-04-21 19:19 ` Luiz Augusto von Dentz
2025-04-21 7:29 ` [PATCH v1 2/2] Bluetooth: btmtksdio: Do close if SDIO card removed without close Chris Lu
1 sibling, 1 reply; 5+ messages in thread
From: Chris Lu @ 2025-04-21 7:29 UTC (permalink / raw)
To: Marcel Holtmann, Johan Hedberg, Luiz Von Dentz
Cc: Sean Wang, Jiande Lu, Will Lee, SS Wu, Steve Lee, linux-bluetooth,
linux-kernel, linux-mediatek, Chris Lu
Check BTMTKSDIO_FUNC_ENABLED flag before doing close to prevent
btmtksdio_close been called twice.
Signed-off-by: Chris Lu <chris.lu@mediatek.com>
---
drivers/bluetooth/btmtksdio.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/bluetooth/btmtksdio.c b/drivers/bluetooth/btmtksdio.c
index 566c136e83bf..3c66e3ee9834 100644
--- a/drivers/bluetooth/btmtksdio.c
+++ b/drivers/bluetooth/btmtksdio.c
@@ -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 */
--
2.45.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v1 2/2] Bluetooth: btmtksdio: Do close if SDIO card removed without close
2025-04-21 7:29 [PATCH v1 0/2] Bluetooth: btmtksdio: ensure btmtksdio_close is executed before btmtksdio_remove Chris Lu
2025-04-21 7:29 ` [PATCH v1 1/2] Bluetooth: btmtksdio: Check function enabled before doing close Chris Lu
@ 2025-04-21 7:29 ` Chris Lu
2025-04-21 19:19 ` Luiz Augusto von Dentz
1 sibling, 1 reply; 5+ messages in thread
From: Chris Lu @ 2025-04-21 7:29 UTC (permalink / raw)
To: Marcel Holtmann, Johan Hedberg, Luiz Von Dentz
Cc: Sean Wang, Jiande Lu, Will Lee, SS Wu, Steve Lee, linux-bluetooth,
linux-kernel, linux-mediatek, Chris Lu
To prevent Bluetooth SDIO card from being physically removed suddenly,
driver needs to ensure btmtksdio_close is called before btmtksdio_remove
to disable interrupts and txrx workqueue.
Signed-off-by: Chris Lu <chris.lu@mediatek.com>
---
drivers/bluetooth/btmtksdio.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/bluetooth/btmtksdio.c b/drivers/bluetooth/btmtksdio.c
index 3c66e3ee9834..c16a3518b8ff 100644
--- a/drivers/bluetooth/btmtksdio.c
+++ b/drivers/bluetooth/btmtksdio.c
@@ -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);
--
2.45.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v1 1/2] Bluetooth: btmtksdio: Check function enabled before doing close
2025-04-21 7:29 ` [PATCH v1 1/2] Bluetooth: btmtksdio: Check function enabled before doing close Chris Lu
@ 2025-04-21 19:19 ` Luiz Augusto von Dentz
0 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2025-04-21 19:19 UTC (permalink / raw)
To: Chris Lu
Cc: Marcel Holtmann, Johan Hedberg, Sean Wang, Jiande Lu, Will Lee,
SS Wu, Steve Lee, linux-bluetooth, linux-kernel, linux-mediatek
Hi Chris,
On Mon, Apr 21, 2025 at 3:29 AM Chris Lu <chris.lu@mediatek.com> wrote:
>
> Check BTMTKSDIO_FUNC_ENABLED flag before doing close to prevent
> btmtksdio_close been called twice.
>
> Signed-off-by: Chris Lu <chris.lu@mediatek.com>
Please add Fixes tag.
> ---
> drivers/bluetooth/btmtksdio.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/bluetooth/btmtksdio.c b/drivers/bluetooth/btmtksdio.c
> index 566c136e83bf..3c66e3ee9834 100644
> --- a/drivers/bluetooth/btmtksdio.c
> +++ b/drivers/bluetooth/btmtksdio.c
> @@ -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 */
> --
> 2.45.2
>
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1 2/2] Bluetooth: btmtksdio: Do close if SDIO card removed without close
2025-04-21 7:29 ` [PATCH v1 2/2] Bluetooth: btmtksdio: Do close if SDIO card removed without close Chris Lu
@ 2025-04-21 19:19 ` Luiz Augusto von Dentz
0 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2025-04-21 19:19 UTC (permalink / raw)
To: Chris Lu
Cc: Marcel Holtmann, Johan Hedberg, Sean Wang, Jiande Lu, Will Lee,
SS Wu, Steve Lee, linux-bluetooth, linux-kernel, linux-mediatek
Hi Chris,
On Mon, Apr 21, 2025 at 3:29 AM Chris Lu <chris.lu@mediatek.com> wrote:
>
> To prevent Bluetooth SDIO card from being physically removed suddenly,
> driver needs to ensure btmtksdio_close is called before btmtksdio_remove
> to disable interrupts and txrx workqueue.
>
> Signed-off-by: Chris Lu <chris.lu@mediatek.com>
Ditto, please add Fixes tag.
> ---
> drivers/bluetooth/btmtksdio.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/bluetooth/btmtksdio.c b/drivers/bluetooth/btmtksdio.c
> index 3c66e3ee9834..c16a3518b8ff 100644
> --- a/drivers/bluetooth/btmtksdio.c
> +++ b/drivers/bluetooth/btmtksdio.c
> @@ -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);
> --
> 2.45.2
>
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-04-21 19:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-21 7:29 [PATCH v1 0/2] Bluetooth: btmtksdio: ensure btmtksdio_close is executed before btmtksdio_remove Chris Lu
2025-04-21 7:29 ` [PATCH v1 1/2] Bluetooth: btmtksdio: Check function enabled before doing close Chris Lu
2025-04-21 19:19 ` Luiz Augusto von Dentz
2025-04-21 7:29 ` [PATCH v1 2/2] Bluetooth: btmtksdio: Do close if SDIO card removed without close Chris Lu
2025-04-21 19:19 ` Luiz Augusto von Dentz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox