* [PATCH v3 5/5] Bluetooth: qca: Power off WCN3950
2026-11-16 16:26 [PATCH v3 0/5] Bluetooth: qca: Power off WCN3950 Michael McAllister
@ 2026-11-16 16:26 ` Michael McAllister
2026-11-16 16:26 ` [PATCH v3 3/5] Bluetooth: qca: Power off after unregistering the HCI device Michael McAllister
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Michael McAllister @ 2026-11-16 16:26 UTC (permalink / raw)
To: Marcel Holtmann, Luiz Augusto von Dentz
Cc: brgl, linux-bluetooth, linux-arm-msm, linux-kernel, quic_bgodavar,
lumag, mka, me, markus.probst, shuai.zhang, enderaoelyther
Turning Bluetooth off on the Moto G10 leaves the WCN3950 regulator
votes enabled. qca_power_off() handles the other WCN39xx controllers
but omits WCN3950 from both switches.
Add it to the existing power-off pulse and regulator-disable paths.
Fixes: d5712c511cb3 ("Bluetooth: qca: add WCN3950 support")
Signed-off-by: Michael McAllister <me@michaelmcallister.org>
---
drivers/bluetooth/hci_qca.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
index 6642af781..bd8cfe95c 100644
--- a/drivers/bluetooth/hci_qca.c
+++ b/drivers/bluetooth/hci_qca.c
@@ -2283,6 +2283,7 @@ static void qca_power_off(struct hci_uart *hu)
power = qcadev->bt_power;
switch (soc_type) {
+ case QCA_WCN3950:
case QCA_WCN3988:
case QCA_WCN3990:
case QCA_WCN3991:
@@ -2303,6 +2304,7 @@ static void qca_power_off(struct hci_uart *hu)
}
switch (soc_type) {
+ case QCA_WCN3950:
case QCA_WCN3988:
case QCA_WCN3990:
case QCA_WCN3991:
--
2.39.5
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v3 3/5] Bluetooth: qca: Power off after unregistering the HCI device
2026-11-16 16:26 [PATCH v3 0/5] Bluetooth: qca: Power off WCN3950 Michael McAllister
2026-11-16 16:26 ` [PATCH v3 5/5] " Michael McAllister
@ 2026-11-16 16:26 ` Michael McAllister
2026-11-16 16:26 ` [PATCH v3 1/5] Bluetooth: hci_serdev: Unregister HCI before freeing the TX buffer Michael McAllister
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Michael McAllister @ 2026-11-16 16:26 UTC (permalink / raw)
To: Marcel Holtmann, Luiz Augusto von Dentz
Cc: brgl, linux-bluetooth, linux-arm-msm, linux-kernel, quic_bgodavar,
lumag, mka, me, markus.probst, shuai.zhang, enderaoelyther
qca_serdev_remove() powers off while HCI setup and UART writes can still
be running. Leave power-off to qca_close(), after HCI unregistration and
write-work cancellation, while the serial transport is still available.
Check the actual port state before sending the power-off pulse, since
PROTO_READY is already clear during protocol cleanup. Start serdev
controllers in QCA_BT_OFF so registration failure does not send a pulse
before HCI allocation or power-on.
Flush controller TX after stopping UART work, before protocol and port
close, so previously accepted bytes are discarded rather than drained.
Signed-off-by: Michael McAllister <me@michaelmcallister.org>
---
drivers/bluetooth/hci_qca.c | 24 ++----------------------
drivers/bluetooth/hci_serdev.c | 3 +++
2 files changed, 5 insertions(+), 22 deletions(-)
diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
index 28e84fc24..ddbeb0787 100644
--- a/drivers/bluetooth/hci_qca.c
+++ b/drivers/bluetooth/hci_qca.c
@@ -620,6 +620,7 @@ static int qca_open(struct hci_uart *hu)
hu->priv = qca;
if (hu->serdev) {
+ set_bit(QCA_BT_OFF, &qca->flags);
qcadev = serdev_device_get_drvdata(hu->serdev);
switch (qcadev->btsoc_type) {
@@ -2285,11 +2286,7 @@ static void qca_power_off(struct hci_uart *hu)
case QCA_WCN3990:
case QCA_WCN3991:
case QCA_WCN3998:
- /* Both of these write to the serial port which may have
- * already been closed by hci_uart_close(), which closes
- * the port if HCI_QUIRK_NON_PERSISTENT_SETUP is set.
- */
- if (test_bit(HCI_UART_PROTO_READY, &hu->flags)) {
+ if (hu->serdev_open) {
host_set_baudrate(hu, 2400);
qca_send_power_pulse(hu, false);
}
@@ -2618,23 +2615,6 @@ static int qca_serdev_probe(struct serdev_device *serdev)
static void qca_serdev_remove(struct serdev_device *serdev)
{
struct qca_serdev *qcadev = serdev_device_get_drvdata(serdev);
- struct qca_power *power = qcadev->bt_power;
-
- switch (qcadev->btsoc_type) {
- case QCA_WCN3988:
- case QCA_WCN3990:
- case QCA_WCN3991:
- case QCA_WCN3998:
- case QCA_WCN6750:
- case QCA_QCA2066:
- case QCA_WCN6855:
- case QCA_WCN7850:
- if (power->vregs_on)
- qca_power_off(&qcadev->serdev_hu);
- break;
- default:
- break;
- }
hci_uart_unregister_device(&qcadev->serdev_hu);
}
diff --git a/drivers/bluetooth/hci_serdev.c b/drivers/bluetooth/hci_serdev.c
index f86d417b8..e279a7d61 100644
--- a/drivers/bluetooth/hci_serdev.c
+++ b/drivers/bluetooth/hci_serdev.c
@@ -464,6 +464,9 @@ void hci_uart_unregister_device(struct hci_uart *hu)
hu->tx_skb = NULL;
}
+ if (hu->serdev_open)
+ serdev_device_write_flush(hu->serdev);
+
/* Close the protocol before freeing hdev (intrinsically purges queues).
* Some protocol close handlers (e.g. qca_close) may still access the
* serdev device, so keep the serdev port open until this completes.
--
2.39.5
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v3 1/5] Bluetooth: hci_serdev: Unregister HCI before freeing the TX buffer
2026-11-16 16:26 [PATCH v3 0/5] Bluetooth: qca: Power off WCN3950 Michael McAllister
2026-11-16 16:26 ` [PATCH v3 5/5] " Michael McAllister
2026-11-16 16:26 ` [PATCH v3 3/5] Bluetooth: qca: Power off after unregistering the HCI device Michael McAllister
@ 2026-11-16 16:26 ` Michael McAllister
2026-11-16 19:44 ` Bluetooth: qca: Power off WCN3950 bluez.test.bot
2026-11-16 16:26 ` [PATCH v3 4/5] Bluetooth: qca: Handle failed power-pulse writes Michael McAllister
2026-11-16 16:26 ` [PATCH v3 2/5] Bluetooth: hci_serdev: Track whether the serial port is open Michael McAllister
4 siblings, 1 reply; 7+ messages in thread
From: Michael McAllister @ 2026-11-16 16:26 UTC (permalink / raw)
To: Marcel Holtmann, Luiz Augusto von Dentz
Cc: brgl, linux-bluetooth, linux-arm-msm, linux-kernel, quic_bgodavar,
lumag, mka, me, markus.probst, shuai.zhang, enderaoelyther
Unregister frees hu->tx_skb before hci_unregister_dev() waits for an
in-flight HCI close or reset. That path can still flush the same frame,
causing a use-after-free or double free.
Unregister HCI first, before clearing protocol readiness and cancelling
write_work. Skip the HCI flush and close callbacks during unregister;
the transport teardown frees the frame and closes the protocol and port
once setup and HCI close have finished.
Fixes: 21139b3ac62a ("Bluetooth: hci_serdev: Fix use-after-free in hci_uart_unregister_device()")
Cc: stable@vger.kernel.org
Signed-off-by: Michael McAllister <me@michaelmcallister.org>
---
drivers/bluetooth/hci_serdev.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/drivers/bluetooth/hci_serdev.c b/drivers/bluetooth/hci_serdev.c
index d2c48df34..e0e969228 100644
--- a/drivers/bluetooth/hci_serdev.c
+++ b/drivers/bluetooth/hci_serdev.c
@@ -97,6 +97,9 @@ static int hci_uart_flush(struct hci_dev *hdev)
BT_DBG("hdev %p serdev %p", hdev, hu->serdev);
+ if (hci_dev_test_flag(hdev, HCI_UNREGISTER))
+ return 0;
+
if (hu->tx_skb) {
kfree_skb(hu->tx_skb); hu->tx_skb = NULL;
}
@@ -144,6 +147,9 @@ static int hci_uart_close(struct hci_dev *hdev)
BT_DBG("hdev %p", hdev);
+ if (hci_dev_test_flag(hdev, HCI_UNREGISTER))
+ return 0;
+
if (!test_bit(HCI_UART_PROTO_READY, &hu->flags))
return 0;
@@ -402,6 +408,10 @@ void hci_uart_unregister_device(struct hci_uart *hu)
/* Wait for init_ready to finish to prevent registration races */
cancel_work_sync(&hu->init_ready);
+ /* Drain HCI setup before clearing protocol readiness. */
+ if (test_bit(HCI_UART_REGISTERED, &hu->flags))
+ hci_unregister_dev(hdev);
+
proto_ready = test_bit(HCI_UART_PROTO_READY, &hu->flags);
if (proto_ready) {
/* Clear HCI_UART_PROTO_READY under the write lock so a
@@ -423,17 +433,14 @@ void hci_uart_unregister_device(struct hci_uart *hu)
cancel_work_sync(&hu->write_work);
/* Free any partially transmitted frame left over by write_work now
- * that the transmit path is fully quiesced. hci_uart_close() would
- * skip hci_uart_flush() because HCI_UART_PROTO_READY is cleared.
+ * that the transmit path is fully quiesced. The HCI close and flush
+ * callbacks leave transport teardown to us during unregister.
*/
if (hu->tx_skb) {
kfree_skb(hu->tx_skb);
hu->tx_skb = NULL;
}
- if (test_bit(HCI_UART_REGISTERED, &hu->flags))
- hci_unregister_dev(hdev);
-
/* Close the protocol before freeing hdev (intrinsically purges queues).
* Some protocol close handlers (e.g. qca_close) may still access the
* serdev device, so keep the serdev port open until this completes.
--
2.39.5
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v3 4/5] Bluetooth: qca: Handle failed power-pulse writes
2026-11-16 16:26 [PATCH v3 0/5] Bluetooth: qca: Power off WCN3950 Michael McAllister
` (2 preceding siblings ...)
2026-11-16 16:26 ` [PATCH v3 1/5] Bluetooth: hci_serdev: Unregister HCI before freeing the TX buffer Michael McAllister
@ 2026-11-16 16:26 ` Michael McAllister
2026-11-16 16:26 ` [PATCH v3 2/5] Bluetooth: hci_serdev: Track whether the serial port is open Michael McAllister
4 siblings, 0 replies; 7+ messages in thread
From: Michael McAllister @ 2026-11-16 16:26 UTC (permalink / raw)
To: Marcel Holtmann, Luiz Augusto von Dentz
Cc: brgl, linux-bluetooth, linux-arm-msm, linux-kernel, quic_bgodavar,
lumag, mka, me, markus.probst, shuai.zhang, enderaoelyther
A failed UART write leaves hardware flow control disabled. A zero-byte
write is also treated as success even though no pulse was queued.
Require the one-byte pulse to be accepted and restore flow control on
the error path, returning -EIO for a zero-byte write.
Fixes: f9558270b85c ("Bluetooth: hci_qca: use wait_until_sent() for power pulses")
Signed-off-by: Michael McAllister <me@michaelmcallister.org>
---
drivers/bluetooth/hci_qca.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
index ddbeb0787..6642af781 100644
--- a/drivers/bluetooth/hci_qca.c
+++ b/drivers/bluetooth/hci_qca.c
@@ -1430,9 +1430,10 @@ static int qca_send_power_pulse(struct hci_uart *hu, bool on)
serdev_device_write_flush(hu->serdev);
hci_uart_set_flow_control(hu, true);
ret = serdev_device_write_buf(hu->serdev, &cmd, sizeof(cmd));
- if (ret < 0) {
+ if (ret != sizeof(cmd)) {
bt_dev_err(hu->hdev, "failed to send power pulse %02x", cmd);
- return ret;
+ hci_uart_set_flow_control(hu, false);
+ return ret < 0 ? ret : -EIO;
}
serdev_device_wait_until_sent(hu->serdev, timeout);
--
2.39.5
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v3 2/5] Bluetooth: hci_serdev: Track whether the serial port is open
2026-11-16 16:26 [PATCH v3 0/5] Bluetooth: qca: Power off WCN3950 Michael McAllister
` (3 preceding siblings ...)
2026-11-16 16:26 ` [PATCH v3 4/5] Bluetooth: qca: Handle failed power-pulse writes Michael McAllister
@ 2026-11-16 16:26 ` Michael McAllister
4 siblings, 0 replies; 7+ messages in thread
From: Michael McAllister @ 2026-11-16 16:26 UTC (permalink / raw)
To: Marcel Holtmann, Luiz Augusto von Dentz
Cc: brgl, linux-bluetooth, linux-arm-msm, linux-kernel, quic_bgodavar,
lumag, mka, me, markus.probst, shuai.zhang, enderaoelyther
HCI_UART_PROTO_READY is cleared before protocol close during unregister,
even though the serial port stays open. QCA needs to distinguish that
case from a port left closed by a failed setup reopen before sending
its power-off pulse.
Track the port state in the transport and QCA open/close helpers. Keep
the existing PROTO_READY handling for setup failures and use the actual
open state when closing the port during unregister.
Signed-off-by: Michael McAllister <me@michaelmcallister.org>
---
drivers/bluetooth/hci_qca.c | 4 ++--
drivers/bluetooth/hci_serdev.c | 34 ++++++++++++++++++++++++++++------
drivers/bluetooth/hci_uart.h | 3 +++
3 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
index d693e2842..28e84fc24 100644
--- a/drivers/bluetooth/hci_qca.c
+++ b/drivers/bluetooth/hci_qca.c
@@ -1762,14 +1762,14 @@ static void qca_port_close(struct hci_uart *hu)
* hci_uart_close() or hci_uart_unregister_device().
*/
if (test_and_clear_bit(HCI_UART_PROTO_READY, &hu->flags))
- serdev_device_close(hu->serdev);
+ hci_uart_serdev_close(hu);
}
static int qca_port_open(struct hci_uart *hu)
{
int ret;
- ret = serdev_device_open(hu->serdev);
+ ret = hci_uart_serdev_open(hu);
if (!ret)
set_bit(HCI_UART_PROTO_READY, &hu->flags);
diff --git a/drivers/bluetooth/hci_serdev.c b/drivers/bluetooth/hci_serdev.c
index e0e969228..f86d417b8 100644
--- a/drivers/bluetooth/hci_serdev.c
+++ b/drivers/bluetooth/hci_serdev.c
@@ -21,6 +21,29 @@
#include "hci_uart.h"
+int hci_uart_serdev_open(struct hci_uart *hu)
+{
+ int err;
+
+ if (hu->serdev_open)
+ return 0;
+
+ err = serdev_device_open(hu->serdev);
+ if (!err)
+ hu->serdev_open = true;
+
+ return err;
+}
+
+void hci_uart_serdev_close(struct hci_uart *hu)
+{
+ if (!hu->serdev_open)
+ return;
+
+ hu->serdev_open = false;
+ serdev_device_close(hu->serdev);
+}
+
static inline void hci_uart_tx_complete(struct hci_uart *hu, int pkt_type)
{
struct hci_dev *hdev = hu->hdev;
@@ -128,7 +151,7 @@ static int hci_uart_open(struct hci_dev *hdev)
* BT OFF. Upon next BT ON UART port should be opened.
*/
if (!test_bit(HCI_UART_PROTO_READY, &hu->flags)) {
- err = serdev_device_open(hu->serdev);
+ err = hci_uart_serdev_open(hu);
if (err)
return err;
set_bit(HCI_UART_PROTO_READY, &hu->flags);
@@ -162,7 +185,7 @@ static int hci_uart_close(struct hci_dev *hdev)
*/
if (hci_test_quirk(hdev, HCI_QUIRK_NON_PERSISTENT_SETUP)) {
clear_bit(HCI_UART_PROTO_READY, &hu->flags);
- serdev_device_close(hu->serdev);
+ hci_uart_serdev_close(hu);
}
return 0;
@@ -322,7 +345,7 @@ int hci_uart_register_device_priv(struct hci_uart *hu,
if (percpu_init_rwsem(&hu->proto_lock))
return -ENOMEM;
- err = serdev_device_open(hu->serdev);
+ err = hci_uart_serdev_open(hu);
if (err)
goto err_rwsem;
@@ -393,7 +416,7 @@ int hci_uart_register_device_priv(struct hci_uart *hu,
clear_bit(HCI_UART_PROTO_READY, &hu->flags);
p->close(hu);
err_open:
- serdev_device_close(hu->serdev);
+ hci_uart_serdev_close(hu);
err_rwsem:
percpu_free_rwsem(&hu->proto_lock);
return err;
@@ -447,8 +470,7 @@ void hci_uart_unregister_device(struct hci_uart *hu)
*/
hu->proto->close(hu);
- if (proto_ready)
- serdev_device_close(hu->serdev);
+ hci_uart_serdev_close(hu);
hci_free_dev(hdev);
diff --git a/drivers/bluetooth/hci_uart.h b/drivers/bluetooth/hci_uart.h
index 7fbe8dffa..2f8e346f3 100644
--- a/drivers/bluetooth/hci_uart.h
+++ b/drivers/bluetooth/hci_uart.h
@@ -66,6 +66,7 @@ struct hci_uart_proto {
struct hci_uart {
struct tty_struct *tty;
struct serdev_device *serdev;
+ bool serdev_open;
struct hci_dev *hdev;
unsigned long flags;
unsigned long hdev_flags;
@@ -112,6 +113,8 @@ static inline int hci_uart_register_device(struct hci_uart *hu,
}
void hci_uart_unregister_device(struct hci_uart *hu);
+int hci_uart_serdev_open(struct hci_uart *hu);
+void hci_uart_serdev_close(struct hci_uart *hu);
int hci_uart_tx_wakeup(struct hci_uart *hu);
int hci_uart_wait_until_sent(struct hci_uart *hu);
--
2.39.5
^ permalink raw reply related [flat|nested] 7+ messages in thread