mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Patch: linux-2.5.58/drivers/base/bus.c ignored pre-existing devices
@ 2003-01-15 10:52 Adam J. Richter
  2003-01-15 16:23 ` Patrick Mochel
  0 siblings, 1 reply; 3+ messages in thread
From: Adam J. Richter @ 2003-01-15 10:52 UTC (permalink / raw)
  To: mochel; +Cc: tomlins, felix-linuxkernel, linux-kernel, greg

[-- Attachment #1: Type: text/plain, Size: 2010 bytes --]

Hi Patrick,

	device_attach() in linux-2.5.5[78]/drivers/base/bus.c has a
bug.  Any device that is detected before its driver is loaded is
forgotten.

	I noticed this bug when my keyboard and mouse stopped working
and thought that it might be an interrupt routing problem, but Ed
Tomlinson emailed me with a critical observation that I hadn't
noticed: if you unplug the USB devices and plug them back in, they
start to work.  Many thanks to Ed for saving me probably several hours
of bug tracking.  I suppose this is a pretty good example Eric Raymond's
mixed metaphor "given enough eyeballs, all bugs are shallow."

	It's also a good example of the benefits of parts of
drivers/base.  If this bug had only occured in the PCI hot plugging
code, it's unlikely it would have been noticed, but because the code
was common, the bug was noticed much more quickly (both my USB keyboard
and CardBus networking card were no longer binding to their devices).

	Anyhow, getting back to business, the problem arose due to a
botched change in drivers/base/bus.c that apprently was intended to
allow a driver->probe function to return an error other than -ENODEV
and thereby cause the whole binding process to abort.  At least that's
what I think the extra code was inteded to do.  If not, I could shrink
the code by making device_attach return void.

	Here is the patch.  Note that the line numbers will be off
because I have other changes in my bus.c (kmalloc and
dma_alloc_consistent preallocations for drivers that request them,
which I posted before).  Please integrate (or fix the bug some other
way) and forward to Linus.  It will avoid repititious bug reports
if we this bug is gone from Linus's last current release when he
leaves for vacaction.

-- 
Adam J. Richter     __     ______________   575 Oroville Road
adam@yggdrasil.com     \ /                  Milpitas, California 95035
+1 408 309-6081         | g g d r a s i l   United States of America
                         "Free Software For The Rest Of Us."

[-- Attachment #2: bus.diff --]
[-- Type: text/plain, Size: 817 bytes --]

--- linux-2.5.58/drivers/base/bus.c	2003-01-13 21:58:25.000000000 -0800
+++ linux/drivers/base/bus.c	2003-01-15 02:09:48.000000000 -0800
@@ -283,28 +326,28 @@
  *	for each pair. If a compatible pair is found, break out and return.
  */
 static int device_attach(struct device * dev)
 {
  	struct bus_type * bus = dev->bus;
 	struct list_head * entry;
-	int error = 0;
 
 	if (dev->driver) {
 		device_bind_driver(dev);
 		return 0;
 	}
 
 	if (!bus->match)
 		return 0;
 
 	list_for_each(entry,&bus->drivers.list) {
 		struct device_driver * drv = to_drv(entry);
-		if (!(error = bus_match(dev,drv)))
-			break;
+		int error = bus_match(dev,drv);
+		if (error != 0 && error != -ENODEV)
+			return error;
 	}
-	return error;
+	return 0;
 }
 
 
 /**
  *	driver_attach - try to bind driver to devices.
  *	@drv:	driver.

^ permalink raw reply	[flat|nested] 3+ messages in thread
* Re: Patch: linux-2.5.58/drivers/base/bus.c ignored pre-existing devices
@ 2003-01-15 22:01 Adam J. Richter
  0 siblings, 0 replies; 3+ messages in thread
From: Adam J. Richter @ 2003-01-15 22:01 UTC (permalink / raw)
  To: mochel; +Cc: felix-linuxkernel, greg, linux-kernel, tomlins

On 2003-01-15, Patrick Mochel wrote:
>The extra code was an attempt at properly handling failure of ->probe(),
>and to make sure that an error from ->probe() (e.g. -ENOMEM) is propogated
>up.
>
>The cause of the problem you're seeing is that if a device wasn't bound to 
>a driver, -ENODEV was returned, causing it to be removed from the bus's 
>list of devices. 
>
>To remedy this, I've changed the semantics of bus_match() to return the 
>following:
>
>* 1     if device was bound to a driver.
>* 0     if it wasn't 
>* <0    if drv->probe() returned an error. 
>
>This allows the caller to know if binding happened, as well as bubble the 
>error up.

	I have't tried your patch, but, from reading it, I infer that
your patch would not work with drivers that do further matching
in their probe function and return -ENODEV, which should be handled
as if match() function failed.  I suggest you use my patch.

Adam J. Richter     __     ______________   575 Oroville Road
adam@yggdrasil.com     \ /                  Milpitas, California 95035
+1 408 309-6081         | g g d r a s i l   United States of America
                         "Free Software For The Rest Of Us."

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

end of thread, other threads:[~2003-01-15 21:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-15 10:52 Patch: linux-2.5.58/drivers/base/bus.c ignored pre-existing devices Adam J. Richter
2003-01-15 16:23 ` Patrick Mochel
2003-01-15 22:01 Adam J. Richter

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

all inboxes | Powered by JetHome®