Re: [PATCH] kobject: fix double kobject_put in kobject_unregister()

From: Keshavamurthy Anil S
Date: Wed Nov 10 2004 - 21:00:34 EST


On Wed, Nov 10, 2004 at 02:54:21PM -0800, Greg KH wrote:
> On Wed, Nov 10, 2004 at 02:19:23PM -0800, Keshavamurthy Anil S wrote:
> No, this is wrong. Count the add and put in the sequence of:
> kobject_register()
> kobject_unregister()
>
> they are balanced.

Yes, I agree now, but after investigating further here is what I have found.
If you think this is good, please ack this patch.


>
> You mention you are seeing problems. Have a trace? Example code?

Here is what exactly happening. Please see the patch.
In ACPI, kobject_init() is called without initializing kobj.kset.
Due to this kset.kobj's refcount does not get incremented.
Again when we try to do kobject_unregister(), kset of the kobject
that is getting unregister is obtained and kset's kobject refcount
is decremented which was at teh first place never got inceremened.
Due to this kset's kobj's refcount is decremented with out getting
incremented and due to this bug, this kset.kobj is getting released.

Below fix fixes this problem. If you find this this Good patch,
please ack this patch. I am copying to Len too on this patch.


Signed-of-by: Anil S Keshavamurthy <anil.s.keshavamurthy@xxxxxxxxx>
---

linux-2.6.10-rc1-mm4-askeshav/drivers/acpi/scan.c | 3 +--
1 files changed, 1 insertion(+), 2 deletions(-)

diff -puN drivers/acpi/scan.c~kobject_register_fix1 drivers/acpi/scan.c
--- linux-2.6.10-rc1-mm4/drivers/acpi/scan.c~kobject_register_fix1 2004-11-10 17:40:23.393117553 -0800
+++ linux-2.6.10-rc1-mm4-askeshav/drivers/acpi/scan.c 2004-11-10 17:41:45.844288418 -0800
@@ -112,13 +112,12 @@ static void acpi_device_register(struct
list_add_tail(&device->wakeup_list,&acpi_wakeup_device_list);
spin_unlock(&acpi_device_lock);

- kobject_init(&device->kobj);
strlcpy(device->kobj.name,device->pnp.bus_id,KOBJ_NAME_LEN);
if (parent)
device->kobj.parent = &parent->kobj;
device->kobj.ktype = &ktype_acpi_ns;
device->kobj.kset = &acpi_namespace_kset;
- kobject_add(&device->kobj);
+ kobject_register(&device->kobj);
create_sysfs_device_files(device);
}

_
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/