Make the kobject refcounting compliant with Linux. Refcounting on the

parent kobject cannot be factored out and must be done by the kobject
consumers.

MFC after:	1 week
Sponsored by:	Mellanox Technologies
This commit is contained in:
hselasky 2015-12-31 11:27:36 +00:00
parent 0219f2b937
commit c5e1fb2b0f
2 changed files with 8 additions and 4 deletions

View File

@ -54,21 +54,27 @@ static inline void
cdev_release(struct kobject *kobj)
{
struct linux_cdev *cdev;
struct kobject *parent;
cdev = container_of(kobj, struct linux_cdev, kobj);
parent = kobj->parent;
if (cdev->cdev)
destroy_dev(cdev->cdev);
kfree(cdev);
kobject_put(parent);
}
static inline void
cdev_static_release(struct kobject *kobj)
{
struct linux_cdev *cdev;
struct kobject *parent;
cdev = container_of(kobj, struct linux_cdev, kobj);
parent = kobj->parent;
if (cdev->cdev)
destroy_dev(cdev->cdev);
kobject_put(parent);
}
static struct kobj_type cdev_ktype = {
@ -114,6 +120,7 @@ cdev_add(struct linux_cdev *cdev, dev_t dev, unsigned count)
cdev->dev = dev;
cdev->cdev->si_drv1 = cdev;
kobject_get(cdev->kobj.parent);
return (0);
}

View File

@ -157,7 +157,7 @@ kobject_add_complete(struct kobject *kobj, struct kobject *parent)
struct kobj_type *t;
int error;
kobj->parent = kobject_get(parent);
kobj->parent = parent;
error = sysfs_create_dir(kobj);
if (error == 0 && kobj->ktype && kobj->ktype->default_attrs) {
struct attribute **attr;
@ -198,9 +198,6 @@ kobject_release(struct kref *kref)
kobj = container_of(kref, struct kobject, kref);
sysfs_remove_dir(kobj);
if (kobj->parent)
kobject_put(kobj->parent);
kobj->parent = NULL;
name = kobj->name;
if (kobj->ktype && kobj->ktype->release)
kobj->ktype->release(kobj);