* [PATCH AUTOSEL 5.10 15/15] Bluetooth: hci_uart: fix race during initialization
[not found] <20250403191002.2678588-1-sashal@kernel.org>
@ 2025-04-03 19:10 ` Sasha Levin
2025-04-18 17:03 ` Pavel Machek
0 siblings, 1 reply; 2+ messages in thread
From: Sasha Levin @ 2025-04-03 19:10 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Arseniy Krasnov, Luiz Augusto von Dentz, Sasha Levin, marcel,
luiz.dentz, linux-bluetooth
From: Arseniy Krasnov <avkrasnov@salutedevices.com>
[ Upstream commit 366ceff495f902182d42b6f41525c2474caf3f9a ]
'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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/bluetooth/hci_ldisc.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index e7d78937f7d6b..8ca0ac3a440c9 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -706,12 +706,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;
}
--
2.39.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH AUTOSEL 5.10 15/15] Bluetooth: hci_uart: fix race during initialization
2025-04-03 19:10 ` [PATCH AUTOSEL 5.10 15/15] Bluetooth: hci_uart: fix race during initialization Sasha Levin
@ 2025-04-18 17:03 ` Pavel Machek
0 siblings, 0 replies; 2+ messages in thread
From: Pavel Machek @ 2025-04-18 17:03 UTC (permalink / raw)
To: Sasha Levin
Cc: linux-kernel, stable, Arseniy Krasnov, Luiz Augusto von Dentz,
marcel, luiz.dentz, linux-bluetooth
[-- Attachment #1: Type: text/plain, Size: 1420 bytes --]
Hi!
> From: Arseniy Krasnov <avkrasnov@salutedevices.com>
>
> [ Upstream commit 366ceff495f902182d42b6f41525c2474caf3f9a ]
>
> '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()'.
Ok, but do we need to adjust the error handling?
> +++ b/drivers/bluetooth/hci_ldisc.c
> @@ -706,12 +706,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;
> }
Should we clear the bit in the error path to undo the effects?
Best regards,
Pavel
--
DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-04-18 17:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20250403191002.2678588-1-sashal@kernel.org>
2025-04-03 19:10 ` [PATCH AUTOSEL 5.10 15/15] Bluetooth: hci_uart: fix race during initialization Sasha Levin
2025-04-18 17:03 ` Pavel Machek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox