driver-model: misc bug fixes
Subsystems (2)
cover driver-model: misc bug fixes
Hello,
The following 5 patches are misc bugfixes spanning kobject, sysfs and
bus. All patches are independent.
Signature · 1 line
tejun
Re: [PATCH 2.6.10-rc1 4/5] driver-model: kobject_add() error path reference counting fix
df_04_kobject_add_ref_fix.patch
In kobject_add(), @kobj wasn't put'd properly on error path. This
patch fixes it.
lib/kobject.c +1 -0
@@ -183,6 +183,7 @@ int kobject_add(struct kobject * kobj)unlink (kobj);if (parent)kobject_put (parent); +kobject_put (kobj); }else {kobject_hotplug (kobj,KOBJ_ADD ); }
Greg KH
AppliedRe: [PATCH 2.6.10-rc1 4/5] driver-model: kobject_add() error path reference counting fix
Quoted 7 lines · Tejun Heo
df_04_kobject_add_ref_fix.patch
In
kobject_add(), @kobj wasn't put'd properly on error path. This
patch fixes it.Signed-off-by Tejun Heo <[email protected]>
Applied, thanks.
greg k-h
Re: [PATCH 2.6.10-rc1 5/5] driver-model: device_add() error path reference counting fix
In reply to Tejun Heodf_05_device_add_ref_fix.patch
In device_add(), @dev wan't put'd properly when it has zero lengthbus_id (error path). Fixed.
drivers/base/core.c +3 -2
@@ -209,12 +209,13 @@ void device_initialize(struct device *de*/ int device_add (struct device *dev) { -struct device * parent; +struct device * parent =NULL ;int error; + error = -EINVAL ; dev =get_device (dev);if (!dev || !strlen (dev->bus_id)) -return -EINVAL ; + goto Error; parent =get_device (dev->parent);
Greg KH
AppliedRe: [PATCH 2.6.10-rc1 5/5] driver-model: device_add() error path reference counting fix
Quoted 4 lines · Tejun Heo
df_05_device_add_ref_fix.patch
In
device_add(), @dev wan't put'd properly when it has zero lengthbus_id(error path). Fixed.
Applied, thanks.
greg k-h
Re: [PATCH 2.6.10-rc1 3/5] driver-model: sysfs_release() dangling pointer reference fix
In reply to Tejun Heodf_03_sysfs_release_fix.patch
Some attributes are allocated dynamically (e.g. module and device
parameters) and are usually deallocated when the assoicated kobject is released. So, it's not safe to access attr after putting the kobject.
fs/sysfs/file.c +3 -1
@@ -330,11 +330,13 @@ static int sysfs_release(struct inode * {struct kobject * kobj =to_kobj (filp->f_dentry->d_parent);struct attribute * attr =to_attr (filp->f_dentry); +struct module * owner = attr->owner;struct sysfs_buffer * buffer = filp->private_data;if (kobj)kobject_put (kobj); -module_put (attr->owner); +/* After this point, attr should not be accessed. */ +module_put (owner);if (buffer) {if (buffer->page)
Greg KH
AppliedRe: [PATCH 2.6.10-rc1 3/5] driver-model: sysfs_release() dangling pointer reference fix
Quoted 8 lines · Tejun Heo
df_03_sysfs_release_fix.patch
Some attributes are allocated dynamically (e.g. module and device
parameters) and are usually deallocated when the assoicated kobject is released. So, it's not safe to access attr after putting the kobject.Signed-off-by Tejun Heo <[email protected]>
Applied, thanks.
greg k-h
Re: [PATCH 2.6.10-rc1 2/5] driver-model: bus_recan_devices() locking fix
In reply to Tejun Heodf_02_bus_rescan_devcies_fix.patch
bus_rescan_devices() eventually calls device_attach() and thus
requires write locking the corresponding bus. The original code just called bus_for_each_dev() which only read locks the bus. This patch separates __bus_for_each_dev() and __bus_for_each_drv(), which don't do locking themselves, out from the original functions and call them with read lock in the original functions and with write lock in bus_rescan_devices().
drivers/base/bus.c +58 -39
@@ -135,6 +135,54 @@ static struct kobj_type ktype_bus = {decl_subsys (bus, &ktype_bus,NULL ); +static int +__bus_for_each_dev (struct bus_type * bus,struct device * start, +void * data,int (*fn)(struct device *,void *)) +{ +struct device *dev; +struct list_head * head; +int error =0 ; + +if (!(bus =get_bus (bus))) +return -EINVAL ; + + head = &bus->devices.list; + dev =list_prepare_entry (start, head, bus_list); +list_for_each_entry_continue (dev, head, bus_list) { +get_device (dev); + error =fn (dev, data); +put_device (dev); +if (error) +break ; + } +put_bus (bus); +return error; +} + +static int +__bus_for_each_drv (struct bus_type * bus,struct device_driver * start, +void * data,int (*fn)(struct device_driver *,void *)) +{ +struct list_head * head; +struct device_driver *drv; +int error =0 ; + +if (!(bus =get_bus (bus))) +return -EINVAL ; + + head = &bus->drivers.list; + drv =list_prepare_entry (start, head, kobj.entry); +list_for_each_entry_continue (drv, head, kobj.entry) { +get_driver (drv); + error =fn (drv, data); +put_driver (drv); +if (error) +break ; + } +put_bus (bus); +return error; +} +/** * bus_for_each_dev - device iterator. * @bus: bus type.
@@ -154,30 +202,15 @@ decl_subsys(bus, &ktype_bus, NULL);* to retain this data, it should do, and increment the reference * count in the supplied callback. */ +int bus_for_each_dev (struct bus_type * bus,struct device * start,void * data,int (*fn)(struct device *,void *)) { -struct device *dev; -struct list_head * head; -int error =0 ; - -if (!(bus =get_bus (bus))) -return -EINVAL ; - - head = &bus->devices.list; - dev =list_prepare_entry (start, head, bus_list); - +int ret;down_read (&bus->subsys.rwsem); -list_for_each_entry_continue (dev, head, bus_list) { -get_device (dev); - error =fn (dev, data); -put_device (dev); -if (error) -break ; - } + ret =__bus_for_each_dev (bus, start, data, fn);up_read (&bus->subsys.rwsem); -put_bus (bus); -return error; +return ret; }/**
@@ -203,27 +236,11 @@ int bus_for_each_dev(struct bus_type * bint bus_for_each_drv (struct bus_type * bus,struct device_driver * start,void * data,int (*fn)(struct device_driver *,void *)) { -struct list_head * head; -struct device_driver *drv; -int error =0 ; - -if (!(bus =get_bus (bus))) -return -EINVAL ; - - head = &bus->drivers.list; - drv =list_prepare_entry (start, head, kobj.entry); - +int ret;down_read (&bus->subsys.rwsem); -list_for_each_entry_continue (drv, head, kobj.entry) { -get_driver (drv); - error =fn (drv, data); -put_driver (drv); -if (error) -break ; - } + ret =__bus_for_each_drv (bus, start, data, fn);up_read (&bus->subsys.rwsem); -put_bus (bus); -return error; +return ret; }/**
@@ -601,7 +618,9 @@ int bus_rescan_devices(struct bus_type * {int count =0 ; -bus_for_each_dev (bus,NULL , &count, bus_rescan_devices_helper); +down_write (&bus->subsys.rwsem); +__bus_for_each_dev (bus,NULL , &count, bus_rescan_devices_helper); +up_write (&bus->subsys.rwsem);return count; }
Re: [PATCH 2.6.10-rc1 2/5] driver-model: bus_recan_devices() locking fix
Quoted 11 lines · Tejun Heo
df_02_bus_rescan_devcies_fix.patch
bus_rescan_devices()eventually callsdevice_attach()and thus
requires write locking the corresponding bus. The original code just calledbus_for_each_dev()which only read locks the bus. This patch separates__bus_for_each_dev()and__bus_for_each_drv(), which don't do locking themselves, out from the original functions and call them with read lock in the original functions and with write lock inbus_rescan_devices().
Quoted 1 line
Signed-off-by Tejun Heo <[email protected]>
Thanks, I cleaned up the formatting a bit in this patch and applied it.
greg k-h
Re: [PATCH 2.6.10-rc1 2/5] driver-model: bus_recan_devices() locking fix
Quoted 12 lines · Greg KH
Quoted 11 lines · Tejun Heo
df_02_bus_rescan_devcies_fix.patch
bus_rescan_devices()eventually callsdevice_attach()and thus
requires write locking the corresponding bus. The original code just calledbus_for_each_dev()which only read locks the bus. This patch separates__bus_for_each_dev()and__bus_for_each_drv(), which don't do locking themselves, out from the original functions and call them with read lock in the original functions and with write lock inbus_rescan_devices().
Quoted 4 lines
Quoted 1 line
Signed-off-by Tejun Heo <[email protected]>Thanks, I cleaned up the formatting a bit in this patch and applied it.
Hmm, I do not like that the patch now fiddles with bus's rwsem before incrementing bus's refcount.
I think just iterating through device list right the bus_rescan_devices will be good enough. I sent the patch together with other 3, did it get lost?
Signature · 1 line
Dmitry
Re: [PATCH 2.6.10-rc1 2/5] driver-model: bus_recan_devices() locking fix
Hello Dmitry,
Quoted 2 lines · Dmitry Torokhov
Hmm, I do not like that the patch now fiddles with bus's rwsem before incrementing bus's refcount.
Yes, I agree with you.
Quoted 3 lines
I think just iterating through device list right the
bus_rescan_deviceswill be good enough. I sent the patch together with other 3, did it get lost?
Or maybe just adding a @write_lock argument to bus_for_each_*()
functions or create a new function named __bus_for_each_*() which takes additional @write_lock argument.
However, I don't really think the get_bus/put_bus() calls are
necessary there. Unless the caller already has a reference to the bus, we're in trouble anyway. get_bus() cannot synchronize with the last put_bus(), we need outer synchronization to protect that (individual bus drivers are expected to perform the synchronization).
One thing that bothers me is all the "if (kobject_get(x))" codes.
Currently, it doesn't seem to do anything other than checking if x is NULL or not and incrementing the reference count. i.e. the return value only represents if x is NULL or not. I find the codes misleading. It seems like above statement can synchronize get() and the last put() which isn't true. I don't how how the using xchg in kref went, but with preemtion turned on, I don't see how it's gonna change the situation.
Well, I should write the following in another mail but I'll just
continue here.
Another problem I've encountered regarding kobject refcounting is
that currently each sysfs attr carries its owner and gets the owning module when the attr is accessed. However, there are attributes which are provided not by the module which implements whatever the kobject represents but by upper-level module or the kernel builtins. So, it's possible to unload a module while it's kobject is still alive by holding on to such attributes, and, when the attribute is closed, panic occurs, of course (release callback is unloaded already).
Modules which device_driver kobjects are okay because unload_sem is
used to prevent the module from unloading before it is released; however, bus_type, class and class_device kobjects have this problem. I found detach_state attr and all common USB attributes. Also, all class_device attributes, including simple_class dev attribute, which are defined by the class it belongs to suffer this problem (allocated by individual drivers but owned by the class).
We can do one of
1. add unload_sem to all driver-model structures.
-> I believe this defeats the purpose of try_module_get() stuff. We wouldn't know when the module will unload.
2. get the owner field correct for all attributes.
-> This will be a chore. We'll need to allocate separate attr structures for each kobject for all the generic attrs.
3. remove the owner field from the attribute structure and add an owner to kobject and make sysfs ops to hold the owner of the respective kobject.
-> I think this is the best and most consistent solution. As we already assume that module which implements a child kobject should depend upon the module which implements its parent, all attr module reference counting will be correct by using the kobject's owner.
So, I'm currently working on solution #3.
IMHO, we really need some kind of documentation describing the
synchronization, reference counting and behavior assumptions in the driver-model. It just seems a bit too subtle and fragile as it stands now.
Thanks.
Signature · 1 line
tejun
Re: [PATCH 2.6.10-rc1 2/5] driver-model: bus_recan_devices() locking fix
Quoted 10 lines · Tejun Heo
Or maybe just adding a @write_lock argument to bus_for_each_*() functions or create a new function named __bus_for_each_*() which takes additional @write_lock argument.
However, I don't really think the get_bus/put_bus() calls are necessary there. Unless the caller already has a reference to the bus, we're in trouble anyway.
get_bus()cannot synchronize with the lastput_bus(), we need outer synchronization to protect that (individual bus drivers are expected to perform the synchronization).
Yes I think you are right.
Quoted 9 lines
One thing that bothers me is all the "if (
kobject_get(x))" codes. Currently, it doesn't seem to do anything other than checking if x is NULL or not and incrementing the reference count. i.e. the return value only represents if x is NULL or not. I find the codes misleading. It seems like above statement can synchronizeget()and the lastput()which isn't true. I don't how how the using xchg in kref went, but with preemtion turned on, I don't see how it's gonna change the situation.
I agree it is somewhat misleading. And even if _get would synchronize with _put taht wouldmean that the caller does not have a valid reference and the kernel will crash there next time callers uses the object in question.
I think we just have lay down the rules that one needs to get a reference to an object in the following cases:
- object creation (first reference)
- linking some other object to the object in question. Every link to the object should increase reference count.
- before passing object to another thread of execution to guarantee that the object will live long enough for both threads.
This we can get rid of the litter in form:
if (get_bus(bus)) {
sysfs_remove_file(&bus->subsys.kset.kobj, &attr->attr);
put_bus(bus);
}sysfs_remove_file should do just fine by itself, if caller does not have bus reference it's its fault.
Greg, what do you think?
Quoted 12 lines
Well, I should write the following in another mail but I'll just continue here.
Another problem I've encountered regarding kobject refcounting is
that currently each sysfs attr carries its owner and gets the owning module when the attr is accessed. However, there are attributes which are provided not by the module which implements whatever the kobject represents but by upper-level module or the kernel builtins. So, it's possible to unload a module while it's kobject is still alive by holding on to such attributes, and, when the attribute is closed, panic occurs, of course (release callback is unloaded already).
I actually spent quite few days thinking about this problem and here is what I come up with:
You have bus core module that provides generic release function for devices on the bus. When object is registered you bump up module count for the core module.
You also have modues that provide devices. At device unregister time they do all device-specific cleanup, but leave attributes (and memory) handled by core modules intact. This allows to unload device module safely at any time and then when reference to the last generic attribute is dropped the generic cleanup finally removes last traces of the device.
<skip>
Quoted 7 lines
We can do one of
1. add
unload_semto all driver-model structures.
-> I believe this defeats the purpose oftry_module_get()stuff. We wouldn't know when the module will unload.
As Al Viro pointed out "rmmod module < /sys/bus/devices/xxxx/attr" will deadlock the kernel with this scheme.
Quoted 13 lines
2. get the owner field correct for all attributes.
-> This will be a chore. We'll need to allocate separate attr structures for each kobject for all the generic attrs.3. remove the owner field from the attribute structure and add an owner to kobject and make sysfs ops to hold the owner of the respective kobject.
-> I think this is the best and most consistent solution. As we already assume that module which implements a child kobject should depend upon the module which implements its parent, all attr module reference counting will be correct by using the kobject's owner.
Quoted 2 lines
So, I'm currently working on solution #3.
I think this is an overkill and will inflate every kobject out there, unless you will find a hole in my scheme...
Signature · 1 line
Dmitry
Re: [PATCH 2.6.10-rc1 2/5] driver-model: bus_recan_devices() locking fix
Quoted 15 lines · Dmitry Torokhov
Quoted 9 lines · Tejun Heo
Another problem I've encountered regarding kobject refcounting is
that currently each sysfs attr carries its owner and gets the owning module when the attr is accessed. However, there are attributes which are provided not by the module which implements whatever the kobject represents but by upper-level module or the kernel builtins. So, it's possible to unload a module while it's kobject is still alive by holding on to such attributes, and, when the attribute is closed, panic occurs, of course (release callback is unloaded already).I actually spent quite few days thinking about this problem and here is what I come up with:
Quoted 8 lines
You have bus core module that provides generic release function for devices on the bus. When object is registered you bump up module count for the core module.
You also have modues that provide devices. At device unregister time they do all device-specific cleanup, but leave attributes (and memory) handled by core modules intact. This allows to unload device module safely at any time and then when reference to the last generic attribute is dropped the generic cleanup finally removes last traces of the device.
Are you suggesting splitting every bus implementation into two
separate modules? Otherwise, we will have to move kobj field of every bus-specific device structure to the head (to use the common release function). Either way, it can be done, but it just seems another twist added to the already twisted refcounting. Moreoever, not only the devices are problematic, refcounting in class devices and block device hierarchy seems broken too.
Quoted 25 lines
<skip>
Quoted 7 lines
We can do one of
1. add
unload_semto all driver-model structures.
-> I believe this defeats the purpose oftry_module_get()stuff. We wouldn't know when the module will unload.As Al Viro pointed out "rmmod module <
/sys/bus/devices/xxxx/attr" will deadlock the kernel with this scheme.Quoted 13 lines
2. get the owner field correct for all attributes.
-> This will be a chore. We'll need to allocate separate attr structures for each kobject for all the generic attrs.3. remove the owner field from the attribute structure and add an owner to kobject and make sysfs ops to hold the owner of the respective kobject.
-> I think this is the best and most consistent solution. As we already assume that module which implements a child kobject should depend upon the module which implements its parent, all attr module reference counting will be correct by using the kobject's owner.
Quoted 5 lines
Quoted 2 lines
So, I'm currently working on solution #3.
I think this is an overkill and will inflate every kobject out there, unless you will find a hole in my scheme...
But all attrs will be deflated and it just seems the right thing to
do(tm).
Signature · 1 line
tejun
Re: [PATCH 2.6.10-rc1 2/5] driver-model: bus_recan_devices() locking fix
Quoted 25 lines · Tejun Heo
Quoted 15 lines · Dmitry Torokhov
Quoted 9 lines · Tejun Heo
Another problem I've encountered regarding kobject refcounting is
that currently each sysfs attr carries its owner and gets the owning module when the attr is accessed. However, there are attributes which are provided not by the module which implements whatever the kobject represents but by upper-level module or the kernel builtins. So, it's possible to unload a module while it's kobject is still alive by holding on to such attributes, and, when the attribute is closed, panic occurs, of course (release callback is unloaded already).I actually spent quite few days thinking about this problem and here is what I come up with:
Quoted 8 lines
You have bus core module that provides generic release function for devices on the bus. When object is registered you bump up module count for the core module.
You also have modues that provide devices. At device unregister time they do all device-specific cleanup, but leave attributes (and memory) handled by core modules intact. This allows to unload device module safely at any time and then when reference to the last generic attribute is dropped the generic cleanup finally removes last traces of the device.
Quoted 8 lines
Are you suggesting splitting every bus implementation into two
separate modules? Otherwise, we will have to move kobj field of every bus-specific device structure to the head (to use the common release function). Either way, it can be done, but it just seems another twist added to the already twisted refcounting. Moreoever, not only the devices are problematic, refcounting in class devices and block device hierarchy seems broken too.
It is already defacto implementation standard - every subsystem has a core modules (pci, usbcore, serio) plus modules (drivers) actually talking to hardware and registering devices (ports, whatever) with the corresponding core. It is just a matter of splitting cleanup functions into core and device-specific parts.
Quoted 25 lines
Quoted 25 lines
<skip>
Quoted 7 lines
We can do one of
1. add
unload_semto all driver-model structures.
-> I believe this defeats the purpose oftry_module_get()stuff. We wouldn't know when the module will unload.As Al Viro pointed out "rmmod module <
/sys/bus/devices/xxxx/attr" will deadlock the kernel with this scheme.Quoted 13 lines
2. get the owner field correct for all attributes.
-> This will be a chore. We'll need to allocate separate attr structures for each kobject for all the generic attrs.3. remove the owner field from the attribute structure and add an owner to kobject and make sysfs ops to hold the owner of the respective kobject.
-> I think this is the best and most consistent solution. As we already assume that module which implements a child kobject should depend upon the module which implements its parent, all attr module reference counting will be correct by using the kobject's owner.
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
So, I'm currently working on solution #3.
I think this is an overkill and will inflate every kobject out there, unless you will find a hole in my scheme...
But all attrs will be deflated and it just seems the right thing to
do(tm).
I think there are much more kobjects than attrs.
Signature · 1 line
Dmitry
Re: [PATCH 2.6.10-rc1 2/5] driver-model: bus_recan_devices() locking fix
Hello, Dmitry.
Quoted 10 lines · Dmitry Torokhov
Quoted 8 lines · Tejun Heo
Are you suggesting splitting every bus implementation into two
separate modules? Otherwise, we will have to move kobj field of every bus-specific device structure to the head (to use the common release function). Either way, it can be done, but it just seems another twist added to the already twisted refcounting. Moreoever, not only the devices are problematic, refcounting in class devices and block device hierarchy seems broken too.
Quoted 5 lines
It is already defacto implementation standard - every subsystem has a core modules (pci, usbcore, serio) plus modules (drivers) actually talking to hardware and registering devices (ports, whatever) with the corresponding core. It is just a matter of splitting cleanup functions into core and device-specific parts.
AFAIK, PCI isn't compiled as modules and USB has ohci/uhci/ehci stuff
and serio has ports stuff. But still, I cannot agree with you.
1. It's too twisted.
a. to prevent premature unload, we depend on
- attr -> kobj -> module_ref to bus core module. By doing this, we're making a chain of two different types of reference counts. IMHO, it's just a bit too subtle.
b. to enable bus module unload, we depend on
- device creation/detach operations are done in a separate module than device release.
2. too restrictive.
a. any bus implementation must be implemented as two separate
modules just to enable peaceful module unloading
b. all other places which make use of kobject and any type of
generic attr must use only the release routine proper to the core module. No callbacks, no data dereferences.... (for example, scsi_host class uses scsi_host_template
structure which contain class device specific callbacks when releaseing scsi_host class device. This is currently broken and won't be fixed by your method.)
3. not intutive. Maybe this is the most important.
a. it's natural to expect the release code has access to
codes & data of whatever it's releasing.
b. children bypassing dependency hierarchy and depending
directly on indirect ancestor is just difficult to track, memorize and do correctly.
IMO, above a and b are the primary reasons for why kobject/attr refcountings are currently done incorrectly in many places.
Quoted 5 lines
Quoted 3 lines
But all attrs will be deflated and it just seems the right thing to
do(tm).I think there are much more kobjects than attrs.
Yes, there are. But many objects which contain kobjs keep separate
owner field anyway, which can be removed after kobj can handle module refcounting, and even without that, I think 4 or 8 bytes addition to struct kobject is worth it if we can get the refcounting straight.
Thanks.
Signature · 1 line
tejun
Re: [PATCH 2.6.10-rc1 2/5] driver-model: bus_recan_devices() locking fix
In reply to Dmitry TorokhovQuoted 29 lines · Dmitry Torokhov
Quoted 10 lines · Tejun Heo
Or maybe just adding a @write_lock argument to bus_for_each_*() functions or create a new function named __bus_for_each_*() which takes additional @write_lock argument.
However, I don't really think the get_bus/put_bus() calls are necessary there. Unless the caller already has a reference to the bus, we're in trouble anyway.
get_bus()cannot synchronize with the lastput_bus(), we need outer synchronization to protect that (individual bus drivers are expected to perform the synchronization).Yes I think you are right.
Quoted 9 lines
One thing that bothers me is all the "if (
kobject_get(x))" codes. Currently, it doesn't seem to do anything other than checking if x is NULL or not and incrementing the reference count. i.e. the return value only represents if x is NULL or not. I find the codes misleading. It seems like above statement can synchronizeget()and the lastput()which isn't true. I don't how how the using xchg in kref went, but with preemtion turned on, I don't see how it's gonna change the situation.I agree it is somewhat misleading. And even if
_getwould synchronize with_puttaht wouldmean that the caller does not have a valid reference and the kernel will crash there next time callers uses the object in question.
Quoted 7 lines
I think we just have lay down the rules that one needs to get a reference to an object in the following cases:
- object creation (first reference)
- linking some other object to the object in question. Every link to the object should increase reference count.
- before passing object to another thread of execution to guarantee that the object will live long enough for both threads.
The rules are defined. See my OLS 2004 paper on krefs for details.
thanks,
greg k-h
Re: [PATCH 2.6.10-rc1 2/5] driver-model: bus_recan_devices() locking fix
Quoted 10 lines · Greg KH
Quoted 7 lines
I think we just have lay down the rules that one needs to get a reference to an object in the following cases:
- object creation (first reference)
- linking some other object to the object in question. Every link to the ? object should increase reference count.
- before passing object to another thread of execution to guarantee that ? the object will live long enough for both threads.The rules are defined. ?See my OLS 2004 paper on krefs for details.
So that means you will patches like the one below, right?
Signature · 48 lines
Dmitry =================================================================== [email protected], 2004-11-09 23:14:31-05:00, [email protected] Driver core: remove unnecessary get_driver/put_driver from driver.c Signed-off-by: Dmitry Torokhov <[email protected]> driver.c | 13 ++----------- 1 files changed, 2 insertions(+), 11 deletions(-) =================================================================== diff -Nru a/drivers/base/driver.c b/drivers/base/driver.c --- a/drivers/base/driver.c 2004-11-09 23:16:43 -05:00 +++ b/drivers/base/driver.c 2004-11-09 23:16:43 -05:00 @@ -26,13 +26,7 @@ int driver_create_file(struct device_driver * drv, struct driver_attribute * attr) { - int error; - if (get_driver(drv)) { - error = sysfs_create_file(&drv->kobj, &attr->attr); - put_driver(drv); - } else - error = -EINVAL; - return error; + return sysfs_create_file(&drv->kobj, &attr->attr); } @@ -44,10 +38,7 @@ void driver_remove_file(struct device_driver * drv, struct driver_attribute * attr) { - if (get_driver(drv)) { - sysfs_remove_file(&drv->kobj, &attr->attr); - put_driver(drv); - } + sysfs_remove_file(&drv->kobj, &attr->attr); }
Re: [PATCH 2.6.10-rc1 2/5] driver-model: bus_recan_devices() locking fix
Quoted 33 lines · Dmitry Torokhov
Quoted 10 lines · Greg KH
Quoted 7 lines
I think we just have lay down the rules that one needs to get a reference to an object in the following cases:
- object creation (first reference)
- linking some other object to the object in question. Every link to the ? object should increase reference count.
- before passing object to another thread of execution to guarantee that ? the object will live long enough for both threads.The rules are defined. ?See my OLS 2004 paper on krefs for details.
So that means you will patches like the one below, right?
diff -Nru
a/drivers/base/driver.cb/drivers/base/driver.cdrivers/base/driver.c +1
-7@@ -26,13 +26,7 @@int driver_create_file (struct device_driver * drv,struct driver_attribute * attr) { -int error; -if (get_driver (drv)) { - error =sysfs_create_file (&drv->kobj, &attr->attr); -put_driver (drv); - }else - error = -EINVAL ; -return error; +return sysfs_create_file (&drv->kobj, &attr->attr); }
drivers/base/driver.c line 42
Quoted 9 lines
drivers/base/driver.c +1
-4@@ -44,10 +38,7 @@void driver_remove_file (struct device_driver * drv,struct driver_attribute * attr) { -if (get_driver (drv)) { -sysfs_remove_file (&drv->kobj, &attr->attr); -put_driver (drv); - } +sysfs_remove_file (&drv->kobj, &attr->attr); }
While not totally necessary, the current code is safe :)
I'll ask Pat about this next time I see him.
thanks,
greg k-h
Re: [PATCH 2.6.10-rc1 1/5] driver-model: comment fix in bus.c
In reply to Tejun Heodf_01_driver_attach_comment_fix.patch
bus_match() was renamed to driver_probe_device() but the comment fordevice_attach() wasn't updated. This patch updates it.
drivers/base/bus.c +4 -4
@@ -335,10 +335,10 @@ int device_attach(struct device * dev)* driver_attach - try to bind driver to devices. * @drv: driver. * -* Walk the list of devices that the bus has on it and try to match -* the driver with each one. -* If bus_match() returns 0 and the @dev->driver is set, we've found -* a compatible pair. +* Walk the list of devices that the bus has on it and try to +* match the driver with each one. If driver_probe_device() +* returns 0 and the @dev->driver is set, we've found a +* compatible pair. * * Note that we ignore the -ENODEV error from driver_probe_device(), * since it's perfectly valid for a driver not to bind to any devices.
Greg KH
AppliedRe: [PATCH 2.6.10-rc1 1/5] driver-model: comment fix in bus.c
Quoted 7 lines · Tejun Heo
df_01_driver_attach_comment_fix.patch
bus_match()was renamed todriver_probe_device()but the comment fordevice_attach()wasn't updated. This patch updates it.Signed-off-by Tejun Heo <[email protected]>
Applied, thanks.
Oh, Pat's email address is not at osdl.org anymore, it's <[email protected]> now.
thanks,
greg k-h