patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / net / bluetooth / rfcomm / core.c
index d9b4ce0..a2912da 100644 (file)
@@ -50,7 +50,7 @@
 #include <net/bluetooth/l2cap.h>
 #include <net/bluetooth/rfcomm.h>
 
-#define VERSION "1.2"
+#define VERSION "1.3"
 
 #ifndef CONFIG_BT_RFCOMM_DEBUG
 #undef  BT_DBG
@@ -158,8 +158,7 @@ static int rfcomm_l2sock_create(struct socket **sock)
 
        BT_DBG("");
 
-       err = sock_create_kern(PF_BLUETOOTH, SOCK_SEQPACKET,
-                              BTPROTO_L2CAP, sock);
+       err = sock_create_kern(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP, sock);
        if (!err) {
                struct sock *sk = (*sock)->sk;
                sk->sk_data_ready   = rfcomm_l2data_ready;
@@ -471,32 +470,33 @@ struct rfcomm_session *rfcomm_session_add(struct socket *sock, int state)
        if (!s)
                return NULL;
        memset(s, 0, sizeof(*s));
-       
+
        BT_DBG("session %p sock %p", s, sock);
 
        INIT_LIST_HEAD(&s->dlcs);
        s->state = state;
        s->sock  = sock;
 
-       s->mtu   = RFCOMM_DEFAULT_MTU;
-       s->cfc   = RFCOMM_CFC_UNKNOWN;
-       
-       list_add(&s->list, &session_list);
+       s->mtu = RFCOMM_DEFAULT_MTU;
+       s->cfc = RFCOMM_CFC_UNKNOWN;
 
-       /* Do not increment module usage count for listeting sessions.
-        * Otherwise we won't be able to unload the module.
-        * Non listening session are added either by a socket or a TTYs
-        * which means that we already hold refcount to this module.
-        */
+       /* Do not increment module usage count for listening sessions.
+        * Otherwise we won't be able to unload the module. */
        if (state != BT_LISTEN)
-               __module_get(THIS_MODULE);
+               if (!try_module_get(THIS_MODULE)) {
+                       kfree(s);
+                       return NULL;
+               }
+
+       list_add(&s->list, &session_list);
+
        return s;
 }
 
 void rfcomm_session_del(struct rfcomm_session *s)
 {
        int state = s->state;
-       
+
        BT_DBG("session %p state %ld", s, s->state);
 
        list_del(&s->list);
@@ -1642,9 +1642,9 @@ static inline void rfcomm_accept_connection(struct rfcomm_session *s)
 
        BT_DBG("session %p", s);
 
-       if (sock_create_lite(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP, &nsock))
+       if (sock_create_lite(PF_BLUETOOTH, sock->type, BTPROTO_L2CAP, &nsock))
                return;
-       
+
        nsock->ops  = sock->ops;
 
        __module_get(nsock->ops->owner);