* [PATCH] Bluetooth: btusb: Reject autosuspend if HCI inquiry or LE scan is active
@ 2026-01-07 2:48 Linmao Li
2026-01-07 14:47 ` Luiz Augusto von Dentz
0 siblings, 1 reply; 9+ messages in thread
From: Linmao Li @ 2026-01-07 2:48 UTC (permalink / raw)
To: linux-bluetooth; +Cc: marcel, luiz.dentz, linux-kernel, Linmao Li
If USB autosuspend occurs while BR/EDR inquiry or LE scan is active,
the ongoing HCI operation may not complete successfully. On some
devices, this can leave discovery.state stuck in DISCOVERY_FINDING.
Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
---
drivers/bluetooth/btusb.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index ded09e94d296..885c3d8c0a10 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -4469,10 +4469,13 @@ static int btusb_suspend(struct usb_interface *intf, pm_message_t message)
BT_DBG("intf %p", intf);
- /* Don't auto-suspend if there are connections; external suspend calls
- * shall never fail.
+ /* Don't auto-suspend if there are connections or HCI operations in
+ * progress; external suspend calls shall never fail.
*/
- if (PMSG_IS_AUTO(message) && hci_conn_count(data->hdev))
+ if (PMSG_IS_AUTO(message) &&
+ (hci_conn_count(data->hdev) ||
+ test_bit(HCI_INQUIRY, &data->hdev->flags) ||
+ hci_dev_test_flag(data->hdev, HCI_LE_SCAN)))
return -EBUSY;
if (data->suspend_count++)
--
2.25.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Bluetooth: btusb: Reject autosuspend if HCI inquiry or LE scan is active
2026-01-07 2:48 [PATCH] Bluetooth: btusb: Reject autosuspend if HCI inquiry or LE scan is active Linmao Li
@ 2026-01-07 14:47 ` Luiz Augusto von Dentz
2026-01-08 2:06 ` [PATCH v2] Bluetooth: btusb: Reject autosuspend if discovery " Linmao Li
0 siblings, 1 reply; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2026-01-07 14:47 UTC (permalink / raw)
To: Linmao Li; +Cc: linux-bluetooth, marcel, linux-kernel
Hi Linmao,
On Tue, Jan 6, 2026 at 9:48 PM Linmao Li <lilinmao@kylinos.cn> wrote:
>
> If USB autosuspend occurs while BR/EDR inquiry or LE scan is active,
> the ongoing HCI operation may not complete successfully. On some
> devices, this can leave discovery.state stuck in DISCOVERY_FINDING.
>
> Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
> ---
> drivers/bluetooth/btusb.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> index ded09e94d296..885c3d8c0a10 100644
> --- a/drivers/bluetooth/btusb.c
> +++ b/drivers/bluetooth/btusb.c
> @@ -4469,10 +4469,13 @@ static int btusb_suspend(struct usb_interface *intf, pm_message_t message)
>
> BT_DBG("intf %p", intf);
>
> - /* Don't auto-suspend if there are connections; external suspend calls
> - * shall never fail.
> + /* Don't auto-suspend if there are connections or HCI operations in
> + * progress; external suspend calls shall never fail.
> */
> - if (PMSG_IS_AUTO(message) && hci_conn_count(data->hdev))
> + if (PMSG_IS_AUTO(message) &&
> + (hci_conn_count(data->hdev) ||
> + test_bit(HCI_INQUIRY, &data->hdev->flags) ||
> + hci_dev_test_flag(data->hdev, HCI_LE_SCAN)))
We shall probably use hci_discovery_active instead of testing
individual bits like above.
> return -EBUSY;
>
> if (data->suspend_count++)
> --
> 2.25.1
>
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2] Bluetooth: btusb: Reject autosuspend if discovery is active
2026-01-07 14:47 ` Luiz Augusto von Dentz
@ 2026-01-08 2:06 ` Linmao Li
2026-01-08 2:52 ` Linmao Li
0 siblings, 1 reply; 9+ messages in thread
From: Linmao Li @ 2026-01-08 2:06 UTC (permalink / raw)
To: linux-bluetooth; +Cc: marcel, luiz.dentz, linux-kernel, Linmao Li
If USB autosuspend occurs while discovery is active, the ongoing
HCI operation may not complete successfully. On some devices, this
can leave discovery.state stuck in DISCOVERY_FINDING.
Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
---
drivers/bluetooth/btusb.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index ded09e94d296..565e276be3b2 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -4469,10 +4469,11 @@ static int btusb_suspend(struct usb_interface *intf, pm_message_t message)
BT_DBG("intf %p", intf);
- /* Don't auto-suspend if there are connections; external suspend calls
- * shall never fail.
+ /* Don't auto-suspend if there are connections or discovery in
+ * progress; external suspend calls shall never fail.
*/
- if (PMSG_IS_AUTO(message) && hci_conn_count(data->hdev))
+ if (PMSG_IS_AUTO(message) &&
+ (hci_conn_count(data->hdev) || hci_discovery_active(data->hdev)))
return -EBUSY;
if (data->suspend_count++)
--
2.25.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] Bluetooth: btusb: Reject autosuspend if discovery is active
2026-01-08 2:06 ` [PATCH v2] Bluetooth: btusb: Reject autosuspend if discovery " Linmao Li
@ 2026-01-08 2:52 ` Linmao Li
2026-01-08 15:22 ` Luiz Augusto von Dentz
0 siblings, 1 reply; 9+ messages in thread
From: Linmao Li @ 2026-01-08 2:52 UTC (permalink / raw)
To: luiz.dentz; +Cc: marcel, linux-kernel, linux-bluetooth
在 2026/1/8 10:06, Linmao Li 写道:
> If USB autosuspend occurs while discovery is active, the ongoing
> HCI operation may not complete successfully. On some devices, this
> can leave discovery.state stuck in DISCOVERY_FINDING.
>
> Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
> ---
> drivers/bluetooth/btusb.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> index ded09e94d296..565e276be3b2 100644
> --- a/drivers/bluetooth/btusb.c
> +++ b/drivers/bluetooth/btusb.c
> @@ -4469,10 +4469,11 @@ static int btusb_suspend(struct usb_interface *intf, pm_message_t message)
>
> BT_DBG("intf %p", intf);
>
> - /* Don't auto-suspend if there are connections; external suspend calls
> - * shall never fail.
> + /* Don't auto-suspend if there are connections or discovery in
> + * progress; external suspend calls shall never fail.
> */
> - if (PMSG_IS_AUTO(message) && hci_conn_count(data->hdev))
> + if (PMSG_IS_AUTO(message) &&
> + (hci_conn_count(data->hdev) || hci_discovery_active(data->hdev)))
> return -EBUSY;
>
> if (data->suspend_count++)
Hi Luiz,
I found that hci_discovery_active() is not exported, so btusb as a
module cannot use it:
ERROR: modpost: "hci_discovery_active" [drivers/bluetooth/btusb.ko]
undefined!
Should I send a separate patch to export hci_discovery_active(), or
revert to v1 using test_bit(HCI_INQUIRY) and hci_dev_test_flag(HCI_LE_SCAN)?
Best regards,
Linmao
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] Bluetooth: btusb: Reject autosuspend if discovery is active
2026-01-08 2:52 ` Linmao Li
@ 2026-01-08 15:22 ` Luiz Augusto von Dentz
2026-01-09 2:05 ` [PATCH v3 0/2] " Linmao Li
0 siblings, 1 reply; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2026-01-08 15:22 UTC (permalink / raw)
To: Linmao Li; +Cc: marcel, linux-kernel, linux-bluetooth
Hi Linmao,
On Wed, Jan 7, 2026 at 9:53 PM Linmao Li <lilinmao@kylinos.cn> wrote:
>
> 在 2026/1/8 10:06, Linmao Li 写道:
>
> > If USB autosuspend occurs while discovery is active, the ongoing
> > HCI operation may not complete successfully. On some devices, this
> > can leave discovery.state stuck in DISCOVERY_FINDING.
> >
> > Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
> > ---
> > drivers/bluetooth/btusb.c | 7 ++++---
> > 1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> > index ded09e94d296..565e276be3b2 100644
> > --- a/drivers/bluetooth/btusb.c
> > +++ b/drivers/bluetooth/btusb.c
> > @@ -4469,10 +4469,11 @@ static int btusb_suspend(struct usb_interface *intf, pm_message_t message)
> >
> > BT_DBG("intf %p", intf);
> >
> > - /* Don't auto-suspend if there are connections; external suspend calls
> > - * shall never fail.
> > + /* Don't auto-suspend if there are connections or discovery in
> > + * progress; external suspend calls shall never fail.
> > */
> > - if (PMSG_IS_AUTO(message) && hci_conn_count(data->hdev))
> > + if (PMSG_IS_AUTO(message) &&
> > + (hci_conn_count(data->hdev) || hci_discovery_active(data->hdev)))
> > return -EBUSY;
> >
> > if (data->suspend_count++)
> Hi Luiz,
>
> I found that hci_discovery_active() is not exported, so btusb as a
> module cannot use it:
>
> ERROR: modpost: "hci_discovery_active" [drivers/bluetooth/btusb.ko]
> undefined!
>
> Should I send a separate patch to export hci_discovery_active(), or
> revert to v1 using test_bit(HCI_INQUIRY) and hci_dev_test_flag(HCI_LE_SCAN)?
Just add a patch exporting it.
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3 0/2] Bluetooth: btusb: Reject autosuspend if discovery is active
2026-01-08 15:22 ` Luiz Augusto von Dentz
@ 2026-01-09 2:05 ` Linmao Li
2026-01-09 2:05 ` [PATCH v3 1/2] Bluetooth: hci_core: Export hci_discovery_active Linmao Li
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Linmao Li @ 2026-01-09 2:05 UTC (permalink / raw)
To: linux-bluetooth; +Cc: marcel, luiz.dentz, linux-kernel, Linmao Li
This series fixes an issue where USB autosuspend during discovery
can leave the HCI state machine in an inconsistent state.
v3:
- Export hci_discovery_active() in patch 1
- Use hci_discovery_active() in btusb in patch 2
v2:
- Use hci_discovery_active() instead of testing individual bits
(Luiz Augusto von Dentz)
Linmao Li (2):
Bluetooth: hci_core: Export hci_discovery_active
Bluetooth: btusb: Reject autosuspend if discovery is active
drivers/bluetooth/btusb.c | 7 ++++---
net/bluetooth/hci_core.c | 1 +
2 files changed, 5 insertions(+), 3 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3 1/2] Bluetooth: hci_core: Export hci_discovery_active
2026-01-09 2:05 ` [PATCH v3 0/2] " Linmao Li
@ 2026-01-09 2:05 ` Linmao Li
2026-01-09 2:05 ` [PATCH v3 2/2] Bluetooth: btusb: Reject autosuspend if discovery is active Linmao Li
2026-01-12 20:58 ` [PATCH v3 0/2] " patchwork-bot+bluetooth
2 siblings, 0 replies; 9+ messages in thread
From: Linmao Li @ 2026-01-09 2:05 UTC (permalink / raw)
To: linux-bluetooth; +Cc: marcel, luiz.dentz, linux-kernel, Linmao Li
Export hci_discovery_active() so it can be used by bluetooth
drivers built as modules.
Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
---
net/bluetooth/hci_core.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 8ccec73dce45..b069607b145b 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -117,6 +117,7 @@ bool hci_discovery_active(struct hci_dev *hdev)
return false;
}
}
+EXPORT_SYMBOL(hci_discovery_active);
void hci_discovery_set_state(struct hci_dev *hdev, int state)
{
--
2.25.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3 2/2] Bluetooth: btusb: Reject autosuspend if discovery is active
2026-01-09 2:05 ` [PATCH v3 0/2] " Linmao Li
2026-01-09 2:05 ` [PATCH v3 1/2] Bluetooth: hci_core: Export hci_discovery_active Linmao Li
@ 2026-01-09 2:05 ` Linmao Li
2026-01-12 20:58 ` [PATCH v3 0/2] " patchwork-bot+bluetooth
2 siblings, 0 replies; 9+ messages in thread
From: Linmao Li @ 2026-01-09 2:05 UTC (permalink / raw)
To: linux-bluetooth; +Cc: marcel, luiz.dentz, linux-kernel, Linmao Li
If USB autosuspend occurs while discovery is active, the ongoing
HCI operation may not complete successfully. On some devices, this
can leave discovery.state stuck in DISCOVERY_FINDING.
Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
---
drivers/bluetooth/btusb.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index ded09e94d296..565e276be3b2 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -4469,10 +4469,11 @@ static int btusb_suspend(struct usb_interface *intf, pm_message_t message)
BT_DBG("intf %p", intf);
- /* Don't auto-suspend if there are connections; external suspend calls
- * shall never fail.
+ /* Don't auto-suspend if there are connections or discovery in
+ * progress; external suspend calls shall never fail.
*/
- if (PMSG_IS_AUTO(message) && hci_conn_count(data->hdev))
+ if (PMSG_IS_AUTO(message) &&
+ (hci_conn_count(data->hdev) || hci_discovery_active(data->hdev)))
return -EBUSY;
if (data->suspend_count++)
--
2.25.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 0/2] Bluetooth: btusb: Reject autosuspend if discovery is active
2026-01-09 2:05 ` [PATCH v3 0/2] " Linmao Li
2026-01-09 2:05 ` [PATCH v3 1/2] Bluetooth: hci_core: Export hci_discovery_active Linmao Li
2026-01-09 2:05 ` [PATCH v3 2/2] Bluetooth: btusb: Reject autosuspend if discovery is active Linmao Li
@ 2026-01-12 20:58 ` patchwork-bot+bluetooth
2 siblings, 0 replies; 9+ messages in thread
From: patchwork-bot+bluetooth @ 2026-01-12 20:58 UTC (permalink / raw)
To: Linmao Li; +Cc: linux-bluetooth, marcel, luiz.dentz, linux-kernel
Hello:
This series was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:
On Fri, 9 Jan 2026 10:05:36 +0800 you wrote:
> This series fixes an issue where USB autosuspend during discovery
> can leave the HCI state machine in an inconsistent state.
>
> v3:
> - Export hci_discovery_active() in patch 1
> - Use hci_discovery_active() in btusb in patch 2
>
> [...]
Here is the summary with links:
- [v3,1/2] Bluetooth: hci_core: Export hci_discovery_active
https://git.kernel.org/bluetooth/bluetooth-next/c/e133883028d0
- [v3,2/2] Bluetooth: btusb: Reject autosuspend if discovery is active
https://git.kernel.org/bluetooth/bluetooth-next/c/2e5da9653691
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-01-12 21:01 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-07 2:48 [PATCH] Bluetooth: btusb: Reject autosuspend if HCI inquiry or LE scan is active Linmao Li
2026-01-07 14:47 ` Luiz Augusto von Dentz
2026-01-08 2:06 ` [PATCH v2] Bluetooth: btusb: Reject autosuspend if discovery " Linmao Li
2026-01-08 2:52 ` Linmao Li
2026-01-08 15:22 ` Luiz Augusto von Dentz
2026-01-09 2:05 ` [PATCH v3 0/2] " Linmao Li
2026-01-09 2:05 ` [PATCH v3 1/2] Bluetooth: hci_core: Export hci_discovery_active Linmao Li
2026-01-09 2:05 ` [PATCH v3 2/2] Bluetooth: btusb: Reject autosuspend if discovery is active Linmao Li
2026-01-12 20:58 ` [PATCH v3 0/2] " patchwork-bot+bluetooth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®