| Age | Commit message (Collapse) | Author | Files | Lines |
|
Get rid of semaphore abuse by converting device_driver->unload_sem
semaphore to device_driver->unloaded completion.
This should get rid of any confusion as well as save a few bytes in the
process.
Signed-off-by: Mike Waychison <michael.waychison@sun.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
|
|
Signed-off-by: Patrick Mochel <mochel@digitalimplant.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
|
|
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
|
|
Whitespace and formatting changes (a,b,c -> a, b, c) in drivers/base
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
|
|
|
|
|
|
It's a slow afternoon.
|
|
Removes the device_class, devclass_attribute, and device_interface structures
and replaces them with class, class_device, and class_interface structures.
This allows us to have multiple class_device structures per device structures
which mirrors the ways things really are within the kernel. It also allows
class_device structures to be created later than struct devices as they
are naturally created much later in the initialization process of a device.
|
|
|
|
|
|
This a multi-pronged attack aimed at exploiting the kobject infrastructure mor.
- Remove bus_driver_list, in favor of list in bus_subys.
- Remove bus_for_each_* and driver_for_each_dev(). They're not being used by
anyone, have questionable locking semantics, and really don't provide that
much use, as the function returns once the callback fails, with no indication
of where it failed. Forget them, at least for now.
- Make sure that we return success from bus_match() if device matches, but
doesn't have a probe method.
- Remove extraneous get_{device,driver}s from bus routines that are serialized
by the bus's rwsem. bus_{add,remove}_{device,driver} all take the rwsem, so there
is no way we can get a non-existant object when in those functions.
- Use the rwsem in the struct subsystem the bus has embedded in it, and kill the
separate one in struct bus_type.
- Move bulk of driver_register() into bus_add_driver(), which holds the bus's
rwsem during the entirety. this will prevent the driver from being unloaded while
it's being registered, and two drivers with the same name getting registered
at the same time.
- Ditto for driver_unregister() and bus_remove_driver().
- Add driver_release() method for the driver bus driver subsystems. (Explained later)
- Use only the refcounts in the buses' kobjects, and kill the one in struct bus_type.
- Kill struct bus_type::present and struct device_driver::present. These didn't
work out the way we intended them to. The idea was to not let a user obtain a
rerference count to the object if it was in the process of being unregistered.
All the code paths should be fixed now such that their registration is protected with
a semaphore, so no partially initialized objects can be removed, and enough
infrastructure is moved to the kobject model so that once the object is publically
visible, it should be usable by other sources.
- Add a bus_sem to serialize bus registration and unregistration.
- Add struct device_driver::unload_sem to prevent unloading of drivers
with a positive reference count.
The driver model has always had a bug that would allow a driver with a
positive reference count to be unloaded. It would decrement the reference
count and return, letting the module be unloaded, without accounting for
the other users of the object. This has been discussed many times, though
never resolved cleanly. This should fix the problem in the simplest manner.
struct device_driver gets unload_sem, which is initialized to _locked_. When
the reference count for the driver reaches 0, the semaphore is unlocked.
driver_unregister() blocks on acquiring this lock before it exits. In the
normal case that driver_unregister() drops the last reference to the driver,
the lock will be acquired immediately, and the module will unload.
In the case that someone else is using the driver object, driver_unregister()
will not be able to acquire the lock, since the refcount has not reached 0,
and the lock has not been released.
This means that rmmod(8) will block while drivers' sysfs files are open.
There are no sysfs files for drivers yet, but note this when they do have
some.
|
|
devclass_{add,remove}_driver() had been implemented, but had never been
called.
|
|
...since macro using it was changed from #if to #ifdef..
|
|
drivers/base relies on device.h pulling in sched.h pulling in the rest
of the world. Add some explicit dependencies in preparation for removing
sched.h from device.h.
|
|
- add kobject to struct device_driver and register it when drivers are registered
(as member's of their bus's driver subsystem).
- convert driverfs callbacks to know about struct kobject.
- create links from drivers' directories to devices' directories.
- don't even make driverfs directories for drivers anymore.
|
|
Drivers must belong to bus, and each bus has an rwsem. Instead of mucking with
the device_lock spinlock, and dropping it on each iteration of the loop, we take
the bus's lock (read, so multiple drivers can access their list at the same time)
around the entire walk of the list.
|
|
- move list walking and matching to bus.c (since it's a function of the bus driver)
- do specialized walks of the bus's lists when binding; no more callbacks being passed
to bus_for_each_*.
- take rwsem when adding and removing both devices and drivers. lists of each are now
fully protected by that rwsem. It's also taken before we walk each list.
- move calls of device_{de,at}tach() to bus_{add,remove}_device() and calls of
driver_{de,at}tach() to bus_{add,remove}_driver().
|
|
In the spirit of devices and buses, change driver refcounting model to
match the way that devices and buses are done.
struct device_driver gets a ->present field, which is set on registration
and cleared in driver_unregister(). get_device() checks the state of this
flag and returns NULL if cleared.
Note that the horribly wrong remove_driver() is deprecated and simply BUG()s
when called. Please convert callers to use driver_unregister(). Updates to
callers will be coming soon.
Note also that this still doesn't fix the race in which a driver module can
be removed while the refcount on a driver > 1. Near future work should help
to remedy it, but no solutions are guaranteed..
|
|
Change all iterators of devices to:
- use list_for_each
- check return of get_device_locked
- don't break until we hold the lock if we get an error
When a device's reference count hits 0, remove it from all lists, including
bus and driver lists.
Between the iterator algorithm and the guaranteed removal from the lists,
there should never be a device in a list with a reference count of 0.
So, whenever we're iterating over the lists, we'll always have a valid
device. We don't decrement the refcount until the next iteration of the
loop, so we're also guaranteed to get the correct next item in the list.
|
|
This updates the device model locking to use device_lock when accessing all
lists (the global list, the bus' lists and the drivers' lists). Before the latter
two would use their own rwlocks.
This also updates get_device() to return a pointer to the struct device if it
can successfully increment the reference count.
Between these two changes, this should prevent anything gaining an invalid
reference to a device that is in the process of being removed:
If a device is being removed, it's reference count is 0, but it hasn't
necessarily hasn't been removed from its bus's list. If the bus list iterator
attempts to access the device, it will take the lock, but will continue on to
the next device because the refcount is 0 (and drop the lock).
Well, theoretically; the bus iterators still need to be changed, but that's
coming next..
|
|
This cleans up the drivers/base/ files, so they deal mainly with registration.
It also provides a good place to put the glue needed for bus and driver files in driverfs.
|
|
- remove device from driver's list on device_detach
- set device's driver to NULL
- decrement reference count on driver on device_detach
- remove devices from driver's list in driver_detach
- use a write_lock instead of read_lock
- don't lock around initialization of device fields
- assume we have a bus in __remove_driver (we enforce this in driver_register)
- do put_bus last in __remove_driver
- lock bus around atomic_set in remove_driver and atomic_dec_and_test in put_driver
- remove from bus's list while we have it locked
|
|
s/{driver,device}_bind/{driver,device}_attach/ and s/{driver,device}_unbind/{driver,device}_detach/
call bus's match callback instead of bind callback
|
|
- make sure drv->devices is initialized on registration (from Peter Osterlund)
- add remove_driver for forcing removal of driver
There was a potential race with the module unload code. When a pci driver was unloaded, it would call pci_unregister_driver, which would simply call put_driver.
If the driver's refcount wasn't 0, it wouldn't unbind it from devices, but the module unload would still continue.
If something tried to access the driver later (since everyone thinks its still there), Bad Things would happen.
This fixes it until there can be tighter integration between the device model and module unload code.
|
|
- iterate over all devices a driver has, with proper locking on driver and refcounting on devices
|
|
- on device registration, all drivers of bus are iterated over
- bus's bind callback is called to match device to driver
- if successful, driver's probe callback is called
- on device removal, driver's remove callback is called
- on driver registration, list of devices is iterated over (and same thing happens)
|
|
- add name, bus, lock, refcount, bus_list, devices, and dir fields to struct
- add release callback to be called when refcount hits 0
- add helpers for registration and refcounting
- create directory for driver in bus's directory
|