public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kobject: mark object as not initialized after release
@ 2011-06-02 16:29 Laura Abbott
  2011-06-02 22:28 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Laura Abbott @ 2011-06-02 16:29 UTC (permalink / raw)
  To: linux-kernel, gregkh; +Cc: Laura Abbott

During kobject initalization, state_initialized is set to 1. This state
is never set back to 0, even after release. This results in re-initialized
object warnings if the kobject needs to be reinitialized after release. On
a statically allocated platform device and driver:

platform_device_register(&my_device)
platform_driver_register(&my_matching_driver)
platform_device_unregister(&my_device)
platform_device_register(&my_device)

gives

kobject (bf000128): tried to init an initialized object, something is seriously wrong.
[<c0053964>] (unwind_backtrace+0x0/0x128) from [<c02bd444>] (kobject_init+0x38/0x8c)
[<c02bd444>] (kobject_init+0x38/0x8c) from [<c03445cc>] (device_initialize+0x20/0x68)
[<c03445cc>] (device_initialize+0x20/0x68) from [<c0348924>] (platform_device_register+0x10/0x1c)
[<c0348924>] (platform_device_register+0x10/0x1c) from [<bf00305c>] (platform_driver_test_init+0x5c/0x7c [platform_driver_test])
[<bf00305c>] (platform_driver_test_init+0x5c/0x7c [platform_driver_test]) from [<c00466e8>] (do_one_initcall+0xd0/0x1a4)
[<c00466e8>] (do_one_initcall+0xd0/0x1a4) from [<c0109ea4>] (sys_init_module+0x90/0x1ac)

since the kobject that is part of the platform device (mydevice.dev.kobj) never
had the state_initialized reset despite eventually calling kobject_release.

Fix this by setting state_initialized on a released kobject back to 0 as any
state referenced after releasing is undefined.

Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
---
 lib/kobject.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/lib/kobject.c b/lib/kobject.c
index 82dc34c..00390e3 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -577,7 +577,10 @@ static void kobject_cleanup(struct kobject *kobj)
 
 static void kobject_release(struct kref *kref)
 {
-	kobject_cleanup(container_of(kref, struct kobject, kref));
+	struct kobject *kobj = container_of(kref, struct kobject, kref);
+
+	kobject_cleanup(kobj);
+	kobj->state_initialized = 0;
 }
 
 /**
-- 
1.7.3.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] kobject: mark object as not initialized after release
  2011-06-02 16:29 [PATCH] kobject: mark object as not initialized after release Laura Abbott
@ 2011-06-02 22:28 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2011-06-02 22:28 UTC (permalink / raw)
  To: Laura Abbott; +Cc: linux-kernel

On Thu, Jun 02, 2011 at 09:29:47AM -0700, Laura Abbott wrote:
> During kobject initalization, state_initialized is set to 1. This state
> is never set back to 0, even after release. This results in re-initialized
> object warnings if the kobject needs to be reinitialized after release. On
> a statically allocated platform device and driver:
> 
> platform_device_register(&my_device)
> platform_driver_register(&my_matching_driver)
> platform_device_unregister(&my_device)
> platform_device_register(&my_device)
> 
> gives
> 
> kobject (bf000128): tried to init an initialized object, something is seriously wrong.
> [<c0053964>] (unwind_backtrace+0x0/0x128) from [<c02bd444>] (kobject_init+0x38/0x8c)
> [<c02bd444>] (kobject_init+0x38/0x8c) from [<c03445cc>] (device_initialize+0x20/0x68)
> [<c03445cc>] (device_initialize+0x20/0x68) from [<c0348924>] (platform_device_register+0x10/0x1c)
> [<c0348924>] (platform_device_register+0x10/0x1c) from [<bf00305c>] (platform_driver_test_init+0x5c/0x7c [platform_driver_test])
> [<bf00305c>] (platform_driver_test_init+0x5c/0x7c [platform_driver_test]) from [<c00466e8>] (do_one_initcall+0xd0/0x1a4)
> [<c00466e8>] (do_one_initcall+0xd0/0x1a4) from [<c0109ea4>] (sys_init_module+0x90/0x1ac)
> 
> since the kobject that is part of the platform device (mydevice.dev.kobj) never
> had the state_initialized reset despite eventually calling kobject_release.
> 
> Fix this by setting state_initialized on a released kobject back to 0 as any
> state referenced after releasing is undefined.

Nope.

We've been through this before numerous times, please see the archives
for why I will not accept this change (hint, don't use a static kobject.
If you do, you had better know exactly how to use it correctly...)

> Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
> ---
>  lib/kobject.c |    5 ++++-
>  1 files changed, 4 insertions(+), 1 deletions(-)
> 
> diff --git a/lib/kobject.c b/lib/kobject.c
> index 82dc34c..00390e3 100644
> --- a/lib/kobject.c
> +++ b/lib/kobject.c
> @@ -577,7 +577,10 @@ static void kobject_cleanup(struct kobject *kobj)
>  
>  static void kobject_release(struct kref *kref)
>  {
> -	kobject_cleanup(container_of(kref, struct kobject, kref));
> +	struct kobject *kobj = container_of(kref, struct kobject, kref);
> +
> +	kobject_cleanup(kobj);
> +	kobj->state_initialized = 0;
>  }

You really didn't test this code, did you.  It's totally broken and will
cause crashes all over the place (hint, run it with slab debugging...)

{sigh}

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-06-02 22:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-02 16:29 [PATCH] kobject: mark object as not initialized after release Laura Abbott
2011-06-02 22:28 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox