vserver 2.0 rc7
[linux-2.6.git] / net / bluetooth / sco.c
index ac01c40..746c11f 100644 (file)
@@ -30,7 +30,6 @@
 #include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
-#include <linux/major.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/poll.h>
@@ -334,9 +333,6 @@ static void sco_sock_destruct(struct sock *sk)
 
        skb_queue_purge(&sk->sk_receive_queue);
        skb_queue_purge(&sk->sk_write_queue);
-
-       if (sk->sk_protinfo)
-               kfree(sk->sk_protinfo);
 }
 
 static void sco_sock_cleanup_listen(struct sock *parent)
@@ -352,7 +348,7 @@ static void sco_sock_cleanup_listen(struct sock *parent)
        }
 
        parent->sk_state  = BT_CLOSED;
-       parent->sk_zapped = 1;
+       sock_set_flag(parent, SOCK_ZAPPED);
 }
 
 /* Kill socket (only if zapped and orphan)
@@ -360,7 +356,7 @@ static void sco_sock_cleanup_listen(struct sock *parent)
  */
 static void sco_sock_kill(struct sock *sk)
 {
-       if (!sk->sk_zapped || sk->sk_socket)
+       if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket)
                return;
 
        BT_DBG("sk %p state %d", sk, sk->sk_state);
@@ -399,7 +395,7 @@ static void sco_sock_close(struct sock *sk)
                break;
 
        default:
-               sk->sk_zapped = 1;
+               sock_set_flag(sk, SOCK_ZAPPED);
                break;
        };
 
@@ -416,18 +412,29 @@ static void sco_sock_init(struct sock *sk, struct sock *parent)
                sk->sk_type = parent->sk_type;
 }
 
+static struct proto sco_proto = {
+       .name           = "SCO",
+       .owner          = THIS_MODULE,
+       .obj_size       = sizeof(struct sco_pinfo)
+};
+
 static struct sock *sco_sock_alloc(struct socket *sock, int proto, int prio)
 {
        struct sock *sk;
 
-       sk = bt_sock_alloc(sock, proto, sizeof(struct sco_pinfo), prio);
+       sk = sk_alloc(PF_BLUETOOTH, prio, &sco_proto, 1);
        if (!sk)
                return NULL;
 
-       sk_set_owner(sk, THIS_MODULE);
+       sock_init_data(sock, sk);
+       INIT_LIST_HEAD(&bt_sk(sk)->accept_q);
 
        sk->sk_destruct = sco_sock_destruct;
        sk->sk_sndtimeo = SCO_CONN_TIMEOUT;
+
+       sock_reset_flag(sk, SOCK_ZAPPED);
+
+       sk->sk_protocol = proto;
        sk->sk_state    = BT_OPEN;
 
        sco_sock_init_timer(sk);
@@ -778,7 +785,7 @@ static void sco_chan_del(struct sock *sk, int err)
        sk->sk_err   = err;
        sk->sk_state_change(sk);
 
-       sk->sk_zapped = 1;
+       sock_set_flag(sk, SOCK_ZAPPED);
 }
 
 static void sco_conn_ready(struct sco_conn *conn)
@@ -1011,14 +1018,21 @@ static int __init sco_init(void)
 {
        int err;
 
-       if ((err = bt_sock_register(BTPROTO_SCO, &sco_sock_family_ops))) {
-               BT_ERR("SCO socket registration failed");
+       err = proto_register(&sco_proto, 0);
+       if (err < 0)
                return err;
+
+       err = bt_sock_register(BTPROTO_SCO, &sco_sock_family_ops);
+       if (err < 0) {
+               BT_ERR("SCO socket registration failed");
+               goto error;
        }
 
-       if ((err = hci_register_proto(&sco_hci_proto))) {
+       err = hci_register_proto(&sco_hci_proto);
+       if (err < 0) {
                BT_ERR("SCO protocol registration failed");
-               return err;
+               bt_sock_unregister(BTPROTO_SCO);
+               goto error;
        }
 
        sco_proc_init();
@@ -1027,20 +1041,23 @@ static int __init sco_init(void)
        BT_INFO("SCO socket layer initialized");
 
        return 0;
+
+error:
+       proto_unregister(&sco_proto);
+       return err;
 }
 
 static void __exit sco_exit(void)
 {
-       int err;
-
        sco_proc_cleanup();
 
-       /* Unregister socket, protocol and notifier */
-       if ((err = bt_sock_unregister(BTPROTO_SCO)))
-               BT_ERR("SCO socket unregistration failed. %d", err);
+       if (bt_sock_unregister(BTPROTO_SCO) < 0)
+               BT_ERR("SCO socket unregistration failed");
+
+       if (hci_unregister_proto(&sco_hci_proto) < 0)
+               BT_ERR("SCO protocol unregistration failed");
 
-       if ((err = hci_unregister_proto(&sco_hci_proto)))
-               BT_ERR("SCO protocol unregistration failed. %d", err);
+       proto_unregister(&sco_proto);
 }
 
 module_init(sco_init);