Commit f1b6caac authored by Marcel Holtmann's avatar Marcel Holtmann

[Bluetooth] Use try_module_get() for RFCOMM sessions

It is not possible to use __module_get() when adding a new RFCOMM
session, because there is a case where no reference count is hold.
This happens when the module is not in use right now and an incoming
connection occurs.
parent 9ea9778e
...@@ -470,32 +470,33 @@ struct rfcomm_session *rfcomm_session_add(struct socket *sock, int state) ...@@ -470,32 +470,33 @@ struct rfcomm_session *rfcomm_session_add(struct socket *sock, int state)
if (!s) if (!s)
return NULL; return NULL;
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
BT_DBG("session %p sock %p", s, sock); BT_DBG("session %p sock %p", s, sock);
INIT_LIST_HEAD(&s->dlcs); INIT_LIST_HEAD(&s->dlcs);
s->state = state; s->state = state;
s->sock = sock; s->sock = sock;
s->mtu = RFCOMM_DEFAULT_MTU; s->mtu = RFCOMM_DEFAULT_MTU;
s->cfc = RFCOMM_CFC_UNKNOWN; s->cfc = RFCOMM_CFC_UNKNOWN;
list_add(&s->list, &session_list);
/* Do not increment module usage count for listeting sessions. /* Do not increment module usage count for listening sessions.
* Otherwise we won't be able to unload the module. * 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.
*/
if (state != BT_LISTEN) 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; return s;
} }
void rfcomm_session_del(struct rfcomm_session *s) void rfcomm_session_del(struct rfcomm_session *s)
{ {
int state = s->state; int state = s->state;
BT_DBG("session %p state %ld", s, s->state); BT_DBG("session %p state %ld", s, s->state);
list_del(&s->list); list_del(&s->list);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment