Skip to content

Commit bbe6d14

Browse files
Claire Changgregkh
authored andcommitted
Bluetooth: hci_uart: Fix a race for write_work scheduling
[ Upstream commit afe0b1c ] In hci_uart_write_work, there is a loop/goto checking the value of HCI_UART_TX_WAKEUP. If HCI_UART_TX_WAKEUP is set again, it keeps trying hci_uart_dequeue; otherwise, it clears HCI_UART_SENDING and returns. In hci_uart_tx_wakeup, if HCI_UART_SENDING is already set, it sets HCI_UART_TX_WAKEUP, skips schedule_work and assumes the running/pending hci_uart_write_work worker will do hci_uart_dequeue properly. However, if the HCI_UART_SENDING check in hci_uart_tx_wakeup is done after the loop breaks, but before HCI_UART_SENDING is cleared in hci_uart_write_work, the schedule_work is skipped incorrectly. Fix this race by changing the order of HCI_UART_SENDING and HCI_UART_TX_WAKEUP modification. Fixes: 1da177e ("Linux-2.6.12-rc2") Fixes: 82f5169 ("Bluetooth: hci_uart: add serdev driver support library") Signed-off-by: Claire Chang <tientzu@chromium.org> Signed-off-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent fdbed2d commit bbe6d14

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

‎drivers/bluetooth/hci_ldisc.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,9 @@ int hci_uart_tx_wakeup(struct hci_uart *hu)
127127
if (!test_bit(HCI_UART_PROTO_READY, &hu->flags))
128128
goto no_schedule;
129129

130-
if (test_and_set_bit(HCI_UART_SENDING, &hu->tx_state)) {
131-
set_bit(HCI_UART_TX_WAKEUP, &hu->tx_state);
130+
set_bit(HCI_UART_TX_WAKEUP, &hu->tx_state);
131+
if (test_and_set_bit(HCI_UART_SENDING, &hu->tx_state))
132132
goto no_schedule;
133-
}
134133

135134
BT_DBG("");
136135

@@ -174,10 +173,10 @@ static void hci_uart_write_work(struct work_struct *work)
174173
kfree_skb(skb);
175174
}
176175

176+
clear_bit(HCI_UART_SENDING, &hu->tx_state);
177177
if (test_bit(HCI_UART_TX_WAKEUP, &hu->tx_state))
178178
goto restart;
179179

180-
clear_bit(HCI_UART_SENDING, &hu->tx_state);
181180
wake_up_bit(&hu->tx_state, HCI_UART_SENDING);
182181
}
183182

‎drivers/bluetooth/hci_serdev.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ static void hci_uart_write_work(struct work_struct *work)
8383
hci_uart_tx_complete(hu, hci_skb_pkt_type(skb));
8484
kfree_skb(skb);
8585
}
86-
} while (test_bit(HCI_UART_TX_WAKEUP, &hu->tx_state));
8786

88-
clear_bit(HCI_UART_SENDING, &hu->tx_state);
87+
clear_bit(HCI_UART_SENDING, &hu->tx_state);
88+
} while (test_bit(HCI_UART_TX_WAKEUP, &hu->tx_state));
8989
}
9090

9191
/* ------- Interface to HCI layer ------ */

0 commit comments

Comments
 (0)