Bluetooth: hci_conn related fixes
Subsystems (2)
cover Bluetooth: hci_conn related fixes
Hi,
This set of patches contains fixes for various issues introduced by the generic cmd_complete callback mechanism for pending mgmt commands.
Johan
----------------------------------------------------------------
Johan Hedberg (3):
Bluetooth: Fix calling hci_conn_put too early
Bluetooth: Fix incorrect pending cmd removal in pairing_complete()
Bluetooth: Fix notifying mgmt power off before flushing connection list
net/bluetooth/hci_core.c | 14 ++++++-------- net/bluetooth/mgmt.c | 42 +++++++++++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 23 deletions(-)
PATCH 1/3 Bluetooth: Fix calling hci_conn_put too early
From: Johan Hedberg <[email protected]>
The pairing_complete() function relies on a hci_conn reference to be able to access the hci_conn object. It should therefore only release this reference once it's done accessing the object, i.e. at the end of the function.
--- net/bluetooth/mgmt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/bluetooth/mgmt.c +2 -2
@@ -3115,14 +3115,14 @@ static void pairing_complete(struct pending_cmd *cmd, u8 status) conn->disconn_cfm_cb =NULL ;hci_conn_drop (conn); -hci_conn_put (conn); -mgmt_pending_remove (cmd);/* The device is paired so there is no need to remove * its connection parameters anymore. */ clear_bit (HCI_CONN_PARAM_REMOVAL_PEND , &conn->flags); + +hci_conn_put (conn); }void mgmt_smp_complete (struct hci_conn *conn,bool complete)
Signature · 1 line
2.1.0
PATCH 2/3 Bluetooth: Fix incorrect pending cmd removal in pairing_complete()
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
The pairing_complete() function is used as a pending mgmt command cmd_complete callback. The expectation of such functions is that they are not responsible themselves for calling mgmt_pending_remove(). This patch fixes the incorrect mgmt_pending_remove() call in pairing_complete() and adds it to the appropriate changes.
--- net/bluetooth/mgmt.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-)
net/bluetooth/mgmt.c +25 -13
@@ -3115,7 +3115,6 @@ static void pairing_complete(struct pending_cmd *cmd, u8 status) conn->disconn_cfm_cb =NULL ;hci_conn_drop (conn); -mgmt_pending_remove (cmd);/* The device is paired so there is no need to remove * its connection parameters anymore.
@@ -3131,8 +3130,10 @@ void mgmt_smp_complete(struct hci_conn *conn, bool complete)struct pending_cmd *cmd; cmd =find_pairing (conn); -if (cmd) +if (cmd) { cmd->cmd_complete (cmd, status); +mgmt_pending_remove (cmd); + } }static void pairing_complete_cb (struct hci_conn *conn,u8 status)
@@ -3142,10 +3143,13 @@ static void pairing_complete_cb(struct hci_conn *conn, u8 status)BT_DBG ("status %u" , status); cmd =find_pairing (conn); -if (!cmd) +if (!cmd) {BT_DBG ("Unable to find a pending command" ); -else - cmd->cmd_complete (cmd,mgmt_status (status)); +return ; + } + + cmd->cmd_complete (cmd,mgmt_status (status)); +mgmt_pending_remove (cmd); }static void le_pairing_complete_cb (struct hci_conn *conn,u8 status)
@@ -3158,10 +3162,13 @@ static void le_pairing_complete_cb(struct hci_conn *conn, u8 status)return ; cmd =find_pairing (conn); -if (!cmd) +if (!cmd) {BT_DBG ("Unable to find a pending command" ); -else - cmd->cmd_complete (cmd,mgmt_status (status)); +return ; + } + + cmd->cmd_complete (cmd,mgmt_status (status)); +mgmt_pending_remove (cmd); } static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
@@ -3275,8 +3282,10 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data, cmd->user_data =hci_conn_get (conn);if ((conn->state ==BT_CONNECTED || conn->state ==BT_CONFIG ) && -hci_conn_security (conn, sec_level, auth_type, true)) -pairing_complete (cmd,0 ); +hci_conn_security (conn, sec_level, auth_type, true)) { + cmd->cmd_complete (cmd,0 ); +mgmt_pending_remove (cmd); + } err =0 ;
@@ -3318,7 +3327,8 @@ static int cancel_pair_device(struct sock *sk, struct hci_dev *hdev, void *data, goto unlock; } -pairing_complete (cmd,MGMT_STATUS_CANCELLED ); + cmd->cmd_complete (cmd,MGMT_STATUS_CANCELLED ); +mgmt_pending_remove (cmd); err =cmd_complete (sk, hdev->id,MGMT_OP_CANCEL_PAIR_DEVICE ,0 , addr,sizeof (*addr));
@@ -6687,8 +6697,10 @@ void mgmt_auth_failed(struct hci_conn *conn, u8 hci_status)mgmt_event (MGMT_EV_AUTH_FAILED , conn->hdev, &ev,sizeof (ev), cmd ? cmd->sk :NULL ); -if (cmd) -pairing_complete (cmd, status); +if (cmd) { + cmd->cmd_complete (cmd, status); +mgmt_pending_remove (cmd); + } }void mgmt_auth_enable_complete (struct hci_dev *hdev,u8 status)
Signature · 1 line
2.1.0
PATCH 3/3 Bluetooth: Fix notifying mgmt power off before flushing connection list
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
This patch moves the mgmt_powered() notification earlier in the hci_dev_do_close() function. This way the correct "not powered" error gets passed to any pending mgmt commands. Without the patch the pending commands would instead get a misleading "disconnected" response when powering down the adapter.
--- net/bluetooth/hci_core.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
net/bluetooth/hci_core.c +6 -8
@@ -2634,6 +2634,12 @@ static int hci_dev_do_close(struct hci_dev *hdev)drain_workqueue (hdev->workqueue);hci_dev_lock (hdev); + +if (!test_and_clear_bit (HCI_AUTO_OFF , &hdev->dev_flags)) { +if (hdev->dev_type ==HCI_BREDR ) +mgmt_powered (hdev,0 ); + } +hci_inquiry_cache_flush (hdev);hci_pend_le_actions_clear (hdev);hci_conn_hash_flush (hdev);
@@ -2681,14 +2687,6 @@ static int hci_dev_do_close(struct hci_dev *hdev) hdev->flags &=BIT (HCI_RAW ); hdev->dev_flags &= ~HCI_PERSISTENT_MASK ; -if (!test_and_clear_bit (HCI_AUTO_OFF , &hdev->dev_flags)) { -if (hdev->dev_type ==HCI_BREDR ) { -hci_dev_lock (hdev); -mgmt_powered (hdev,0 ); -hci_dev_unlock (hdev); - } - } -/* Controller radio is available but is currently powered down */ hdev->amp_status =AMP_STATUS_POWERED_DOWN ;
Signature · 1 line
2.1.0
Marcel Holtmann
maintainerHi Johan,
Quoted 11 lines
This set of patches contains fixes for various issues introduced by the generic
cmd_completecallback mechanism for pending mgmt commands.Johan
----------------------------------------------------------------
Johan Hedberg (3):
Bluetooth: Fix callinghci_conn_puttoo early
Bluetooth: Fix incorrect pending cmd removal inpairing_complete()
Bluetooth: Fix notifying mgmt power off before flushing connection list
Quoted 3 lines
net/bluetooth/hci_core.c| 14 ++++++--------net/bluetooth/mgmt.c| 42 +++++++++++++++++++++++++++---------------2 files changed, 33 insertions(+), 23 deletions(-)
all 3 patches have been applied to bluetooth-next tree.
Regards
Marcel