public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* How should an exit routine wait for release() callbacks?
@ 2007-04-12 21:23 Alan Stern
  2007-04-13  9:03 ` Cornelia Huck
  0 siblings, 1 reply; 14+ messages in thread
From: Alan Stern @ 2007-04-12 21:23 UTC (permalink / raw)
  To: USB development list; +Cc: Kernel development list

Here's a not-so-theoretical question.

I've got a module which registers a struct device.  (It represents a
virtual device, not a real one, but that doesn't matter.)  Obviously the
module's exit routine has to wait until the release() routine for that
device has been invoked -- if it returned too early then the release()
call would oops.

How should it wait?

The most straightforward approach is to use a struct completion, like 
this:

	static struct {
		struct device dev;
		...
	} my_dev;

	static DECLARE_COMPLETION(my_completion);

	static void my_release(struct device *dev)
	{
		complete(&my_completion);
	}

	static void __exit my_exit(void)
	{
		device_unregister(&my_dev.dev);
		wait_for_completion(&my_completion);
	}

The problem is that there is no guarantee a context switch won't take
place after my_release() has called complete() and before my_release()  
returns.  If that happens and my_exit() finishes running, then the module
will be unloaded and the next context switch back to finish off
my_release() will oops.

Other approaches have similar defects.  So how can this problem be solved?

Alan Stern


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

end of thread, other threads:[~2007-04-17 15:59 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-12 21:23 How should an exit routine wait for release() callbacks? Alan Stern
2007-04-13  9:03 ` Cornelia Huck
2007-04-13 11:42   ` Markus Rechberger
2007-04-13 13:24     ` Cornelia Huck
2007-04-13 14:15       ` Markus Rechberger
2007-04-13 14:27         ` Cornelia Huck
2007-04-13 15:24           ` Alan Stern
2007-04-16  8:53             ` Cornelia Huck
2007-04-16 14:43               ` Alan Stern
2007-04-16 14:51                 ` [linux-usb-devel] " Robert Marquardt
2007-04-16 15:05                 ` Cornelia Huck
2007-04-16 22:12             ` [linux-usb-devel] " Greg KH
2007-04-17  7:26               ` Cornelia Huck
2007-04-17 15:59               ` Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox