* [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
@ 2026-11-16 16:26 ` Michael McAllister
2026-11-18 12:47 ` Zhao Li
2026-11-16 16:26 ` [PATCH v3 5/5] Bluetooth: qca: Power off WCN3950 Michael McAllister
` (4 subsequent siblings)
5 siblings, 1 reply; 15+ 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] 15+ messages in thread* Re: [PATCH v3 2/5] Bluetooth: hci_serdev: Track whether the serial port is open
2026-11-16 16:26 ` [PATCH v3 2/5] Bluetooth: hci_serdev: Track whether the serial port is open Michael McAllister
@ 2026-11-18 12:47 ` Zhao Li
0 siblings, 0 replies; 15+ messages in thread
From: Zhao Li @ 2026-11-18 12:47 UTC (permalink / raw)
To: Michael McAllister
Cc: Marcel Holtmann, Luiz Augusto von Dentz, brgl, linux-bluetooth,
linux-arm-msm, linux-kernel, quic_bgodavar, lumag, mka,
markus.probst, shuai.zhang
Hi Michael,
The hci_uart_close() hunk touches the quirk branch that clears
HCI_UART_PROTO_READY and closes the port. That branch has a separate
race: it clears the flag without hu->proto_lock and closes the port
without waiting for write_work, so a transmit that is still queued can
reach the tty while the port is being closed.
hci_uart_unregister_device() already clears the flag under
percpu_down_write() and calls cancel_work_sync() first.
Your patch does not change the ordering, so I think it is better kept
as is. I will send a separate fix for the close path. It changes one
context line of your hunk (the close call), so it will need a trivial
rebase on whichever series lands first. If you prefer, fold it into
your series and I will send it to you.
Zhao Li
^ permalink raw reply [flat|nested] 15+ messages in thread
* [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 ` [PATCH v3 2/5] Bluetooth: hci_serdev: Track whether the serial port is open Michael McAllister
@ 2026-11-16 16:26 ` Michael McAllister
2026-11-16 16:26 ` [PATCH v3 4/5] Bluetooth: qca: Handle failed power-pulse writes Michael McAllister
` (3 subsequent siblings)
5 siblings, 0 replies; 15+ 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] 15+ 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
2026-11-16 16:26 ` [PATCH v3 2/5] Bluetooth: hci_serdev: Track whether the serial port is open Michael McAllister
2026-11-16 16:26 ` [PATCH v3 5/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
` (2 subsequent siblings)
5 siblings, 0 replies; 15+ 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] 15+ 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
` (2 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
2026-11-16 16:26 ` [PATCH v3 1/5] Bluetooth: hci_serdev: Unregister HCI before freeing the TX buffer Michael McAllister
2026-11-23 15:38 ` [PATCH v3 0/5] " Bartosz Golaszewski
5 siblings, 0 replies; 15+ 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] 15+ 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
` (3 preceding siblings ...)
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-23 15:38 ` [PATCH v3 0/5] " Bartosz Golaszewski
5 siblings, 1 reply; 15+ 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] 15+ messages in thread* Re: [PATCH v3 0/5] Bluetooth: qca: Power off WCN3950
2026-11-16 16:26 [PATCH v3 0/5] Bluetooth: qca: Power off WCN3950 Michael McAllister
` (4 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-23 15:38 ` Bartosz Golaszewski
2026-11-26 18:59 ` [PATCH v4 0/4] Bluetooth: qca: Power off WCN3950 safely Michael McAllister
5 siblings, 1 reply; 15+ messages in thread
From: Bartosz Golaszewski @ 2026-11-23 15:38 UTC (permalink / raw)
To: Michael McAllister
Cc: Marcel Holtmann, Luiz Augusto von Dentz, linux-bluetooth,
linux-arm-msm, linux-kernel, quic_bgodavar, lumag, mka,
markus.probst, shuai.zhang, enderaoelyther
On Mon, Nov 16, 2026 at 04:26:21PM +0000, Michael McAllister wrote:
> Hi Zhao, thanks for the review. I've split the serdev unregister fix into
> its own patch as requested.
>
> The final code is unchanged from v2, which I tested on my Moto G10. I've
> also build-tested the standalone fix and rerun the regression tests.
>
> Thanks,
> Michael
>
> Changes in v3:
> - Split the generic unregister fix out as patch 1, with a stable Cc.
> - Keep the port-state-dependent TX flush with the QCA power-off change.
> - No changes to the final source tree.
>
> Patch 1 applies independently. The remaining series keeps the separate
> Marvell port-lifetime fix as a prerequisite, as in v2.
Then send patch 1 separately. As it is, this series doesn't apply on top
of linux-next.
Bart
^ permalink raw reply [flat|nested] 15+ messages in thread* [PATCH v4 0/4] Bluetooth: qca: Power off WCN3950 safely
2026-11-23 15:38 ` [PATCH v3 0/5] " Bartosz Golaszewski
@ 2026-11-26 18:59 ` Michael McAllister
2026-11-26 18:59 ` [PATCH v4 3/4] Bluetooth: qca: Handle failed power-pulse writes Michael McAllister
` (3 more replies)
0 siblings, 4 replies; 15+ messages in thread
From: Michael McAllister @ 2026-11-26 18:59 UTC (permalink / raw)
To: marcel, luiz.dentz
Cc: brgl, enderaoelyther, linux-arm-msm, linux-bluetooth,
linux-kernel, lumag, markus.probst, mka, phone-devel,
quic_bgodavar, shuai.zhang, zhaojinming, me
Hi,
On my Moto G10, turning Bluetooth off leaves its four regulator votes
enabled. This series adds the missing WCN3950 power-off handling and fixes
the UART teardown ordering needed to send the pulse safely.
I've split the unregister/TX fix out as requested and rebased these four
patches onto the current Bluetooth tree, including Zhao's flush and close
changes. This series depends on that standalone fix.
Tested as a module backport on my Moto G10 running 7.2.9: six Bluetooth
off/on cycles and driver unbind/rebind with Bluetooth both off and on.
The four regulator votes dropped to zero on every power-off, and Bluetooth
came back on each time. One firmware download needed a retry and recovered;
the original driver also needed retries in the same six-cycle test.
Thanks,
Michael
Changes in v4:
- Submit the unregister/TX fix separately from this series.
- Rebase onto f57f78086ab5, retaining the merged flush and close fixes.
- Move controller TX flushing into the standalone unregister fix.
- The separate Marvell prerequisite from v3 is now upstream.
v3: https://lore.kernel.org/179484638195.54009.1916641645532262287.wcn3950-poweroff-v3-0@michaelmcallister.org/
Michael McAllister (4):
Bluetooth: hci_serdev: Track whether the serial port is open
Bluetooth: qca: Power off after unregistering the HCI device
Bluetooth: qca: Handle failed power-pulse writes
Bluetooth: qca: Power off WCN3950
drivers/bluetooth/hci_qca.c | 34 +++++++++-----------------------
drivers/bluetooth/hci_serdev.c | 36 +++++++++++++++++++++++++++-------
drivers/bluetooth/hci_uart.h | 3 +++
3 files changed, 41 insertions(+), 32 deletions(-)
base-commit: f57f78086ab54f3b3122fbaeba2c842ba7bb6d00
prerequisite-patch-id: 4f7b2f10b0911886f60ec40656c453138c3570f0
--
2.39.5
^ permalink raw reply [flat|nested] 15+ messages in thread* [PATCH v4 3/4] Bluetooth: qca: Handle failed power-pulse writes
2026-11-26 18:59 ` [PATCH v4 0/4] Bluetooth: qca: Power off WCN3950 safely Michael McAllister
@ 2026-11-26 18:59 ` Michael McAllister
2026-11-26 18:59 ` [PATCH v4 4/4] Bluetooth: qca: Power off WCN3950 Michael McAllister
` (2 subsequent siblings)
3 siblings, 0 replies; 15+ messages in thread
From: Michael McAllister @ 2026-11-26 18:59 UTC (permalink / raw)
To: marcel, luiz.dentz
Cc: brgl, enderaoelyther, linux-arm-msm, linux-bluetooth,
linux-kernel, lumag, markus.probst, mka, phone-devel,
quic_bgodavar, shuai.zhang, zhaojinming, me
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 53239b0ab..d341481cd 100644
--- a/drivers/bluetooth/hci_qca.c
+++ b/drivers/bluetooth/hci_qca.c
@@ -1426,9 +1426,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] 15+ messages in thread* [PATCH v4 4/4] Bluetooth: qca: Power off WCN3950
2026-11-26 18:59 ` [PATCH v4 0/4] Bluetooth: qca: Power off WCN3950 safely Michael McAllister
2026-11-26 18:59 ` [PATCH v4 3/4] Bluetooth: qca: Handle failed power-pulse writes Michael McAllister
@ 2026-11-26 18:59 ` Michael McAllister
2026-11-26 18:59 ` [PATCH v4 2/4] Bluetooth: qca: Power off after unregistering the HCI device Michael McAllister
2026-11-26 18:59 ` [PATCH v4 1/4] Bluetooth: hci_serdev: Track whether the serial port is open Michael McAllister
3 siblings, 0 replies; 15+ messages in thread
From: Michael McAllister @ 2026-11-26 18:59 UTC (permalink / raw)
To: marcel, luiz.dentz
Cc: brgl, enderaoelyther, linux-arm-msm, linux-bluetooth,
linux-kernel, lumag, markus.probst, mka, phone-devel,
quic_bgodavar, shuai.zhang, zhaojinming, me
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 d341481cd..898c7a980 100644
--- a/drivers/bluetooth/hci_qca.c
+++ b/drivers/bluetooth/hci_qca.c
@@ -2284,6 +2284,7 @@ static void qca_power_off(struct hci_uart *hu)
qcadev = serdev_device_get_drvdata(hu->serdev);
switch (soc_type) {
+ case QCA_WCN3950:
case QCA_WCN3988:
case QCA_WCN3990:
case QCA_WCN3991:
@@ -2304,6 +2305,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] 15+ messages in thread* [PATCH v4 2/4] Bluetooth: qca: Power off after unregistering the HCI device
2026-11-26 18:59 ` [PATCH v4 0/4] Bluetooth: qca: Power off WCN3950 safely Michael McAllister
2026-11-26 18:59 ` [PATCH v4 3/4] Bluetooth: qca: Handle failed power-pulse writes Michael McAllister
2026-11-26 18:59 ` [PATCH v4 4/4] Bluetooth: qca: Power off WCN3950 Michael McAllister
@ 2026-11-26 18:59 ` Michael McAllister
2026-11-26 18:59 ` [PATCH v4 1/4] Bluetooth: hci_serdev: Track whether the serial port is open Michael McAllister
3 siblings, 0 replies; 15+ messages in thread
From: Michael McAllister @ 2026-11-26 18:59 UTC (permalink / raw)
To: marcel, luiz.dentz
Cc: brgl, enderaoelyther, linux-arm-msm, linux-bluetooth,
linux-kernel, lumag, markus.probst, mka, phone-devel,
quic_bgodavar, shuai.zhang, zhaojinming, me
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.
Signed-off-by: Michael McAllister <me@michaelmcallister.org>
---
drivers/bluetooth/hci_qca.c | 23 ++---------------------
1 file changed, 2 insertions(+), 21 deletions(-)
diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
index 0f893f16a..53239b0ab 100644
--- a/drivers/bluetooth/hci_qca.c
+++ b/drivers/bluetooth/hci_qca.c
@@ -616,6 +616,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) {
@@ -2286,11 +2287,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);
}
@@ -2664,22 +2661,6 @@ static void qca_serdev_remove(struct serdev_device *serdev)
{
struct qca_serdev *qcadev = serdev_device_get_drvdata(serdev);
- 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 (qcadev->vregs_on)
- qca_power_off(&qcadev->serdev_hu);
- break;
- default:
- break;
- }
-
hci_uart_unregister_device(&qcadev->serdev_hu);
}
--
2.39.5
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v4 1/4] Bluetooth: hci_serdev: Track whether the serial port is open
2026-11-26 18:59 ` [PATCH v4 0/4] Bluetooth: qca: Power off WCN3950 safely Michael McAllister
` (2 preceding siblings ...)
2026-11-26 18:59 ` [PATCH v4 2/4] Bluetooth: qca: Power off after unregistering the HCI device Michael McAllister
@ 2026-11-26 18:59 ` Michael McAllister
2026-11-26 21:38 ` Bluetooth: qca: Power off WCN3950 safely bluez.test.bot
3 siblings, 1 reply; 15+ messages in thread
From: Michael McAllister @ 2026-11-26 18:59 UTC (permalink / raw)
To: marcel, luiz.dentz
Cc: brgl, enderaoelyther, linux-arm-msm, linux-bluetooth,
linux-kernel, lumag, markus.probst, mka, phone-devel,
quic_bgodavar, shuai.zhang, zhaojinming, me
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 flushing or closing the port during unregister.
Signed-off-by: Michael McAllister <me@michaelmcallister.org>
---
drivers/bluetooth/hci_qca.c | 4 ++--
drivers/bluetooth/hci_serdev.c | 36 +++++++++++++++++++++++++++-------
drivers/bluetooth/hci_uart.h | 3 +++
3 files changed, 34 insertions(+), 9 deletions(-)
diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
index d51db761f..0f893f16a 100644
--- a/drivers/bluetooth/hci_qca.c
+++ b/drivers/bluetooth/hci_qca.c
@@ -1758,14 +1758,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 dfa921afc..d4b8c3b61 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;
@@ -145,7 +168,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);
@@ -187,7 +210,7 @@ static int hci_uart_close(struct hci_dev *hdev)
clear_bit(HCI_UART_PROTO_READY, &hu->flags);
percpu_up_write(&hu->proto_lock);
- serdev_device_close(hu->serdev);
+ hci_uart_serdev_close(hu);
clear_bit(HCI_UART_TX_WAKEUP, &hu->tx_state);
enable_work(&hu->write_work);
@@ -351,7 +374,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;
@@ -422,7 +445,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;
@@ -470,7 +493,7 @@ void hci_uart_unregister_device(struct hci_uart *hu)
hu->tx_skb = NULL;
}
- if (proto_ready)
+ if (hu->serdev_open)
serdev_device_write_flush(hu->serdev);
/* Close the protocol before freeing hdev (intrinsically purges queues).
@@ -479,8 +502,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] 15+ messages in thread* RE: Bluetooth: qca: Power off WCN3950 safely
2026-11-26 18:59 ` [PATCH v4 1/4] Bluetooth: hci_serdev: Track whether the serial port is open Michael McAllister
@ 2026-11-26 21:38 ` bluez.test.bot
0 siblings, 0 replies; 15+ messages in thread
From: bluez.test.bot @ 2026-11-26 21:38 UTC (permalink / raw)
To: linux-bluetooth, me
[-- Attachment #1: Type: text/plain, Size: 858 bytes --]
This is an automated email and please do not reply to this email.
Dear Submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
While preparing the CI tests, the patches you submitted couldn't be applied to the current HEAD of the repository.
----- Output -----
error: patch failed: drivers/bluetooth/hci_serdev.c:470
error: drivers/bluetooth/hci_serdev.c: patch does not apply
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Please resolve the issue and submit the patches again.
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 15+ messages in thread