Lee, Chun-Yi 7cbdb8
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Lee, Chun-Yi 7cbdb8
Date: Tue, 21 Jun 2022 11:58:34 -0700
Lee, Chun-Yi 7cbdb8
Subject: Bluetooth: mgmt: Fix using hci_conn_abort
Lee, Chun-Yi 7cbdb8
Patch-mainline: v6.0-rc1
Lee, Chun-Yi 7cbdb8
Git-commit: 1f7435c8f6558a94f75b408a74140bdcbd0f6dd1
Lee, Chun-Yi 7cbdb8
References: jsc#PED-1407
Lee, Chun-Yi 7cbdb8
Lee, Chun-Yi 7cbdb8
This fixes using hci_conn_abort instead of using hci_conn_abort_sync.
Lee, Chun-Yi 7cbdb8
Lee, Chun-Yi 7cbdb8
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Lee, Chun-Yi 7cbdb8
Acked-by: Lee, Chun-Yi <jlee@suse.com>
Lee, Chun-Yi 7cbdb8
---
Lee, Chun-Yi 7cbdb8
 include/net/bluetooth/hci_sync.h |    2 ++
Lee, Chun-Yi 7cbdb8
 net/bluetooth/hci_sync.c         |    3 +--
Lee, Chun-Yi 7cbdb8
 net/bluetooth/mgmt.c             |   38 +++++++++++++++++++++++++++++++++++---
Lee, Chun-Yi 7cbdb8
 3 files changed, 38 insertions(+), 5 deletions(-)
Lee, Chun-Yi 7cbdb8
Lee, Chun-Yi 7cbdb8
--- a/include/net/bluetooth/hci_sync.h
Lee, Chun-Yi 7cbdb8
+++ b/include/net/bluetooth/hci_sync.h
Lee, Chun-Yi 7cbdb8
@@ -105,4 +105,6 @@ int hci_resume_sync(struct hci_dev *hdev
Lee, Chun-Yi 7cbdb8
 
Lee, Chun-Yi 7cbdb8
 struct hci_conn;
Lee, Chun-Yi 7cbdb8
 
Lee, Chun-Yi 7cbdb8
+int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, u8 reason);
Lee, Chun-Yi 7cbdb8
+
Lee, Chun-Yi 7cbdb8
 int hci_le_create_conn_sync(struct hci_dev *hdev, struct hci_conn *conn);
Lee, Chun-Yi 7cbdb8
--- a/net/bluetooth/hci_sync.c
Lee, Chun-Yi 7cbdb8
+++ b/net/bluetooth/hci_sync.c
Lee, Chun-Yi 7cbdb8
@@ -4489,8 +4489,7 @@ static int hci_reject_conn_sync(struct h
Lee, Chun-Yi 7cbdb8
 				     sizeof(cp), &cp, HCI_CMD_TIMEOUT);
Lee, Chun-Yi 7cbdb8
 }
Lee, Chun-Yi 7cbdb8
 
Lee, Chun-Yi 7cbdb8
-static int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn,
Lee, Chun-Yi 7cbdb8
-			       u8 reason)
Lee, Chun-Yi 7cbdb8
+int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, u8 reason)
Lee, Chun-Yi 7cbdb8
 {
Lee, Chun-Yi 7cbdb8
 	int err;
Lee, Chun-Yi 7cbdb8
 
Lee, Chun-Yi 7cbdb8
--- a/net/bluetooth/mgmt.c
Lee, Chun-Yi 7cbdb8
+++ b/net/bluetooth/mgmt.c
Lee, Chun-Yi 7cbdb8
@@ -2528,6 +2528,37 @@ static int device_unpaired(struct hci_de
Lee, Chun-Yi 7cbdb8
 			  skip_sk);
Lee, Chun-Yi 7cbdb8
 }
Lee, Chun-Yi 7cbdb8
 
