#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
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;
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);
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);