diff options
author | Johan Hedberg <johan.hedberg@intel.com> | 2013-07-27 15:11:14 -0400 |
---|---|---|
committer | Gustavo Padovan <gustavo.padovan@collabora.co.uk> | 2013-07-29 07:28:04 -0400 |
commit | 53e21fbc288218a423959f878c86471a0e323a9a (patch) | |
tree | 0c7db14fc7d29e468cdf57d9f3eb0cad75011fed /net | |
parent | 3f8e2d75c14660abc8b69206f30190ab93304379 (diff) |
Bluetooth: Fix calling request callback more than once
In certain circumstances, such as an HCI driver using __hci_cmd_sync_ev
with HCI_EV_CMD_COMPLETE as the expected completion event there is the
chance that hci_event_packet will call hci_req_cmd_complete twice (once
for the explicitly looked after event and another time in the actual
handler of cmd_complete).
In the case of __hci_cmd_sync_ev this introduces a race where the first
call wakes up the blocking __hci_cmd_sync_ev and lets it complete.
However, by the time that a second __hci_cmd_sync_ev call is already in
progress the second hci_req_cmd_complete call (from the previous
operation) will wake up the blocking function prematurely and cause it
to fail, as witnessed by the following log:
[ 639.232195] hci_rx_work: hci0 Event packet
[ 639.232201] hci_req_cmd_complete: opcode 0xfc8e status 0x00
[ 639.232205] hci_sent_cmd_data: hci0 opcode 0xfc8e
[ 639.232210] hci_req_sync_complete: hci0 result 0x00
[ 639.232220] hci_cmd_complete_evt: hci0 opcode 0xfc8e
[ 639.232225] hci_req_cmd_complete: opcode 0xfc8e status 0x00
[ 639.232228] __hci_cmd_sync_ev: hci0 end: err 0
[ 639.232234] __hci_cmd_sync_ev: hci0
[ 639.232238] hci_req_add_ev: hci0 opcode 0xfc8e plen 250
[ 639.232242] hci_prepare_cmd: skb len 253
[ 639.232246] hci_req_run: length 1
[ 639.232250] hci_sent_cmd_data: hci0 opcode 0xfc8e
[ 639.232255] hci_req_sync_complete: hci0 result 0x00
[ 639.232266] hci_cmd_work: hci0 cmd_cnt 1 cmd queued 1
[ 639.232271] __hci_cmd_sync_ev: hci0 end: err 0
[ 639.232276] Bluetooth: hci0 sending Intel patch command (0xfc8e) failed (-61)
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Diffstat (limited to 'net')
-rw-r--r-- | net/bluetooth/hci_core.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 0176f200ccb0..48e1e0438f3a 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c | |||
@@ -3442,8 +3442,16 @@ void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status) | |||
3442 | */ | 3442 | */ |
3443 | if (hdev->sent_cmd) { | 3443 | if (hdev->sent_cmd) { |
3444 | req_complete = bt_cb(hdev->sent_cmd)->req.complete; | 3444 | req_complete = bt_cb(hdev->sent_cmd)->req.complete; |
3445 | if (req_complete) | 3445 | |
3446 | if (req_complete) { | ||
3447 | /* We must set the complete callback to NULL to | ||
3448 | * avoid calling the callback more than once if | ||
3449 | * this function gets called again. | ||
3450 | */ | ||
3451 | bt_cb(hdev->sent_cmd)->req.complete = NULL; | ||
3452 | |||
3446 | goto call_complete; | 3453 | goto call_complete; |
3454 | } | ||
3447 | } | 3455 | } |
3448 | 3456 | ||
3449 | /* Remove all pending commands belonging to this request */ | 3457 | /* Remove all pending commands belonging to this request */ |