Lee, Chun-Yi 7cbdb8
+static void unpair_device_complete(struct hci_dev *hdev, void *data, int err)
Lee, Chun-Yi 7cbdb8
+{
Lee, Chun-Yi 7cbdb8
+	struct mgmt_pending_cmd *cmd = data;
Lee, Chun-Yi 7cbdb8
+	struct mgmt_cp_unpair_device *cp = cmd->param;
Lee, Chun-Yi 7cbdb8
+
Lee, Chun-Yi 7cbdb8
+	if (!err)
Lee, Chun-Yi 7cbdb8
+		device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, cmd->sk);
Lee, Chun-Yi 7cbdb8
+
Lee, Chun-Yi 7cbdb8
+	cmd->cmd_complete(cmd, err);
Lee, Chun-Yi 7cbdb8
+	mgmt_pending_free(cmd);
Lee, Chun-Yi 7cbdb8
+}
Lee, Chun-Yi 7cbdb8
+
Lee, Chun-Yi 7cbdb8
+static int unpair_device_sync(struct hci_dev *hdev, void *data)
Lee, Chun-Yi 7cbdb8
+{
Lee, Chun-Yi 7cbdb8
+	struct mgmt_pending_cmd *cmd = data;
Lee, Chun-Yi 7cbdb8
+	struct mgmt_cp_unpair_device *cp = cmd->param;
Lee, Chun-Yi 7cbdb8
+	struct hci_conn *conn;
Lee, Chun-Yi 7cbdb8
+
Lee, Chun-Yi 7cbdb8
+	if (cp->addr.type == BDADDR_BREDR)
Lee, Chun-Yi 7cbdb8
+		conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK,
Lee, Chun-Yi 7cbdb8
+					       &cp->addr.bdaddr);
Lee, Chun-Yi 7cbdb8
+	else
Lee, Chun-Yi 7cbdb8
+		conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr,
Lee, Chun-Yi 7cbdb8
+					       le_addr_type(cp->addr.type));
Lee, Chun-Yi 7cbdb8
+
Lee, Chun-Yi 7cbdb8
+	if (!conn)
Lee, Chun-Yi 7cbdb8
+		return 0;
Lee, Chun-Yi 7cbdb8
+
Lee, Chun-Yi 7cbdb8
+	return hci_abort_conn_sync(hdev, conn, HCI_ERROR_REMOTE_USER_TERM);
Lee, Chun-Yi 7cbdb8
+}
Lee, Chun-Yi 7cbdb8
+
Lee, Chun-Yi 7cbdb8
 static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data,
Lee, Chun-Yi 7cbdb8
 			 u16 len)
Lee, Chun-Yi 7cbdb8
 {
Lee, Chun-Yi 7cbdb8
@@ -2638,7 +2669,7 @@ done:
Lee, Chun-Yi 7cbdb8
 		goto unlock;
Lee, Chun-Yi 7cbdb8
 	}
Lee, Chun-Yi 7cbdb8
 
Lee, Chun-Yi 7cbdb8
-	cmd = mgmt_pending_add(sk, MGMT_OP_UNPAIR_DEVICE, hdev, cp,
Lee, Chun-Yi 7cbdb8
+	cmd = mgmt_pending_new(sk, MGMT_OP_UNPAIR_DEVICE, hdev, cp,
Lee, Chun-Yi 7cbdb8
 			       sizeof(*cp));
Lee, Chun-Yi 7cbdb8
 	if (!cmd) {
Lee, Chun-Yi 7cbdb8
 		err = -ENOMEM;
Lee, Chun-Yi 7cbdb8
@@ -2647,9 +2678,10 @@ done:
Lee, Chun-Yi 7cbdb8
 
Lee, Chun-Yi 7cbdb8
 	cmd->cmd_complete = addr_cmd_complete;
Lee, Chun-Yi 7cbdb8
 
Lee, Chun-Yi 7cbdb8
-	err = hci_abort_conn(conn, HCI_ERROR_REMOTE_USER_TERM);
Lee, Chun-Yi 7cbdb8
+	err = hci_cmd_sync_queue(hdev, unpair_device_sync, cmd,
Lee, Chun-Yi 7cbdb8
+				 unpair_device_complete);
Lee, Chun-Yi 7cbdb8
 	if (err < 0)
Lee, Chun-Yi 7cbdb8
-		mgmt_pending_remove(cmd);
Lee, Chun-Yi 7cbdb8
+		mgmt_pending_free(cmd);
Lee, Chun-Yi 7cbdb8
 
Lee, Chun-Yi 7cbdb8
 unlock:
Lee, Chun-Yi 7cbdb8
 	hci_dev_unlock(hdev);