Skip to content

Commit 25df084

Browse files
David HerrmannGustavo F. Padovan
authored andcommitted
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>
1 parent 7f103a0 commit 25df084

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎net/bluetooth/hidp/core.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ static struct hidp_session *__hidp_get_session(bdaddr_t *bdaddr)
9494

9595
static void __hidp_link_session(struct hidp_session *session)
9696
{
97-
__module_get(THIS_MODULE);
9897
list_add(&session->list, &hidp_session_list);
9998
}
10099

@@ -103,7 +102,6 @@ static void __hidp_unlink_session(struct hidp_session *session)
103102
hci_conn_put_device(session->conn);
104103

105104
list_del(&session->list);
106-
module_put(THIS_MODULE);
107105
}
108106

109107
static void __hidp_copy_session(struct hidp_session *session, struct hidp_conninfo *ci)
@@ -703,6 +701,7 @@ static int hidp_session(void *arg)
703701

704702
BT_DBG("session %p", session);
705703

704+
__module_get(THIS_MODULE);
706705
set_user_nice(current, -15);
707706

708707
init_waitqueue_entry(&ctrl_wait, current);
@@ -781,6 +780,7 @@ static int hidp_session(void *arg)
781780

782781
kfree(session->rd_data);
783782
kfree(session);
783+
module_put_and_exit(0);
784784
return 0;
785785
}
786786

0 commit comments

Comments
 (0)