Bluetooth : hidp: Get the valid hci_conn while unlink

Since the context where unlink will be called is unaware of
validity of hci_conn pointer, fetch the valid hci_conn
before unlink.

CRs-Fixed: 433361
Change-Id: Ief71997a3f007ea43431765c6cf543ab0d6416a8
Signed-off-by: Sumit Bajpai <sbajpai@codeaurora.org>
diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
index 2c4ab78..2af4149 100644
--- a/net/bluetooth/hidp/core.c
+++ b/net/bluetooth/hidp/core.c
@@ -101,7 +101,20 @@
 
 static void __hidp_unlink_session(struct hidp_session *session)
 {
-	if (session->conn)
+	bdaddr_t *dst = &session->bdaddr;
+	struct hci_dev *hdev;
+	struct device *dev = NULL;
+
+	hdev = hci_get_route(dst, BDADDR_ANY);
+	if (hdev) {
+		session->conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, dst);
+		if (session->conn)
+			dev = &session->conn->dev;
+
+		hci_dev_put(hdev);
+	}
+
+	if (dev)
 		hci_conn_put_device(session->conn);
 
 	list_del(&session->list);