Re: device model update 2/2

Linus Torvalds (torvalds@transmeta.com)
Thu, 6 Jun 2002 16:45:25 +0000 (UTC)


In article <Pine.LNX.4.33.0206060808050.654-100000@geena.pdx.osdl.net>,
Patrick Mochel <mochel@osdl.org> wrote:
>-
> /* detach from driver */
> if (dev->driver->remove)
> dev->driver->remove(dev);
> put_driver(dev->driver);
>+
>+ lock_device(dev);
>+ dev->driver = NULL;
>+ unlock_device(dev);

Code like the above just basically can _never_ be correct.

The locking just doesn't make any sense like that.

Real locking looks something like this:

lock_device(dev);
driver = dev->driver;
dev->driver = NULL;
unlock_device(dev);

if (driver->remove)
driver->remove(dev);
put_driver(driver);

together with some promise that "dev" cannot go away from under us (ie a
refcount on "dev" itself).

Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/