Re: [Bug? Report] kref problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Mar 16, 2006 at 08:10:04PM +0300, Artem B. Bityutskiy wrote:
> On Thu, 2006-03-16 at 20:07 +0300, Artem B. Bityutskiy wrote:
> > On Thu, 2006-03-16 at 08:53 -0800, Greg KH wrote: 
> > > > static void a_release(struct kobject *kobj)
> > > > {
> > > > 	struct my_obj_a *a;
> > > > 	
> > > > 	printk("%s\n", __FUNCTION__);
> > > > 	a = container_of(kobj, struct my_obj_a, kobj);
> > > > 	sysfs_remove_dir(&a->kobj);
> > > 
> > > Woah, don't do that here, the kobject core already does this.  A release
> > > function is for you to release the memory you have created with this
> > > kobject, not to mess with sysfs.
> > So do you mean this (attached) ? Anyway I end up with -1 kref.
> > 
> Pardon, forgot to attach.

> #include <linux/kernel.h>
> #include <linux/init.h>
> #include <linux/module.h>
> #include <linux/kobject.h>
> #include <linux/stat.h>
> 
> static void a_release(struct kobject *kobj);
> 
> static struct kobj_type a_ktype = {
>         .release   = a_release
> };
> 
> static void b_release(struct kobject *kobj);
> 
> static struct kobj_type b_ktype = {
>         .release   = b_release
> };
> 
> struct my_obj_a
> {
> 	struct kobject kobj;
> } a;
> 
> struct my_obj_b
> {
> 	struct kobject kobj;
> } b;
> 
> static __init int test_init(void)
> {
> 	int err;
> 
> 	kobject_init(&a.kobj);
> 	a.kobj.ktype = &a_ktype;
> 	err = kobject_set_name(&a.kobj, "A");
> 	if (err)
> 		return err;
> 	printk("a inited, kref %d\n", atomic_read(&a.kobj.kref.refcount));
> 	
> 	kobject_init(&b.kobj);
> 	b.kobj.ktype = &b_ktype;
> 	b.kobj.parent = &a.kobj;
> 	err = kobject_set_name(&b.kobj, "B");
> 	if (err)
> 		goto out_a;
> 	printk("b inited, kref %d\n", atomic_read(&b.kobj.kref.refcount));
> 
> 	err = sysfs_create_dir(&a.kobj);

Again, why are you trying to call the sysfs raw functions?  You are not
registering the kobject with the kobject core, so bad things are
happening.  Why not call kobject_register() or kobject_add(), like it is
documented to do so?

Because of this, you are seeing odd things happen.

thanks,

greg k-h
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux