From mboxrd@z Thu Jan 1 00:00:00 1970 From: Keshavamurthy Anil S Date: Wed, 10 Nov 2004 23:04:01 +0000 Subject: Re: [PATCH] kobject: fix double kobject_put in kobject_unregister() Message-Id: <20041110150400.C13668@unix-os.sc.intel.com> List-Id: References: <20041110141923.A13668@unix-os.sc.intel.com> <20041110225421.GA16785@kroah.com> In-Reply-To: <20041110225421.GA16785@kroah.com>; from greg@kroah.com on Wed, Nov 10, 2004 at 02:54:21PM -0800 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: Greg KH Cc: Keshavamurthy Anil S , Hotplug List , Linux Kernel 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: > > Hi Greg, > > =09 > > This patch fixes the problem where in kobject resources were getting > > freed when those kobject were still in use due to double kobject_put() > > getting called in the kobject_unregister() code path. > >=20 > > With out this patch kobject_unregister() will have some serious side ef= fects. > >=20 > > Please apply. > >=20 > > signed-off-by: Anil S Keshavamurthy > >=20 > >=20 > > linux-2.6.10-rc1-mm4-askeshav/lib/kobject.c | 3 ++- > > 1 files changed, 2 insertions(+), 1 deletion(-) > >=20 > > diff -puN lib/kobject.c~kobject_unregister_fix lib/kobject.c > > --- linux-2.6.10-rc1-mm4/lib/kobject.c~kobject_unregister_fix 2004-11-1= 0 13:43:42.243877455 -0800 > > +++ linux-2.6.10-rc1-mm4-askeshav/lib/kobject.c 2004-11-10 13:46:30.788= 797265 -0800 > > @@ -301,6 +301,8 @@ void kobject_del(struct kobject * kobj) > > { > > kobject_hotplug(kobj, KOBJ_REMOVE); > > sysfs_remove_dir(kobj); > > + > > + /* unlink does kobject_put() for us */ > > unlink(kobj); > > } > > =20 > > @@ -313,7 +315,6 @@ void kobject_unregister(struct kobject * > > { > > pr_debug("kobject %s: unregistering\n",kobject_name(kobj)); > > kobject_del(kobj); > > - kobject_put(kobj); > > } >=20 > No, this is wrong. Count the add and put in the sequence of: > kobject_register() > kobject_unregister() >=20 > they are balanced. >=20 > You mention you are seeing problems. Have a trace? Example code? Here is the call trace when I tried to do kobject_unregiser() Call Trace: [] show_stack+0x80/0xa0 sp=E00000000e3cf730 bsp=E00000000e3c9230 [] show_regs+0x840/0x880 sp=E00000000e3cf900 bsp=E00000000e3c91c8 [] die+0x150/0x1c0 sp=E00000000e3cf910 bsp=E00000000e3c9188 [] die_if_kernel+0x40/0x60 sp=E00000000e3cf910 bsp=E00000000e3c9158 [] ia64_fault+0x110/0x1060 sp=E00000000e3cf910 bsp=E00000000e3c9100 [] ia64_leave_kernel+0x0/0x260 sp=E00000000e3cfb20 bsp=E00000000e3c9100 [] strlen+0x20/0x140 sp=E00000000e3cfcf0 bsp=E00000000e3c90a8 [] kobject_get_path+0x150/0x1e0 sp=E00000000e3cfcf0 bsp=E00000000e3c9068 [] kobject_hotplug+0x350/0x6e0 sp=E00000000e3cfcf0 bsp=E00000000e3c9008 [] kobject_del+0x30/0x80 sp=E00000000e3cfd10 bsp=E00000000e3c8fe0 [] kobject_unregister+0x20/0x60 sp=E00000000e3cfd10 bsp=E00000000e3c8fc0 [] acpi_device_unregister+0x320/0x340 sp=E00000000e3cfd10 bsp=E00000000e3c8fa0 [] acpi_bus_remove+0x2f0/0x340 sp=E00000000e3cfd10 bsp=E00000000e3c8f68 [] acpi_bus_trim+0x300/0x440 sp=E00000000e3cfd30 bsp=E00000000e3c8f18 [] acpi_eject_store+0x110/0x240 sp=E00000000e3cfde0 bsp=E00000000e3c8ee0 [] acpi_device_attr_store+0x70/0xa0 sp=E00000000e3cfe20 bsp=E00000000e3c8ea8 [] sysfs_write_file+0x270/0x300 sp=E00000000e3cfe20 bsp=E00000000e3c8e58 [] vfs_write+0x200/0x2c0 I will try to explain the what is happening here. I have a sysfs tree like this. .../_SB/LSB0=20 .../_SB/LSB0/CPU5 .../_SB/LSB0/MEM1 .../_SB/LSB0/MEM2 Say LSB0 is kobj1, CPU5 is kobj2, MEM1 is kobj3, MEM2 is kobj4 All I am trying to do is first I will do kobject_unregister(kobj2),then=20 kobject_unregister(kobj3), then kobject_unregister(kobj4) and now when I try to do kobject_unregister(kobj1) i.e when I am trying to remove LSB0 directory, I am seeing the above stack trace. The patch I posted fixed this problem. Let me know if you need more data. -Anil >=20 > thanks, >=20 > gre k-h ------------------------------------------------------- This SF.Net email is sponsored by: Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux. http://ads.osdn.com/?ad_idU88&alloc_id=12065&op=3Dclick _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel