aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@googlemail.com>2011-11-01 12:27:50 -0400
committerGustavo F. Padovan <padovan@profusion.mobi>2011-11-07 14:24:54 -0500
commit25df0845e054f70a8735ee0184739472d8a573c9 (patch)
tree090ca61b8fbe3f97e4f5549ebe444ea5ea8fa728 /net/bluetooth
parent7f103a0d23d2778b86cea407c1992522d41ead81 (diff)
Bluetooth: hidp: Fix module reference cleanup
Calling module_put(THIS_MODULE) is *never* safe when we cannot go sure that we own at least two references. This is because the call may unload our module before it returns and then the "return" will jump into invalid memory. Gladly, module.h provides a wrapper for kthread-users: module_put_and_exit(). This puts our module and then exits the kthread without returning to the module. This patch fixes the hidp kthread to use this wrapper instead of manually freeing its own reference. See nfsd or lockd for other kthreads using this. Calling __module_get() inside the kthread is safe as the hidp module will always wait until the kthread sets "waiting_for_startup" to 0. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
Diffstat (limited to 'net/bluetooth')
-rw-r--r--net/bluetooth/hidp/core.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
index 2efd6cc58b66..56dc660d234a 100644
--- a/net/bluetooth/hidp/core.c
+++ b/net/bluetooth/hidp/core.c
@@ -94,7 +94,6 @@ static struct hidp_session *__hidp_get_session(bdaddr_t *bdaddr)
94 94
95static void __hidp_link_session(struct hidp_session *session) 95static void __hidp_link_session(struct hidp_session *session)
96{ 96{
97 __module_get(THIS_MODULE);
98 list_add(&session->list, &hidp_session_list); 97 list_add(&session->list, &hidp_session_list);
99} 98}
100 99
@@ -103,7 +102,6 @@ static void __hidp_unlink_session(struct hidp_session *session)
103 hci_conn_put_device(session->conn); 102 hci_conn_put_device(session->conn);
104 103
105 list_del(&session->list); 104 list_del(&session->list);
106 module_put(THIS_MODULE);
107} 105}
108 106
109static void __hidp_copy_session(struct hidp_session *session, struct hidp_conninfo *ci) 107static void __hidp_copy_session(struct hidp_session *session, struct hidp_conninfo *ci)
@@ -703,6 +701,7 @@ static int hidp_session(void *arg)
703 701
704 BT_DBG("session %p", session); 702 BT_DBG("session %p", session);
705 703
704 __module_get(THIS_MODULE);
706 set_user_nice(current, -15); 705 set_user_nice(current, -15);
707 706
708 init_waitqueue_entry(&ctrl_wait, current); 707 init_waitqueue_entry(&ctrl_wait, current);
@@ -781,6 +780,7 @@ static int hidp_session(void *arg)
781 780
782 kfree(session->rd_data); 781 kfree(session->rd_data);
783 kfree(session); 782 kfree(session);
783 module_put_and_exit(0);
784 return 0; 784 return 0;
785} 785}
786 786