Skip to contentSkip to conversation

Bluetooth: Use ERR_PTR as return error from hci_connect

PATCH In review [email protected] 2 participants 2 messages Feb 22, 2011 – Feb 27, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Bluetooth: Use ERR_PTR as return error from hci_connect

From: Ville Tervo <[email protected]>

Use ERR_PTR mechanism to return error from hci_connect.

---
 net/bluetooth/hci_conn.c   |    4 ++--
 net/bluetooth/l2cap_core.c |   10 ++++------
 net/bluetooth/mgmt.c       |    4 ++--
 net/bluetooth/sco.c        |    6 +++---
 4 files changed, 11 insertions(+), 13 deletions(-)
net/bluetooth/hci_conn.c +2 -2
index 4504cb6..7a6f56b 100644
@@ -431,10 +431,10 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8
 	if (type == LE_LINK) {
 		le = hci_conn_hash_lookup_ba(hdev, LE_LINK, dst);
 		if (le)
-			return NULL;
+			return ERR_PTR(-EBUSY);
 		le = hci_conn_add(hdev, LE_LINK, dst);
 		if (!le)
-			return NULL;
+			return ERR_PTR(-ENOMEM);
 		if (le->state == BT_OPEN)
 			hci_le_connect(le);
 
net/bluetooth/l2cap_core.c +4 -6
index efcef0d..e76e9e5 100644
@@ -841,7 +841,7 @@ int l2cap_do_connect(struct sock *sk)
 	struct hci_conn *hcon;
 	struct hci_dev *hdev;
 	__u8 auth_type;
-	int err;
+	int err = 0;
 
 	BT_DBG("%s -> %s psm 0x%2.2x", batostr(src), batostr(dst),
 							l2cap_pi(sk)->psm);
@@ -852,8 +852,6 @@ int l2cap_do_connect(struct sock *sk)
 
 	hci_dev_lock_bh(hdev);
 
-	err = -ENOMEM;
-
 	auth_type = l2cap_get_auth_type(sk);
 
 	if (l2cap_pi(sk)->dcid == L2CAP_CID_LE_DATA)
@@ -863,8 +861,10 @@ int l2cap_do_connect(struct sock *sk)
 		hcon = hci_connect(hdev, ACL_LINK, dst,
 					l2cap_pi(sk)->sec_level, auth_type);
 
-	if (!hcon)
+	if (IS_ERR(hcon)) {
+		err = PTR_ERR(hcon);
 		goto done;
+	}
 
 	conn = l2cap_conn_add(hcon, 0);
 	if (!conn) {
@@ -872,8 +872,6 @@ int l2cap_do_connect(struct sock *sk)
 		goto done;
 	}
 
-	err = 0;
-
 	/* Update source addr of the socket */
 	bacpy(src, conn->src);
 
net/bluetooth/mgmt.c +2 -2
index 982becd..37cabb5 100644
@@ -1149,8 +1149,8 @@ static int pair_device(struct sock *sk, unsigned char *data, u16 len)
 	}
 
 	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;
 	}
 
net/bluetooth/sco.c +3 -3
index c9348dd..26f2f04 100644
@@ -190,16 +190,16 @@ static int sco_connect(struct sock *sk)
 
 	hci_dev_lock_bh(hdev);
 
-	err = -ENOMEM;
-
 	if (lmp_esco_capable(hdev) && !disable_esco)
 		type = ESCO_LINK;
 	else
 		type = SCO_LINK;
 
 	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;
+	}
 
 	conn = sco_conn_add(hcon, 0);
 	if (!conn) {
Signature · 1 line
1.7.1
#1 lore raw

Hi Briglia,

Quoted 4 lines · * [email protected] <[email protected]> [2011-02-22…

From: Ville Tervo <[email protected]>

Use ERR_PTR mechanism to return error from hci_connect.

Quoted 8 lines
---
 net/bluetooth/hci_conn.c   |    4 ++--
 net/bluetooth/l2cap_core.c |   10 ++++------
 net/bluetooth/mgmt.c       |    4 ++--
 net/bluetooth/sco.c        |    6 +++---
 4 files changed, 11 insertions(+), 13 deletions(-)

Patch is applied now, but I had to fix it, your error handling was still wrong. Here are the changes I did to your patch:

net/bluetooth/l2cap_core.c +4 -1
index 0bbb6c6..c9f9cec 100644
@@ -841,7 +841,7 @@ int l2cap_do_connect(struct sock *sk)
        struct hci_conn *hcon;
        struct hci_dev *hdev;
        __u8 auth_type;
-       int err = 0;
+       int err;
 
        BT_DBG("%s -> %s psm 0x%2.2x", batostr(src), batostr(dst),
                                                        l2cap_pi(sk)->psm);
@@ -869,6 +869,7 @@ int l2cap_do_connect(struct sock *sk)
        conn = l2cap_conn_add(hcon, 0);
        if (!conn) {
                hci_conn_put(hcon);
+               err = -ENOMEM;
                goto done;
        }
 
@@ -890,6 +891,8 @@ int l2cap_do_connect(struct sock *sk)
                        l2cap_do_start(sk);
        }
 
+       err = 0;
+
 done:
        hci_dev_unlock_bh(hdev);
        hci_dev_put(hdev);
net/bluetooth/sco.c +1 -0
index 26f2f04..42fdffd 100644
@@ -204,6 +204,7 @@ static int sco_connect(struct sock *sk)
        conn = sco_conn_add(hcon, 0);
        if (!conn) {
                hci_conn_put(hcon);
+               err = -ENOMEM;
                goto done;
        }
 
Signature · 2 lines
Gustavo F. Padovan
http://profusion.mobi