Bluetooth: Use ERR_PTR to return error from hci_connect
Subsystems (2)
RFC v2 3/4 Bluetooth: Use ERR_PTR to return error from hci_connect
From: Ville Tervo <[email protected]>
Use ERR_PRT mechanism to return error from hci_connect. This patch also includes a change to return error if LE link exists already to remote host.
--- net/bluetooth/hci_conn.c | 12 +++++++----- net/bluetooth/l2cap_core.c | 10 ++++------ net/bluetooth/sco.c | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-)
net/bluetooth/hci_conn.c +7 -5
@@ -305,7 +305,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst) conn =kzalloc (sizeof (struct hci_conn ),GFP_ATOMIC );if (!conn) -return NULL ; +return ERR_PTR (-ENOMEM );bacpy (&conn->dst, dst); conn->hdev = hdev;
@@ -459,8 +459,10 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8 le =hci_conn_hash_lookup_ba (hdev,LE_LINK , dst);if (!le) le =hci_conn_add (hdev,LE_LINK , dst); -if (!le) -return NULL ; +else +return ERR_PTR (-EBUSY ); +if (IS_ERR (le)) +return le;if (le->state ==BT_OPEN )hci_le_connect (le);
@@ -472,8 +474,8 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8 acl =hci_conn_hash_lookup_ba (hdev,ACL_LINK , dst);if (!acl) { acl =hci_conn_add (hdev,ACL_LINK , dst); -if (!acl) -return NULL ; +if (IS_ERR (acl)) +return acl; }hci_conn_hold (acl);
net/bluetooth/l2cap_core.c +4 -6
@@ -869,7 +869,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);
@@ -880,8 +880,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 )
@@ -891,8 +889,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) {
@@ -900,8 +900,6 @@ int l2cap_do_connect(struct sock *sk) goto done; } - err =0 ; -/* Update source addr of the socket */ bacpy (src, conn->src);
net/bluetooth/sco.c +3 -3
@@ -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
Hi Ville,
Quoted 3 lines · * [email protected] <[email protected]> [2011-02-17…
From: Ville Tervo <[email protected]>
Use
ERR_PRTmechanism to return error fromhci_connect. This patch also
Typo here, ERR_PTR.
Quoted 14 lines
includes a change to return error if LE link exists already to remote host.
Signed-off-by Ville Tervo <[email protected]>--- net/bluetooth/hci_conn.c | 12 +++++++----- net/bluetooth/l2cap_core.c | 10 ++++------ net/bluetooth/sco.c | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-)net/bluetooth/hci_conn.c +0
-0
net/bluetooth/hci_conn.c struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst) · line 308
Quoted 5 lines
net/bluetooth/hci_conn.c +1
-1@@ -305,7 +305,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst) conn =kzalloc (sizeof (struct hci_conn ),GFP_ATOMIC );if (!conn) -return NULL ; +return ERR_PTR (-ENOMEM );
That's not really need. Seems that return NULL here means ENOMEM.
net/bluetooth/hci_conn.c struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8 · line 465
Quoted 13 lines
net/bluetooth/hci_conn.c +4
-2bacpy (&conn->dst, dst); conn->hdev = hdev;@@ -459,8 +459,10 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8 le =hci_conn_hash_lookup_ba (hdev,LE_LINK , dst);if (!le) le =hci_conn_add (hdev,LE_LINK , dst); -if (!le) -return NULL ; +else +return ERR_PTR (-EBUSY ); +if (IS_ERR (le)) +return le;
I prefer this instead:
le = hci_conn_hash_lookup_ba(hdev, LE_LINK, dst);
if (le)
return ERR_PTR(-EBUSY);
le = hci_conn_add(hdev, LE_LINK, dst);
if (!le)
return ERR_PTR(-ENOMEM);Regards,
Signature · 2 lines
Gustavo F. Padovan http://profusion.mobi
Hi Gustavo,
Quoted 13 lines · Gustavo F. Padovan
net/bluetooth/hci_conn.c struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8 · line 465
Quoted 10 lines
net/bluetooth/hci_conn.c +4
-2@@ -459,8 +459,10 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8 le = hci_conn_hash_lookup_ba(hdev, LE_LINK, dst); if (!le) le = hci_conn_add(hdev, LE_LINK, dst); - if (!le) - return NULL; + else + return ERR_PTR(-EBUSY); + if (IS_ERR(le)) + return le;I prefer this instead:
Quoted 7 lines
le =
hci_conn_hash_lookup_ba(hdev, LE_LINK, dst); if (le)
returnERR_PTR(-EBUSY);le =
hci_conn_add(hdev, LE_LINK, dst); if (!le)
returnERR_PTR(-ENOMEM);
I think the code above (besides the "if (le)" typo) is not equivalent to the original one. See:
Quoted 5 lines
net/bluetooth/hci_conn.c struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8 · line 463
Quoted 5 lines
net/bluetooth/hci_conn.c +0
-2le =hci_conn_hash_lookup_ba (hdev,LE_LINK , dst);if (!le) le =hci_conn_add (hdev,LE_LINK , dst); -if (!le) -return NULL ;
if hci_conn_hash_lookup_ba() returns NULL, it should call hci_conn_add(), and if that fails, then return NULL (or some ERR_PTR()).
Regards,
Signature · 3 lines
Anderson Lizardo Instituto Nokia de Tecnologia - INdT Manaus - Brazil
Hi Briglia,
net/bluetooth/hci_conn.c struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8 · line 479
Quoted 9 lines · On Thu, Feb 17, 2011 at 10:39 AM, <[email protected]> wrote:
net/bluetooth/hci_conn.c +2
-2@@ -472,8 +474,8 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8 acl = hci_conn_hash_lookup_ba(hdev, ACL_LINK, dst); if (!acl) { acl = hci_conn_add(hdev, ACL_LINK, dst); - if (!acl) - return NULL; + if (IS_ERR(acl)) + return acl; }
Note that if you follow Gustavo's suggestion to keep hci_conn_add() returning NULL on ENOMEM, you should change this as well:
if (!acl)
return ERR_PTR(-ENOMEM);
Regards,
Signature · 3 lines
Anderson Lizardo Instituto Nokia de Tecnologia - INdT Manaus - Brazil