Skip to content

Commit 74e9f5f

Browse files
committed
Driver core: remove unneeded completion from driver release path
The completion in the driver release path is due to ancient history in the _very_ early 2.5 days when we were not tracking the module reference count of attributes. It is not needed at all and can be removed. Note, we now have an empty release function for the driver structure. This is due to the fact that drivers are statically allocated in the system at this point in time, something which I want to change in the future. But remember, drivers are really code, which is reference counted by the module, unlike devices, which are data and _must_ be reference counted properly in order to work correctly. Cc: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent c6a4669 commit 74e9f5f

3 files changed

Lines changed: 13 additions & 23 deletions

File tree

‎drivers/base/bus.c‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,19 @@ static struct sysfs_ops driver_sysfs_ops = {
6363

6464
static void driver_release(struct kobject * kobj)
6565
{
66-
struct device_driver * drv = to_driver(kobj);
67-
complete(&drv->unloaded);
66+
/*
67+
* Yes this is an empty release function, it is this way because struct
68+
* device is always a static object, not a dynamic one. Yes, this is
69+
* not nice and bad, but remember, drivers are code, reference counted
70+
* by the module count, not a device, which is really data. And yes,
71+
* in the future I do want to have all drivers be created dynamically,
72+
* and am working toward that goal, but it will take a bit longer...
73+
*
74+
* But do not let this example give _anyone_ the idea that they can
75+
* create a release function without any code in it at all, to do that
76+
* is almost always wrong. If you have any questions about this,
77+
* please send an email to <greg@kroah.com>
78+
*/
6879
}
6980

7081
static struct kobj_type ktype_driver = {

‎drivers/base/driver.c‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,6 @@ void put_driver(struct device_driver * drv)
149149
* We pass off most of the work to the bus_add_driver() call,
150150
* since most of the things we have to do deal with the bus
151151
* structures.
152-
*
153-
* The one interesting aspect is that we setup @drv->unloaded
154-
* as a completion that gets complete when the driver reference
155-
* count reaches 0.
156152
*/
157153
int driver_register(struct device_driver * drv)
158154
{
@@ -162,35 +158,19 @@ int driver_register(struct device_driver * drv)
162158
printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name);
163159
}
164160
klist_init(&drv->klist_devices, NULL, NULL);
165-
init_completion(&drv->unloaded);
166161
return bus_add_driver(drv);
167162
}
168163

169-
170164
/**
171165
* driver_unregister - remove driver from system.
172166
* @drv: driver.
173167
*
174168
* Again, we pass off most of the work to the bus-level call.
175-
*
176-
* Though, once that is done, we wait until @drv->unloaded is completed.
177-
* This will block until the driver refcount reaches 0, and it is
178-
* released. Only modular drivers will call this function, and we
179-
* have to guarantee that it won't complete, letting the driver
180-
* unload until all references are gone.
181169
*/
182170

183171
void driver_unregister(struct device_driver * drv)
184172
{
185173
bus_remove_driver(drv);
186-
/*
187-
* If the driver is a module, we are probably in
188-
* the module unload path, and we want to wait
189-
* for everything to unload before we can actually
190-
* finish the unload.
191-
*/
192-
if (drv->owner)
193-
wait_for_completion(&drv->unloaded);
194174
}
195175

196176
/**

‎include/linux/device.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ struct device_driver {
126126
const char * name;
127127
struct bus_type * bus;
128128

129-
struct completion unloaded;
130129
struct kobject kobj;
131130
struct klist klist_devices;
132131
struct klist_node knode_bus;

0 commit comments

Comments
 (0)