public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Bug (?) in subsystem kset refcounts
@ 2003-11-09  3:20 Alan Stern
  2003-11-09  4:29 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Stern @ 2003-11-09  3:20 UTC (permalink / raw)
  To: Patrick Mochel, Greg KH; +Cc: linux-kernel

I hesitate to say this is definitely a bug, since it might be intended 
behavior.  But it is rather strange.

Subsystems included an embedded kset, which itself includes an embedded 
kobject and so is subject to reference counting.  Whenever a kobject 
belonging to the kset is destroyed, the kset's reference count is 
decremented.  However, kobjects can be added to a kset via the three 
macros

	kobj_set_kset_s, kset_set_kset_s, and subsys_set_kset

and these do _not_ increment the kset's reference count.  As a result, the 
reference count only goes down, not up, quickly becoming negative.

Now maybe this doesn't matter -- if subsystems are intended to be
permanent (i.e., never released), for example.  But it provokes a warning
message from kernels that check for reference counts going below zero,
appears to be unintended, and may cause other problems as well.

The patch below is offered as a possible solution.  I don't know that it's 
the right one, but at least it prevents the unwanted warning messages.

Alan Stern


--- a/include/linux/kobject.h.orig	Thu Sep 11 09:46:38 2003
+++ a/include/linux/kobject.h	Sat Nov  8 17:57:35 2003
@@ -168,7 +168,7 @@
  */
 
 #define kobj_set_kset_s(obj,subsys) \
-	(obj)->kobj.kset = &(subsys).kset
+	(obj)->kobj.kset = kset_get(&(subsys).kset)
 
 /**
  *	kset_set_kset_s(obj,subsys) - set kset for embedded kset.
@@ -182,7 +182,7 @@
  */
 
 #define kset_set_kset_s(obj,subsys) \
-	(obj)->kset.kobj.kset = &(subsys).kset
+	(obj)->kset.kobj.kset = kset_get(&(subsys).kset)
 
 /**
  *	subsys_set_kset(obj,subsys) - set kset for subsystem
@@ -195,7 +195,7 @@
  */
 
 #define subsys_set_kset(obj,_subsys) \
-	(obj)->subsys.kset.kobj.kset = &(_subsys).kset
+	(obj)->subsys.kset.kobj.kset = kset_get(&(_subsys).kset)
 
 extern void subsystem_init(struct subsystem *);
 extern int subsystem_register(struct subsystem *);


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

end of thread, other threads:[~2003-11-09 19:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-09  3:20 Bug (?) in subsystem kset refcounts Alan Stern
2003-11-09  4:29 ` Greg KH
2003-11-09 17:01   ` Alan Stern
2003-11-09 19:42     ` Greg KH

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