Re: [PATCH] net: bluetooth: hci_sync: fix hci_le_create_conn_sync
From: Luiz Augusto von Dentz
Date: Thu Mar 05 2026 - 09:23:13 EST
Hi Michael,
On Thu, Mar 5, 2026 at 8:51 AM Michael Grzeschik
<m.grzeschik@xxxxxxxxxxxxxx> wrote:
>
> While introducing hci_le_create_conn_sync the functionality
> of hci_connect_le was ported to hci_le_create_conn_sync including
> the disable of the scan before starting the connection.
>
> When this code was run non synchronously the immediate call that was
> setting the flag HCI_LE_SCAN_INTERRUPTED had an impact. Since the
> completion handler for the LE_SCAN_DISABLE was not immediately called.
> In the completion handler of the LE_SCAN_DISABLE event, this flag is
> checked to set the state of the hdev to DISCOVERY_STOPPED.
>
> With the synchronised approach the later setting of the
> HCI_LE_SCAN_INTERRUPTED flag has not the same effect. The completion
> handler would immediately fire in the LE_SCAN_DISABLE call, check for
> the flag, which is then not yet set and do nothing.
>
> To fix this issue and make the function call work as before, we move the
> setting of the flag HCI_LE_SCAN_INTERRUPTED before disabling the scan.
>
> Fixes: Bluetooth: hci_sync: Add hci_le_create_conn_sync ('8e8b92ee60de5341e9db83c11f75a525e555e2b3')
> Signed-off-by: Michael Grzeschik <m.grzeschik@xxxxxxxxxxxxxx>
> ---
> net/bluetooth/hci_sync.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
> index 121dbc8208ec231210505135187e769028c17483..3166914b0d6ce3e56ced2f9a7914427296d38c48 100644
> --- a/net/bluetooth/hci_sync.c
> +++ b/net/bluetooth/hci_sync.c
> @@ -6627,8 +6627,8 @@ static int hci_le_create_conn_sync(struct hci_dev *hdev, void *data)
> * state.
> */
> if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) {
> - hci_scan_disable_sync(hdev);
> hci_dev_set_flag(hdev, HCI_LE_SCAN_INTERRUPTED);
> + hci_scan_disable_sync(hdev);
> }
The change is probably correct but now I wonder if we should even keep
the HCI_LE_SCAN_INTERRUPTED because with the cmd sync we could
actually do wait for the scan to be disabled so we might as well do
hci_discovery_set_state(hdev, DISCOVERY_STOPPED) after
hci_scan_disable_sync completes, anyway I can make the change on top
of yours since I don't think we want to backport such a change since
it won't be a one liner like the above.
> /* Update random address, but set require_privacy to false so
>
> ---
> base-commit: c107785c7e8dbabd1c18301a1c362544b5786282
> change-id: 20260305-bluetooth-fixes-b2c85a0aeb2a
>
> Best regards,
> --
> Michael Grzeschik <m.grzeschik@xxxxxxxxxxxxxx>
>
--
Luiz Augusto von Dentz