Re: [RFC] [PATCH] driver core: allow userspace to unbind drivers from devices.

From: Greg KH
Date: Tue Nov 09 2004 - 19:37:07 EST

On Tue, Nov 09, 2004 at 06:36:52PM -0500, Dmitry Torokhov wrote:
> Hi Greg,
> On Tue, 9 Nov 2004 14:37:29 -0800, Greg KH <greg@xxxxxxxxx> wrote:
> > Ok, everone's been back and forth about the whole bind/unbind stuff
> > lately, so let's just do this a step at a time.
> >
> > How about the following patch. It adds a "unbind" file to any device
> > that is bound to a driver. Writing any value to that file disconnects
> > the device from the driver associated with it.
> >
> > It's small, simple, and it works.
> >
> > It also can cause bad things to happen if you aren't careful about what
> > type of device you are unbinding (some i2c chip devices don't really
> > unbind from the driver fully, but that's an i2c issue, and I'm working
> > on it.)
> >
> > Also, unbinding a device from a driver can cause the children devices to
> > disappear, depending on the type of driver that is bound to the device.
> With the present implementation it is pretty much impossible to do
> since unbind grabs bus's rwsem. That means that any driver attempting
> to remove children will deadlock. Driver core is not aware of evry bus's
> topology issues that's why you need a bus method to do proper locking
> and children removal.

Ok, in looking some more at this, you are right.

So, how to solve this. I don't want a bus callback for bind, unbind,
re-bind, bind-every-other-day-depending-on-the-phase-of-the-moon, and so
on. I really think we can do this with the current callbacks that we
have today.

All we have to do is rework that rwsem lock. It's been staring at us
since the beginning of the driver core work, and we knew it would have
to be fixed eventually. So might as well do it now.

Unfortunatly it seems everyone likes to grab that lock, so it's not
going to be a simple thing to fix (in their defense, we encouraged
people to grab the lock, so it's our fault too.)

So, if we fix up the locking issues, then we can do the following, which
I know people have been wanting to do:
- add new devices from within a probe() callback.
- remove other devices from within a probe() callback.
- remove other devices from the remove() callback.
- unbind devices from the driver core.

and other good stuff.

So, off to rework this mess...


greg k-h
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at