firewire: fix "kobject_add failed for fw* with -EEXIST"
authorStefan Richter <stefanr@s5r6.in-berlin.de>
Sat, 2 Feb 2008 14:01:09 +0000 (15:01 +0100)
committerStefan Richter <stefanr@s5r6.in-berlin.de>
Sat, 16 Feb 2008 14:40:33 +0000 (15:40 +0100)
commit96b19062e741b715cf399312c30e0672d8889569
treeb0e2197ab7380590bdff00e02dde19e81952a33f
parent1b9c12ba2fdf802a23630f70eddb0e821296634e
firewire: fix "kobject_add failed for fw* with -EEXIST"

There is a race between shutdown and creation of devices:  fw-core may
attempt to add a device with the same name of an already existing
device.  http://bugzilla.kernel.org/show_bug.cgi?id=9828

Impact of the bug:  Happens rarely (when shutdown of a device coincides
with creation of another), forces the user to unplug and replug the new
device to get it working.

The fix is obvious:  Free the minor number *after* instead of *before*
device_unregister().  This requires to take an additional reference of
the fw_device as long as the IDR tree points to it.

And while we are at it, we fix an additional race condition:
fw_device_op_open() took its reference of the fw_device a little bit too
late, hence was in danger to access an already invalid fw_device.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
drivers/firewire/fw-cdev.c
drivers/firewire/fw-device.c
drivers/firewire/fw-device.h