* [Patch 1/2] Driver core: Clarify device cleanup. [not found] <20080903162808.36bb2405@gondolin.boeblingen.de.ibm.com> @ 2008-09-03 16:26 ` Cornelia Huck 2008-09-03 16:26 ` [Patch 2/2] Driver core: Fix cleanup in device_create_vargs() Cornelia Huck 1 sibling, 0 replies; 3+ messages in thread From: Cornelia Huck @ 2008-09-03 16:26 UTC (permalink / raw) To: Greg K-H; +Cc: linux-kernel Make the comments on how to use device_initialize(), device_add() and device_register() a bit clearer - in particular, explicitly note that put_device() must be used once we tried to add the device to the hierarchy. Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> --- drivers/base/core.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) Index: linux-2.6/drivers/base/core.c =================================================================== --- linux-2.6.orig/drivers/base/core.c +++ linux-2.6/drivers/base/core.c @@ -524,11 +524,16 @@ static void klist_children_put(struct kl * device_initialize - init device structure. * @dev: device. * - * This prepares the device for use by other layers, - * including adding it to the device hierarchy. + * This prepares the device for use by other layers by initializing + * its fields. * It is the first half of device_register(), if called by - * that, though it can also be called separately, so one - * may use @dev's fields (e.g. the refcount). + * that function, though it can also be called separately, so one + * may use @dev's fields. In particular, get_device()/put_device() + * may be used for reference counting of @dev after calling this + * function. + * + * NOTE: Use put_device() to give up your reference instead of freeing + * @dev directly once you have called this function. */ void device_initialize(struct device *dev) { @@ -836,9 +841,13 @@ static void device_remove_sys_dev_entry( * This is part 2 of device_register(), though may be called * separately _iff_ device_initialize() has been called separately. * - * This adds it to the kobject hierarchy via kobject_add(), adds it + * This adds @dev to the kobject hierarchy via kobject_add(), adds it * to the global and sibling lists for the device, then * adds it to the other relevant subsystems of the driver model. + * + * NOTE: _Never_ directly free @dev after calling this function, even + * if it returned an error! Always use put_device() to give up your + * reference instead. */ int device_add(struct device *dev) { @@ -958,6 +967,10 @@ int device_add(struct device *dev) * I.e. you should only call the two helpers separately if * have a clearly defined need to use and refcount the device * before it is added to the hierarchy. + * + * NOTE: _Never_ directly free @dev after calling this function, even + * if it returned an error! Always use put_device() to give up the + * reference initialized in this function instead. */ int device_register(struct device *dev) { ^ permalink raw reply [flat|nested] 3+ messages in thread
* [Patch 2/2] Driver core: Fix cleanup in device_create_vargs(). [not found] <20080903162808.36bb2405@gondolin.boeblingen.de.ibm.com> 2008-09-03 16:26 ` [Patch 1/2] Driver core: Clarify device cleanup Cornelia Huck @ 2008-09-03 16:26 ` Cornelia Huck 2008-09-11 10:11 ` patch driver-core-fix-cleanup-in-device_create_vargs.patch added to gregkh-2.6 tree gregkh 1 sibling, 1 reply; 3+ messages in thread From: Cornelia Huck @ 2008-09-03 16:26 UTC (permalink / raw) To: Greg K-H; +Cc: linux-kernel If device_register() in device_create_vargs() fails, the device must be cleaned up with put_device() (which is also fine on NULL) instead of kfree(). Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> --- drivers/base/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) Index: linux-2.6/drivers/base/core.c =================================================================== --- linux-2.6.orig/drivers/base/core.c +++ linux-2.6/drivers/base/core.c @@ -1248,7 +1248,7 @@ struct device *device_create_vargs(struc return dev; error: - kfree(dev); + put_device(dev); return ERR_PTR(retval); } EXPORT_SYMBOL_GPL(device_create_vargs); ^ permalink raw reply [flat|nested] 3+ messages in thread
* patch driver-core-fix-cleanup-in-device_create_vargs.patch added to gregkh-2.6 tree 2008-09-03 16:26 ` [Patch 2/2] Driver core: Fix cleanup in device_create_vargs() Cornelia Huck @ 2008-09-11 10:11 ` gregkh 0 siblings, 0 replies; 3+ messages in thread From: gregkh @ 2008-09-11 10:11 UTC (permalink / raw) To: cornelia.huck, gregkh, greg, linux-kernel, stable This is a note to let you know that I've just added the patch titled Subject: Driver core: Fix cleanup in device_create_vargs(). to my gregkh-2.6 tree. Its filename is driver-core-fix-cleanup-in-device_create_vargs.patch This tree can be found at http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/patches/ >From cornelia.huck@de.ibm.com Thu Sep 11 02:38:46 2008 From: Cornelia Huck <cornelia.huck@de.ibm.com> Date: Wed, 3 Sep 2008 18:26:41 +0200 Subject: Driver core: Fix cleanup in device_create_vargs(). To: Greg K-H <greg@kroah.com> Cc: linux-kernel <linux-kernel@vger.kernel.org> Message-ID: <20080903182641.75db23a6@gondolin.boeblingen.de.ibm.com> From: Cornelia Huck <cornelia.huck@de.ibm.com> If device_register() in device_create_vargs() fails, the device must be cleaned up with put_device() (which is also fine on NULL) instead of kfree(). Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> Cc: stable <stable@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> --- drivers/base/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1256,7 +1256,7 @@ struct device *device_create_vargs(struc return dev; error: - kfree(dev); + put_device(dev); return ERR_PTR(retval); } EXPORT_SYMBOL_GPL(device_create_vargs); Patches currently in gregkh-2.6 which might be from cornelia.huck@de.ibm.com are driver-core/s390-bus_id-dev_name-conversions.patch driver-core/driver-core-clarify-device-cleanup.patch driver-core/driver-core-fix-cleanup-in-device_create_vargs.patch driver-core/s390-bus_id-dev_set_name-changes.patch driver-core/s390-more-bus_id-dev_name-conversions.patch driver-core/s390-use-s390_root_dev_-in-kvm_virtio.patch driver-core/s390-bus_id-dev_set_name-for-css-and-ccw-busses.patch driver-core/driver-core-provide-a-dev_set_name-that-handles-names-longer-than-20-chars.patch ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-09-11 10:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20080903162808.36bb2405@gondolin.boeblingen.de.ibm.com>
2008-09-03 16:26 ` [Patch 1/2] Driver core: Clarify device cleanup Cornelia Huck
2008-09-03 16:26 ` [Patch 2/2] Driver core: Fix cleanup in device_create_vargs() Cornelia Huck
2008-09-11 10:11 ` patch driver-core-fix-cleanup-in-device_create_vargs.patch added to gregkh-2.6 tree gregkh
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox