linux/drivers
Patrick Mochel 0d3e5a2e39 [PATCH] Driver Core: fix bk-driver-core kills ppc64
There's no check to see if the device is already bound to a driver, which
could do bad things.  The first thing to go wrong is that it will try to match
a driver with a device already bound to one.  In some cases (it appears with
USB with drivers/usb/core/usb.c::usb_match_id()), some drivers will match a
device based on the class type, so it would be common (especially for HID
devices) to match a device that is already bound.

The fun comes when ->probe() is called, it fails, then
driver_probe_device() does this:

	dev->driver = NULL;

Later on, that pointer could be be dereferenced without checking and cause
hell to break loose.

This problem could be nasty. It's very hardware dependent, since some
devices could have a different set of matching qualifiers than others.

Now, I don't quite see exactly where/how you were getting that crash.
You're dereferencing bad memory, but I'm not sure which pointer was bad
and where it came from, but it could have come from a couple of different
places.

The patch below will hopefully fix it all up for you. It's against
2.6.12-rc2-mm1, and does the following:

- Move logic to driver_probe_device() and comments uncommon returns:
  1 - If device is bound
  0 - If device not bound, and no error
  error - If there was an error.

- Move locking to caller of that function, since we want to lock a
  device for the entire time we're trying to bind it to a driver (to
  prevent against a driver being loaded at the same time).

- Update __device_attach() and __driver_attach() to do that locking.

- Check if device is already bound in __driver_attach()

- Update the converse device_release_driver() so it locks the device
  around all of the operations.

- Mark driver_probe_device() as static and remove export. It's an
  internal function, it should stay that way, and there are no other
  callers. If there is ever a need to export it, we can audit it as
  necessary.

Signed-off-by: Andrew Morton <akpm@osdl.org>
2005-06-20 15:15:27 -07:00
..
acorn Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
acpi [PATCH] sysfs: (rest) if show/store is missing return -EIO 2005-06-20 15:15:03 -07:00
atm [ATM]: [drivers] kill pointless NULL checks and casts before kfree() 2005-06-02 13:04:07 -07:00
base [PATCH] Driver Core: fix bk-driver-core kills ppc64 2005-06-20 15:15:27 -07:00
block [PATCH] class: convert drivers/block/* to use the new class api instead of class_simple 2005-06-20 15:15:07 -07:00
bluetooth Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
cdrom [PATCH] ppc64 iSeries: make virtual DVD-RAMs writable again 2005-05-28 11:14:00 -07:00
char [PATCH] fix up ipmi code after class_simple.c removal 2005-06-20 15:15:12 -07:00
cpufreq [PATCH] sysfs: (rest) if show/store is missing return -EIO 2005-06-20 15:15:03 -07:00
crypto Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
dio Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
eisa Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
fc4 [SCSI] allow sleeping in ->eh_host_reset_handler() 2005-06-17 12:05:18 -05:00
firmware [PATCH] sysfs: (rest) if show/store is missing return -EIO 2005-06-20 15:15:03 -07:00
i2c [PATCH] I2C: ALI1563 SMBus driver fix 2005-05-31 14:03:05 -07:00
ide [PATCH] PCI: amd74xx patch for new NVIDIA device IDs 2005-05-31 14:26:38 -07:00
ieee1394 [PATCH] Use device_for_each_child() to unregister devices in nodemgr_remove_host_dev() 2005-06-20 15:15:26 -07:00
infiniband [PATCH] sysfs: (rest) if show/store is missing return -EIO 2005-06-20 15:15:03 -07:00
input [PATCH] INPUT: move to use the new class code, instead of class_simple 2005-06-20 15:15:04 -07:00
isdn [PATCH] class: convert drivers/* to use the new class api instead of class_simple 2005-06-20 15:15:09 -07:00
macintosh [PATCH] class: convert drivers/* to use the new class api instead of class_simple 2005-06-20 15:15:09 -07:00
mca Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
md [PATCH] dm: Handle READA requests in dm-mpath.c 2005-06-08 16:21:14 -07:00
media [PATCH] class: convert drivers/* to use the new class api instead of class_simple 2005-06-20 15:15:09 -07:00
message merge by hand (fix up qla_os.c merge error) 2005-06-17 18:42:23 -05:00
misc Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
mmc [PATCH] MMC: Proper MMC command classes support 2005-05-21 10:27:02 +01:00
mtd [PATCH] fix u32 vs. pm_message_t in drivers/mmc,mtd,scsi 2005-04-16 15:25:29 -07:00
net [PATCH] class: convert drivers/* to use the new class api instead of class_simple 2005-06-20 15:15:09 -07:00
nubus Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
oprofile [PATCH] oprofile trivial user annotations 2005-04-26 07:43:42 -07:00
parisc Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
parport [PATCH] ISA_DMA Kconfig fixes - part 2 (parport_pc) 2005-05-04 07:33:13 -07:00
pci [PATCH] use device_for_each_child() to properly access child devices. 2005-06-20 15:15:26 -07:00
pcmcia [PATCH] pcmcia/ds: handle any error code 2005-05-17 07:59:21 -07:00
pnp [PATCH] Use driver_for_each_device() in drivers/pnp/driver.c instead of manually walking list. 2005-06-20 15:15:13 -07:00
s390 [PATCH] class: convert drivers/* to use the new class api instead of class_simple 2005-06-20 15:15:09 -07:00
sbus [SPARC]: Eliminate local MIN/MAX macros in drivers/sbus/char/aurora.c 2005-05-15 16:01:50 -07:00
scsi [PATCH] use device_for_each_child() to properly access child devices. 2005-06-20 15:15:22 -07:00
serial [PATCH] Serial: remove unused variable in sa1100 driver 2005-06-08 19:26:47 +01:00
sh Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
sn Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
tc Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
telephony [PATCH] ixj* - compile warning cleanup 2005-05-05 16:36:48 -07:00
usb [PATCH] USB: fix build warning in usb core as pointed out by Andrew. 2005-06-20 15:15:26 -07:00
video [PATCH] class: convert drivers/* to use the new class api instead of class_simple 2005-06-20 15:15:09 -07:00
w1 [PATCH] w1_smem: w1 ID is only 8 bytes long. 2005-04-18 21:16:57 -07:00
zorro Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
Kconfig Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00
Makefile Linux-2.6.12-rc2 2005-04-16 15:20:36 -07:00