瀏覽代碼

Bluetooth: Use ERR_PTR as return error from hci_connect

Use ERR_PTR mechanism to return error from hci_connect.

Signed-off-by: Ville Tervo <ville.tervo@nokia.com>
Signed-off-by: Anderson Briglia <anderson.briglia@openbossa.org>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
Ville Tervo 14 年之前
父節點
當前提交
30e7627219
共有 4 個文件被更改,包括 14 次插入12 次删除
  1. 2 2
      net/bluetooth/hci_conn.c
  2. 6 5
      net/bluetooth/l2cap_core.c
  3. 2 2
      net/bluetooth/mgmt.c
  4. 4 3
      net/bluetooth/sco.c

+ 2 - 2
net/bluetooth/hci_conn.c

@@ -431,10 +431,10 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8
 	if (type == LE_LINK) {
 	if (type == LE_LINK) {
 		le = hci_conn_hash_lookup_ba(hdev, LE_LINK, dst);
 		le = hci_conn_hash_lookup_ba(hdev, LE_LINK, dst);
 		if (le)
 		if (le)
-			return NULL;
+			return ERR_PTR(-EBUSY);
 		le = hci_conn_add(hdev, LE_LINK, dst);
 		le = hci_conn_add(hdev, LE_LINK, dst);
 		if (!le)
 		if (!le)
-			return NULL;
+			return ERR_PTR(-ENOMEM);
 		if (le->state == BT_OPEN)
 		if (le->state == BT_OPEN)
 			hci_le_connect(le);
 			hci_le_connect(le);
 
 

+ 6 - 5
net/bluetooth/l2cap_core.c

@@ -852,8 +852,6 @@ int l2cap_do_connect(struct sock *sk)
 
 
 	hci_dev_lock_bh(hdev);
 	hci_dev_lock_bh(hdev);
 
 
-	err = -ENOMEM;
-
 	auth_type = l2cap_get_auth_type(sk);
 	auth_type = l2cap_get_auth_type(sk);
 
 
 	if (l2cap_pi(sk)->dcid == L2CAP_CID_LE_DATA)
 	if (l2cap_pi(sk)->dcid == L2CAP_CID_LE_DATA)
@@ -863,17 +861,18 @@ int l2cap_do_connect(struct sock *sk)
 		hcon = hci_connect(hdev, ACL_LINK, dst,
 		hcon = hci_connect(hdev, ACL_LINK, dst,
 					l2cap_pi(sk)->sec_level, auth_type);
 					l2cap_pi(sk)->sec_level, auth_type);
 
 
-	if (!hcon)
+	if (IS_ERR(hcon)) {
+		err = PTR_ERR(hcon);
 		goto done;
 		goto done;
+	}
 
 
 	conn = l2cap_conn_add(hcon, 0);
 	conn = l2cap_conn_add(hcon, 0);
 	if (!conn) {
 	if (!conn) {
 		hci_conn_put(hcon);
 		hci_conn_put(hcon);
+		err = -ENOMEM;
 		goto done;
 		goto done;
 	}
 	}
 
 
-	err = 0;
-
 	/* Update source addr of the socket */
 	/* Update source addr of the socket */
 	bacpy(src, conn->src);
 	bacpy(src, conn->src);
 
 
@@ -892,6 +891,8 @@ int l2cap_do_connect(struct sock *sk)
 			l2cap_do_start(sk);
 			l2cap_do_start(sk);
 	}
 	}
 
 
+	err = 0;
+
 done:
 done:
 	hci_dev_unlock_bh(hdev);
 	hci_dev_unlock_bh(hdev);
 	hci_dev_put(hdev);
 	hci_dev_put(hdev);

+ 2 - 2
net/bluetooth/mgmt.c

@@ -1171,8 +1171,8 @@ static int pair_device(struct sock *sk, u16 index, unsigned char *data, u16 len)
 	}
 	}
 
 
 	conn = hci_connect(hdev, ACL_LINK, &cp->bdaddr, sec_level, auth_type);
 	conn = hci_connect(hdev, ACL_LINK, &cp->bdaddr, sec_level, auth_type);
-	if (!conn) {
-		err = -ENOMEM;
+	if (IS_ERR(conn)) {
+		err = PTR_ERR(conn);
 		goto unlock;
 		goto unlock;
 	}
 	}
 
 

+ 4 - 3
net/bluetooth/sco.c

@@ -190,20 +190,21 @@ static int sco_connect(struct sock *sk)
 
 
 	hci_dev_lock_bh(hdev);
 	hci_dev_lock_bh(hdev);
 
 
-	err = -ENOMEM;
-
 	if (lmp_esco_capable(hdev) && !disable_esco)
 	if (lmp_esco_capable(hdev) && !disable_esco)
 		type = ESCO_LINK;
 		type = ESCO_LINK;
 	else
 	else
 		type = SCO_LINK;
 		type = SCO_LINK;
 
 
 	hcon = hci_connect(hdev, type, dst, BT_SECURITY_LOW, HCI_AT_NO_BONDING);
 	hcon = hci_connect(hdev, type, dst, BT_SECURITY_LOW, HCI_AT_NO_BONDING);
-	if (!hcon)
+	if (IS_ERR(hcon)) {
+		err = PTR_ERR(hcon);
 		goto done;
 		goto done;
+	}
 
 
 	conn = sco_conn_add(hcon, 0);
 	conn = sco_conn_add(hcon, 0);
 	if (!conn) {
 	if (!conn) {
 		hci_conn_put(hcon);
 		hci_conn_put(hcon);
+		err = -ENOMEM;
 		goto done;
 		goto done;
 	}
 	}