linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] Bluetooth: cmtp: Fix module reference
@ 2011-11-19 12:23 David Herrmann
  2011-11-19 12:23 ` [PATCH 2/2] Bluetooth: bnep: " David Herrmann
  2011-11-19 12:53 ` [PATCH 1/2] Bluetooth: cmtp: " Marcel Holtmann
  0 siblings, 2 replies; 5+ messages in thread
From: David Herrmann @ 2011-11-19 12:23 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: padovan, David Herrmann

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>
---
 net/bluetooth/cmtp/core.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c
index 9e8940b..6c9c1fd 100644
--- a/net/bluetooth/cmtp/core.c
+++ b/net/bluetooth/cmtp/core.c
@@ -65,14 +65,12 @@ static struct cmtp_session *__cmtp_get_session(bdaddr_t *bdaddr)
 
 static void __cmtp_link_session(struct cmtp_session *session)
 {
-	__module_get(THIS_MODULE);
 	list_add(&session->list, &cmtp_session_list);
 }
 
 static void __cmtp_unlink_session(struct cmtp_session *session)
 {
 	list_del(&session->list);
-	module_put(THIS_MODULE);
 }
 
 static void __cmtp_copy_session(struct cmtp_session *session, struct cmtp_conninfo *ci)
@@ -325,6 +323,7 @@ static int cmtp_session(void *arg)
 	up_write(&cmtp_session_sem);
 
 	kfree(session);
+	module_put_and_exit(0);
 	return 0;
 }
 
@@ -374,9 +373,11 @@ int cmtp_add_connection(struct cmtp_connadd_req *req, struct socket *sock)
 
 	__cmtp_link_session(session);
 
+	__module_get(THIS_MODULE);
 	session->task = kthread_run(cmtp_session, session, "kcmtpd_ctr_%d",
 								session->num);
 	if (IS_ERR(session->task)) {
+		module_put(THIS_MODULE);
 		err = PTR_ERR(session->task);
 		goto unlink;
 	}
-- 
1.7.7.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] Bluetooth: bnep: Fix module reference
  2011-11-19 12:23 [PATCH 1/2] Bluetooth: cmtp: Fix module reference David Herrmann
@ 2011-11-19 12:23 ` David Herrmann
  2011-11-19 12:54   ` Marcel Holtmann
  2011-11-21 16:30   ` Gustavo Padovan
  2011-11-19 12:53 ` [PATCH 1/2] Bluetooth: cmtp: " Marcel Holtmann
  1 sibling, 2 replies; 5+ messages in thread
From: David Herrmann @ 2011-11-19 12:23 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: padovan, David Herrmann

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>
---
 net/bluetooth/bnep/core.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
index a6cd856..42d53b8 100644
--- a/net/bluetooth/bnep/core.c
+++ b/net/bluetooth/bnep/core.c
@@ -77,17 +77,12 @@ static struct bnep_session *__bnep_get_session(u8 *dst)
 
 static void __bnep_link_session(struct bnep_session *s)
 {
-	/* It's safe to call __module_get() here because sessions are added
-	   by the socket layer which has to hold the reference to this module.
-	 */
-	__module_get(THIS_MODULE);
 	list_add(&s->list, &bnep_session_list);
 }
 
 static void __bnep_unlink_session(struct bnep_session *s)
 {
 	list_del(&s->list);
-	module_put(THIS_MODULE);
 }
 
 static int bnep_send(struct bnep_session *s, void *data, size_t len)
@@ -528,6 +523,7 @@ static int bnep_session(void *arg)
 
 	up_write(&bnep_session_sem);
 	free_netdev(dev);
+	module_put_and_exit(0);
 	return 0;
 }
 
@@ -614,9 +610,11 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
 
 	__bnep_link_session(s);
 
+	__module_get(THIS_MODULE);
 	s->task = kthread_run(bnep_session, s, "kbnepd %s", dev->name);
 	if (IS_ERR(s->task)) {
 		/* Session thread start failed, gotta cleanup. */
+		module_put(THIS_MODULE);
 		unregister_netdev(dev);
 		__bnep_unlink_session(s);
 		err = PTR_ERR(s->task);
-- 
1.7.7.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] Bluetooth: cmtp: Fix module reference
  2011-11-19 12:23 [PATCH 1/2] Bluetooth: cmtp: Fix module reference David Herrmann
  2011-11-19 12:23 ` [PATCH 2/2] Bluetooth: bnep: " David Herrmann
@ 2011-11-19 12:53 ` Marcel Holtmann
  1 sibling, 0 replies; 5+ messages in thread
From: Marcel Holtmann @ 2011-11-19 12:53 UTC (permalink / raw)
  To: David Herrmann; +Cc: linux-bluetooth, padovan

Hi David,

> 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>
> ---
>  net/bluetooth/cmtp/core.c |    5 +++--
>  1 files changed, 3 insertions(+), 2 deletions(-)

Acked-by: Marcel Holtmann <marcel@holtmann.org>

Regards

Marcel



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] Bluetooth: bnep: Fix module reference
  2011-11-19 12:23 ` [PATCH 2/2] Bluetooth: bnep: " David Herrmann
@ 2011-11-19 12:54   ` Marcel Holtmann
  2011-11-21 16:30   ` Gustavo Padovan
  1 sibling, 0 replies; 5+ messages in thread
From: Marcel Holtmann @ 2011-11-19 12:54 UTC (permalink / raw)
  To: David Herrmann; +Cc: linux-bluetooth, padovan

Hi David,

> 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>
> ---
>  net/bluetooth/bnep/core.c |    8 +++-----
>  1 files changed, 3 insertions(+), 5 deletions(-)

Acked-by: Marcel Holtmann <marcel@holtmann.org>

Regards

Marcel



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] Bluetooth: bnep: Fix module reference
  2011-11-19 12:23 ` [PATCH 2/2] Bluetooth: bnep: " David Herrmann
  2011-11-19 12:54   ` Marcel Holtmann
@ 2011-11-21 16:30   ` Gustavo Padovan
  1 sibling, 0 replies; 5+ messages in thread
From: Gustavo Padovan @ 2011-11-21 16:30 UTC (permalink / raw)
  To: David Herrmann; +Cc: linux-bluetooth

Hi David,

* David Herrmann <dh.herrmann@googlemail.com> [2011-11-19 13:23:33 +0100]:

> 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>
> ---
>  net/bluetooth/bnep/core.c |    8 +++-----
>  1 files changed, 3 insertions(+), 5 deletions(-)

Both patches have been applied, thanks.

	Gustavo

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-11-21 16:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-19 12:23 [PATCH 1/2] Bluetooth: cmtp: Fix module reference David Herrmann
2011-11-19 12:23 ` [PATCH 2/2] Bluetooth: bnep: " David Herrmann
2011-11-19 12:54   ` Marcel Holtmann
2011-11-21 16:30   ` Gustavo Padovan
2011-11-19 12:53 ` [PATCH 1/2] Bluetooth: cmtp: " Marcel Holtmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).