aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/cmtp
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@googlemail.com>2011-11-19 07:23:32 -0500
committerGustavo F. Padovan <padovan@profusion.mobi>2011-11-21 11:28:45 -0500
commit48b28b8db9a74cc5c43e76485dc397e22bea2984 (patch)
tree1381e6eecede87f48603be76da5347d5d2245878 /net/bluetooth/cmtp
parent2ac654f740b574c58ee02bac3816cf466a1bfb41 (diff)
Bluetooth: cmtp: Fix module reference
We cannot call module_put(THIS_MODULE) if this is our last reference. Otherwise, this call may cleanup our module before it returns. Gladly, the kthread API provides a simple wrapper for us. So lets use module_put_and_exit() to avoid a race condition with the module cleanup code. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com> Acked-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
Diffstat (limited to 'net/bluetooth/cmtp')
-rw-r--r--net/bluetooth/cmtp/core.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c
index 7d00ddf9e9dc..5a6e634f7fca 100644
--- a/net/bluetooth/cmtp/core.c
+++ b/net/bluetooth/cmtp/core.c
@@ -67,14 +67,12 @@ static struct cmtp_session *__cmtp_get_session(bdaddr_t *bdaddr)
67 67
68static void __cmtp_link_session(struct cmtp_session *session) 68static void __cmtp_link_session(struct cmtp_session *session)
69{ 69{
70 __module_get(THIS_MODULE);
71 list_add(&session->list, &cmtp_session_list); 70 list_add(&session->list, &cmtp_session_list);
72} 71}
73 72
74static void __cmtp_unlink_session(struct cmtp_session *session) 73static void __cmtp_unlink_session(struct cmtp_session *session)
75{ 74{
76 list_del(&session->list); 75 list_del(&session->list);
77 module_put(THIS_MODULE);
78} 76}
79 77
80static void __cmtp_copy_session(struct cmtp_session *session, struct cmtp_conninfo *ci) 78static void __cmtp_copy_session(struct cmtp_session *session, struct cmtp_conninfo *ci)
@@ -327,6 +325,7 @@ static int cmtp_session(void *arg)
327 up_write(&cmtp_session_sem); 325 up_write(&cmtp_session_sem);
328 326
329 kfree(session); 327 kfree(session);
328 module_put_and_exit(0);
330 return 0; 329 return 0;
331} 330}
332 331
@@ -376,9 +375,11 @@ int cmtp_add_connection(struct cmtp_connadd_req *req, struct socket *sock)
376 375
377 __cmtp_link_session(session); 376 __cmtp_link_session(session);
378 377
378 __module_get(THIS_MODULE);
379 session->task = kthread_run(cmtp_session, session, "kcmtpd_ctr_%d", 379 session->task = kthread_run(cmtp_session, session, "kcmtpd_ctr_%d",
380 session->num); 380 session->num);
381 if (IS_ERR(session->task)) { 381 if (IS_ERR(session->task)) {
382 module_put(THIS_MODULE);
382 err = PTR_ERR(session->task); 383 err = PTR_ERR(session->task);
383 goto unlink; 384 goto unlink;
384 } 385 }