linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] Input: Remove unsafe device module references
@ 2011-11-01 15:41 David Herrmann
  2011-11-01 17:01 ` Greg KH
  0 siblings, 1 reply; 12+ messages in thread
From: David Herrmann @ 2011-11-01 15:41 UTC (permalink / raw)
  To: linux-input; +Cc: dmitry.torokhov, gregkh, linux-kernel, David Herrmann

Hi Dmitry and Greg

It doesn't make sense to take a reference to our own module. When we call
module_put(THIS_MODULE) we cannot make sure that our module is still alive when
this function returns. Therefore, module_put() will return to invalid memory and
our input_dev_release() function is no longer available.

It would be interesting if Greg could elaborate what else we could do to replace
this module-refcount as it is definitely needed here. However, "struct device"
doesn't provide an owner field so there is no way for us to let the device core
keep a reference to our module.

I have no clue what to do here but the current implementation is definitely
unsafe so this is marked as RFC. Currently, the device_attributes probably
already keep a reference to our module so applying this patch would probably not
break anything, however, this does not look like something we can trust on.

My bug-thread kind of died (https://lkml.org/lkml/2011/10/29/75) so I now try to
show this with an example here.

Regards
David

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
---
 drivers/input/input.c |    4 ----
 1 files changed, 0 insertions(+), 4 deletions(-)

diff --git a/drivers/input/input.c b/drivers/input/input.c
index da38d97..f691502 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -1417,8 +1417,6 @@ static void input_dev_release(struct device *device)
 	input_mt_destroy_slots(dev);
 	kfree(dev->absinfo);
 	kfree(dev);
-
-	module_put(THIS_MODULE);
 }
 
 /*
@@ -1657,8 +1655,6 @@ struct input_dev *input_allocate_device(void)
 		spin_lock_init(&dev->event_lock);
 		INIT_LIST_HEAD(&dev->h_list);
 		INIT_LIST_HEAD(&dev->node);
-
-		__module_get(THIS_MODULE);
 	}
 
 	return dev;
-- 
1.7.7.1


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

end of thread, other threads:[~2011-11-02 14:43 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-01 15:41 [RFC] Input: Remove unsafe device module references David Herrmann
2011-11-01 17:01 ` Greg KH
2011-11-01 17:52   ` Dmitry Torokhov
2011-11-01 17:58     ` Greg KH
2011-11-01 17:52   ` David Herrmann
2011-11-01 18:00     ` Greg KH
2011-11-01 18:09       ` David Herrmann
2011-11-01 18:18         ` Dmitry Torokhov
2011-11-02 13:45           ` David Herrmann
2011-11-02 14:43             ` Greg KH
2011-11-01 18:05     ` Dmitry Torokhov
2011-11-01 18:16       ` David Herrmann

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).