Skip to contentSkip to conversation

Fix refcounting for attribute_container

PATCH In review Hannes Reinecke 2 participants 2 messages Mar 18, 2008 – Mar 23, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 7/8 Fix refcounting for attribute_container

attribute_container_add_device() takes an explicit reference on the parent device, making it impossible to remove the parent by doing a simple put_device(). So we'd rather _not_ take a reference here as attribute_container will be handled explicitly by calls to attribute_container_remove_device()/_destroy_device() anyway.

---
 drivers/base/attribute_container.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
drivers/base/attribute_container.c +5 -3
index f57652d..6c7e633 100644
@@ -114,10 +114,8 @@ static void attribute_container_release(struct device *classdev)
 {
 	struct internal_container *ic 
 		= container_of(classdev, struct internal_container, classdev);
-	struct device *dev = classdev->parent;
 
 	kfree(ic);
-	put_device(dev);
 }
 
 /**
@@ -164,7 +162,11 @@ attribute_container_add_device(struct device *dev,
 
 		ic->cont = cont;
 		device_initialize(&ic->classdev);
-		ic->classdev.parent = get_device(dev);
+		/*
+		 * Don't increase refcount here, device will be
+		 * removed explicitly by a call to _destroy().
+		 */
+		ic->classdev.parent = dev;
 		ic->classdev.class = cont->class;
 		cont->class->dev_release = attribute_container_release;
 		strcpy(ic->classdev.bus_id, dev->bus_id);
Signature · 1 line
1.5.2.4
maintainer
#1 lore raw
Quoted 5 lines · Hannes Reinecke

attribute_container_add_device() takes an explicit reference on the parent device, making it impossible to remove the parent by doing a simple put_device(). So we'd rather _not_ take a reference here as attribute_container will be handled explicitly by calls to attribute_container_remove_device()/_destroy_device() anyway.

I really don't think this is right. The attribute container does hold a reference to the device, so we should make it explicit. You could argue that in the new parent indicates class device model there's *already* a reference, so this one is superfluous, but it does help to make the relationship explicit. Regardless, because we have an implicit reference, your comment for the patch can't work (whether we explicitly take the ref or not, you can't expect the device to be unrefereced by the attribute container).

James