* [PATCH] Bluetooth: hci_h5: Avoid clearing the escape bit for ordinary bytes
@ 2026-09-07 15:08 Xuhua Zhang
2026-09-08 16:30 ` patchwork-bot+bluetooth
0 siblings, 1 reply; 2+ messages in thread
From: Xuhua Zhang @ 2026-09-07 15:08 UTC (permalink / raw)
To: marcel, luiz.dentz; +Cc: linux-bluetooth, linux-kernel, Xuhua Zhang
h5_unslip_one_byte() calls test_and_clear_bit() for every byte other than
an initial SLIP escape byte, even when H5_RX_ESC is already clear. This
performs an unnecessary atomic read-modify-write on the ordinary-byte
receive path. On x86, it emits a locked btr instruction for each such
byte.
Test H5_RX_ESC first and clear it only when consuming an escaped byte.
Handle an initial SLIP escape byte in the alternative branch. The HCI
UART receive callbacks are serialized by the TTY layer, and H5_RX_ESC
is only changed by receive processing and initialization, so there is
no need to atomically test and clear it in one operation.
Keep set_bit() and clear_bit() atomic because other bits in h5->flags
can be updated by the transmit path concurrently. Escape decoding and
invalid-escape recovery remain unchanged.
Signed-off-by: Xuhua Zhang <zhangxuhua@kylinsec.com.cn>
---
drivers/bluetooth/hci_h5.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c
index b1999e14aade..37f4d9327e72 100644
--- a/drivers/bluetooth/hci_h5.c
+++ b/drivers/bluetooth/hci_h5.c
@@ -543,12 +543,8 @@ static void h5_unslip_one_byte(struct h5 *h5, unsigned char c)
const u8 delim = SLIP_DELIMITER, esc = SLIP_ESC;
const u8 *byte = &c;
- if (!test_bit(H5_RX_ESC, &h5->flags) && c == SLIP_ESC) {
- set_bit(H5_RX_ESC, &h5->flags);
- return;
- }
-
- if (test_and_clear_bit(H5_RX_ESC, &h5->flags)) {
+ if (test_bit(H5_RX_ESC, &h5->flags)) {
+ clear_bit(H5_RX_ESC, &h5->flags);
switch (c) {
case SLIP_ESC_DELIM:
byte = &delim;
@@ -561,6 +557,9 @@ static void h5_unslip_one_byte(struct h5 *h5, unsigned char c)
h5_reset_rx(h5);
return;
}
+ } else if (c == SLIP_ESC) {
+ set_bit(H5_RX_ESC, &h5->flags);
+ return;
}
skb_put_data(h5->rx_skb, byte, 1);
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Bluetooth: hci_h5: Avoid clearing the escape bit for ordinary bytes
2026-09-07 15:08 [PATCH] Bluetooth: hci_h5: Avoid clearing the escape bit for ordinary bytes Xuhua Zhang
@ 2026-09-08 16:30 ` patchwork-bot+bluetooth
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+bluetooth @ 2026-09-08 16:30 UTC (permalink / raw)
To: Xuhua Zhang; +Cc: marcel, luiz.dentz, linux-bluetooth, linux-kernel
Hello:
This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:
On Mon, 7 Sep 2026 23:08:08 +0800 you wrote:
> h5_unslip_one_byte() calls test_and_clear_bit() for every byte other than
> an initial SLIP escape byte, even when H5_RX_ESC is already clear. This
> performs an unnecessary atomic read-modify-write on the ordinary-byte
> receive path. On x86, it emits a locked btr instruction for each such
> byte.
>
> Test H5_RX_ESC first and clear it only when consuming an escaped byte.
> Handle an initial SLIP escape byte in the alternative branch. The HCI
> UART receive callbacks are serialized by the TTY layer, and H5_RX_ESC
> is only changed by receive processing and initialization, so there is
> no need to atomically test and clear it in one operation.
>
> [...]
Here is the summary with links:
- Bluetooth: hci_h5: Avoid clearing the escape bit for ordinary bytes
https://git.kernel.org/bluetooth/bluetooth-next/c/676cc47454c4
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-08 16:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-07 15:08 [PATCH] Bluetooth: hci_h5: Avoid clearing the escape bit for ordinary bytes Xuhua Zhang
2026-09-08 16:30 ` patchwork-bot+bluetooth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®