Skip to content

Commit

Permalink
Bluetooth: hci_uart: fix race during initialization
Browse files Browse the repository at this point in the history
'hci_register_dev()' calls power up function, which is executed by
kworker - 'hci_power_on()'. This function does access to bluetooth chip
using callbacks from 'hci_ldisc.c', for example 'hci_uart_send_frame()'.
Now 'hci_uart_send_frame()' checks 'HCI_UART_PROTO_READY' bit set, and
if not - it fails. Problem is that 'HCI_UART_PROTO_READY' is set after
'hci_register_dev()', and there is tiny chance that 'hci_power_on()' will
be executed before setting this bit. In that case HCI init logic fails.

Patch moves setting of 'HCI_UART_PROTO_READY' before calling function
'hci_uart_register_dev()'.

Signed-off-by: Arseniy Krasnov <avkrasnov@salutedevices.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
  • Loading branch information
Arseniy Krasnov authored and Luiz Augusto von Dentz committed Mar 25, 2025
1 parent bb3569a commit 366ceff
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/bluetooth/hci_ldisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,12 +707,13 @@ static int hci_uart_set_proto(struct hci_uart *hu, int id)

hu->proto = p;

set_bit(HCI_UART_PROTO_READY, &hu->flags);

err = hci_uart_register_dev(hu);
if (err) {
return err;
}

set_bit(HCI_UART_PROTO_READY, &hu->flags);
return 0;
}

Expand Down

0 comments on commit 366ceff

Please sign in to comment.