Bluetooth: Use ERR_PTR as return error from hci_connect
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / net / bluetooth / sco.c
index 66b9e5c0523a2211450cece91d5cf217fbd4722b..42fdffd1d76c0c17c5ab3382b94ea5bf4fcc62c9 100644 (file)
 #include <net/sock.h>
 
 #include <asm/system.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
 
 #include <net/bluetooth/bluetooth.h>
 #include <net/bluetooth/hci_core.h>
 #include <net/bluetooth/sco.h>
 
-#define VERSION "0.6"
-
-static int disable_esco = 0;
+static int disable_esco;
 
 static const struct proto_ops sco_sock_ops;
 
@@ -138,16 +136,17 @@ static inline struct sock *sco_chan_get(struct sco_conn *conn)
 
 static int sco_conn_del(struct hci_conn *hcon, int err)
 {
-       struct sco_conn *conn;
+       struct sco_conn *conn = hcon->sco_data;
        struct sock *sk;
 
-       if (!(conn = hcon->sco_data))
+       if (!conn)
                return 0;
 
        BT_DBG("hcon %p conn %p, err %d", hcon, conn, err);
 
        /* Kill socket */
-       if ((sk = sco_chan_get(conn))) {
+       sk = sco_chan_get(conn);
+       if (sk) {
                bh_lock_sock(sk);
                sco_sock_clear_timer(sk);
                sco_chan_del(sk, err);
@@ -185,25 +184,27 @@ static int sco_connect(struct sock *sk)
 
        BT_DBG("%s -> %s", batostr(src), batostr(dst));
 
-       if (!(hdev = hci_get_route(dst, src)))
+       hdev = hci_get_route(dst, src);
+       if (!hdev)
                return -EHOSTUNREACH;
 
        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) {
                hci_conn_put(hcon);
+               err = -ENOMEM;
                goto done;
        }
 
@@ -510,7 +511,8 @@ static int sco_sock_connect(struct socket *sock, struct sockaddr *addr, int alen
        /* Set destination address and psm */
        bacpy(&bt_sk(sk)->dst, &sa->sco_bdaddr);
 
-       if ((err = sco_connect(sk)))
+       err = sco_connect(sk);
+       if (err)
                goto done;
 
        err = bt_sock_wait_state(sk, BT_CONNECTED,
@@ -700,6 +702,7 @@ static int sco_sock_getsockopt_old(struct socket *sock, int optname, char __user
                        break;
                }
 
+               memset(&cinfo, 0, sizeof(cinfo));
                cinfo.hci_handle = sco_pi(sk)->conn->hcon->handle;
                memcpy(cinfo.dev_class, sco_pi(sk)->conn->hcon->dev_class, 3);
 
@@ -828,13 +831,14 @@ static void sco_chan_del(struct sock *sk, int err)
 
 static void sco_conn_ready(struct sco_conn *conn)
 {
-       struct sock *parent, *sk;
+       struct sock *parent;
+       struct sock *sk = conn->sk;
 
        BT_DBG("conn %p", conn);
 
        sco_conn_lock(conn);
 
-       if ((sk = conn->sk)) {
+       if (sk) {
                sco_sock_clear_timer(sk);
                bh_lock_sock(sk);
                sk->sk_state = BT_CONNECTED;
@@ -1019,7 +1023,7 @@ static struct hci_proto sco_hci_proto = {
        .recv_scodata   = sco_recv_scodata
 };
 
-static int __init sco_init(void)
+int __init sco_init(void)
 {
        int err;
 
@@ -1047,7 +1051,6 @@ static int __init sco_init(void)
                        BT_ERR("Failed to create SCO debug file");
        }
 
-       BT_INFO("SCO (Voice Link) ver %s", VERSION);
        BT_INFO("SCO socket layer initialized");
 
        return 0;
@@ -1057,7 +1060,7 @@ error:
        return err;
 }
 
-static void __exit sco_exit(void)
+void __exit sco_exit(void)
 {
        debugfs_remove(sco_debugfs);
 
@@ -1070,14 +1073,5 @@ static void __exit sco_exit(void)
        proto_unregister(&sco_proto);
 }
 
-module_init(sco_init);
-module_exit(sco_exit);
-
 module_param(disable_esco, bool, 0644);
 MODULE_PARM_DESC(disable_esco, "Disable eSCO connection creation");
-
-MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
-MODULE_DESCRIPTION("Bluetooth SCO ver " VERSION);
-MODULE_VERSION(VERSION);
-MODULE_LICENSE("GPL");
-MODULE_ALIAS("bt-proto-2");