All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gerd Knorr <kraxel@bytesex.org>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: Gerd Knorr <kraxel@suse.de>,
	Johannes Stezenbach <js@convergence.de>,
	Johannes Stezenbach <js@linuxtv.org>,
	Takashi Iwai <tiwai@suse.de>,
	"Alexander E. Patrakov" <patrakov@ums.usu.ru>,
	lkml - Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: modprobe + request_module() deadlock
Date: Thu, 25 Nov 2004 17:03:39 +0100	[thread overview]
Message-ID: <20041125160339.GA3504@bytesex> (raw)
In-Reply-To: <1101272551.6186.25.camel@localhost.localdomain>

On Wed, Nov 24, 2004 at 04:02:31PM +1100, Rusty Russell wrote:
> On Mon, 2004-11-22 at 17:52 +0100, Gerd Knorr wrote:
> > > > I can fix that in the driver, by delaying the request_module() somehow
> > > > until the saa7134 module initialization is finished.  I don't think that
> > > > this is a good idea through as it looks like I'm not the only one with
> > > > that problem ...
> > > 
> > > Delaying request_module() sounds ugly. Anyway, if you can
> > > get it to work reliably...
> > 
> > I think I can, havn't tried yet through.

Untested proof-of-concept code (don't have a saa7134 card in my machine
at the moment), but that way it could work I think.  Tried to keep it
generic.  Basically it keeps a list of pending module loads and the
dependencies.  Then it hooks into the module state notifier chain and
calls request_module() once the depending module went to LIVE state.

Comments?

  Gerd

Index: saa7134-core.c
===================================================================
RCS file: /home/cvsroot/video4linux/saa7134-core.c,v
retrieving revision 1.20
diff -u -p -r1.20 saa7134-core.c
--- saa7134-core.c	23 Nov 2004 17:29:09 -0000	1.20
+++ saa7134-core.c	25 Nov 2004 15:54:23 -0000
@@ -233,6 +233,75 @@ static void dump_statusregs(struct saa71
 }
 #endif
 
+/* ----------------------------------------------------------- */
+
+struct pending_module {
+	struct module    *dep;
+	char             *name;
+	struct list_head next;
+};
+
+static int pending_call(struct notifier_block *self, unsigned long state,
+			void *module);
+
+static LIST_HEAD(pending_modules);
+static struct notifier_block pending_notifier = {
+	.notifier_call = pending_call,
+};
+
+static int pending_call(struct notifier_block *self, unsigned long state,
+			void *module)
+{
+	struct list_head *item;
+	struct pending_module *mod = NULL;
+
+	list_for_each(item,&pending_modules) {
+		mod = list_entry(item, struct pending_module, next);
+		if (mod->dep == module)
+			break;
+		mod = NULL;
+	}
+	if (NULL == mod)
+		return NOTIFY_DONE;
+
+	switch (state) {
+	case MODULE_STATE_LIVE:
+		request_module(mod->name);
+		/* fall through */
+	case MODULE_STATE_GOING:
+		list_del(&mod->next);
+		kfree(mod);
+		if (list_empty(&pending_modules))
+			unregister_module_notifier(&pending_notifier);
+		break;
+	}
+	return NOTIFY_DONE;
+}
+
+static void request_module_depend(struct module *dep, char *name)
+{
+	struct pending_module *mod;
+
+	switch (dep->state) {
+	case MODULE_STATE_COMING:
+		mod = kmalloc(sizeof(mod),GFP_KERNEL);
+		if (NULL == mod)
+			return;
+		mod->dep  = dep;
+		mod->name = name;
+		if (list_empty(&pending_modules))
+			register_module_notifier(&pending_notifier);
+		list_add(&mod->next,&pending_modules);
+		break;
+	case MODULE_STATE_LIVE:
+		request_module(name);
+		break;
+	default:
+		/* nothing */;
+		break;
+	}
+}
+
 /* ------------------------------------------------------------------ */
 
 /* nr of (saa7134-)pages for the given buffer size */
@@ -954,12 +1023,12 @@ static int __devinit saa7134_initdev(str
 		request_module("tuner");
 	if (dev->tda9887_conf)
 		request_module("tda9887");
-  	if (card_is_empress(dev)) {
-		request_module("saa7134-empress");
+  	if (1 /* card_is_empress(dev) */) {
+		request_module_depend(THIS_MODULE,"saa7134-empress");
 		request_module("saa6752hs");
 	}
-  	if (card_is_dvb(dev))
-		request_module("saa7134-dvb");
+  	if (1 /* card_is_dvb(dev) */)
+		request_module_depend(THIS_MODULE,"saa7134-dvb");
 
 	v4l2_prio_init(&dev->prio);
 

  parent reply	other threads:[~2004-11-26 20:12 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-17 22:29 modprobe + request_module() deadlock Johannes Stezenbach
2004-11-18  3:48 ` Rusty Russell
2004-11-18 13:55   ` Johannes Stezenbach
2004-11-18 19:05     ` Takashi Iwai
2004-11-19  4:04       ` Alexander E. Patrakov
2004-11-19 11:10         ` Takashi Iwai
2004-11-19 11:50           ` Gerd Knorr
2004-11-19 12:42             ` Alexander E. Patrakov
2004-11-21  8:39             ` Rusty Russell
2004-11-22 10:25               ` Gerd Knorr
2004-11-22 14:16                 ` Johannes Stezenbach
2004-11-22 14:44                   ` Gerd Knorr
2004-11-22 15:36                     ` Johannes Stezenbach
2004-11-22 16:52                       ` Gerd Knorr
2004-11-24  5:02                         ` Rusty Russell
2004-11-24 12:11                           ` Gerd Knorr
2004-11-25 16:03                           ` Gerd Knorr [this message]
2004-11-26  0:34                             ` Rusty Russell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20041125160339.GA3504@bytesex \
    --to=kraxel@bytesex.org \
    --cc=js@convergence.de \
    --cc=js@linuxtv.org \
    --cc=kraxel@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patrakov@ums.usu.ru \
    --cc=rusty@rustcorp.com.au \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.