Re: [PATCH v2] Bluetooth: hci_serdev: stop write_work before closing the port

From: Zhao Li

Date: Sat Nov 21 2026 - 07:28:59 EST


On Fri, Nov 20, 2026 at 02:39:41PM +0100, Loic Poulain wrote:
> > + cancel_work_sync(&hu->write_work);
> > + clear_bit(HCI_UART_SENDING, &hu->tx_state);
> > + clear_bit(HCI_UART_TX_WAKEUP, &hu->tx_state);
>
> Looks like you are mostly re-doing what has already been done in
> hci_uart_flush()...
> Wouldn't it be simpler to have a hci_uart_flush parameter to not
> reschedule tx on flush?

Good point. The only reason hci_uart_close() has to stop TX a second
time is that hci_uart_flush() unconditionally re-enables write_work at
the end.

Skipping just the final wakeup replay wouldn't be enough, though. Once
hci_uart_flush() re-enables write_work and clears HCI_UART_SENDING, a
serdev write_wakeup callback can still queue write_work before
serdev_device_close() runs.

Instead, we can split out a __hci_uart_flush(hdev, bool resume_tx)
helper (since hci_uart_flush() itself is the hdev->flush callback):

- Normal flushes pass resume_tx = true and behave as today.
- With HCI_QUIRK_NON_PERSISTENT_SETUP, hci_uart_close() passes
resume_tx = false, leaving write_work disabled and HCI_UART_SENDING
set across the close.
- After clearing HCI_UART_PROTO_READY under hu->proto_lock (to drain
in-flight wakeups) and calling serdev_device_close(), hci_uart_close()
clears HCI_UART_TX_WAKEUP, re-enables write_work, and clears
HCI_UART_SENDING for the next open.

That drops the duplicate cancel_work_sync() and tx_skb cleanup while
keeping write_work completely disabled until the port is closed.

I'll send a v3 along these lines.

Thanks,
Zhao