Skip to content

Commit

Permalink
Bluetooth: btintel_pcie: Fix a potential race condition
Browse files Browse the repository at this point in the history
On HCI_OP_RESET command, firmware raises alive interrupt. Driver needs
to wait for this before sending other command. This patch fixes the potential
miss of alive interrupt due to which HCI_OP_RESET can timeout.

Expected flow:
If tx command is HCI_OP_RESET,
  1. set data->gp0_received = false
  2. send HCI_OP_RESET
  3. wait for alive interrupt

Actual flow having potential race:
If tx command is HCI_OP_RESET,
 1. send HCI_OP_RESET
   1a. Firmware raises alive interrupt here and in ISR
       data->gp0_received  is set to true
 2. set data->gp0_received = false
 3. wait for alive interrupt

Signed-off-by: Kiran K <[email protected]>
Fixes: 05c200c ("Bluetooth: btintel_pcie: Add handshake between driver and firmware")
Reported-by: Bjorn Helgaas <[email protected]>
Closes: https://patchwork.kernel.org/project/bluetooth/patch/[email protected]/
Signed-off-by: Luiz Augusto von Dentz <[email protected]>
  • Loading branch information
kirankrishnappa-intel authored and Vudentz committed Feb 13, 2025
1 parent b4f82f9 commit 872274b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/bluetooth/btintel_pcie.c
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,10 @@ static int btintel_pcie_send_frame(struct hci_dev *hdev,
if (opcode == 0xfc01)
btintel_pcie_inject_cmd_complete(hdev, opcode);
}
/* Firmware raises alive interrupt on HCI_OP_RESET */
if (opcode == HCI_OP_RESET)
data->gp0_received = false;

hdev->stat.cmd_tx++;
break;
case HCI_ACLDATA_PKT:
Expand Down Expand Up @@ -1357,7 +1361,6 @@ static int btintel_pcie_send_frame(struct hci_dev *hdev,
opcode, btintel_pcie_alivectxt_state2str(old_ctxt),
btintel_pcie_alivectxt_state2str(data->alive_intr_ctxt));
if (opcode == HCI_OP_RESET) {
data->gp0_received = false;
ret = wait_event_timeout(data->gp0_wait_q,
data->gp0_received,
msecs_to_jiffies(BTINTEL_DEFAULT_INTR_TIMEOUT_MS));
Expand Down

0 comments on commit 872274b

Please sign in to comment.