All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC V2] iommu: correct group reference count
@ 2015-11-09  6:13 ` Peng Fan
  0 siblings, 0 replies; 9+ messages in thread
From: Peng Fan @ 2015-11-09  6:13 UTC (permalink / raw)
  To: joro-zLv9SwRftAIdnm+yROfE0A, will.deacon-5wv7dgnIgG8
  Cc: Peng Fan, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

The basic flow for iommu_group_for_dev is:
iommu_group_get_for_dev
        |->  iommu_group_get   : increase reference count by 1.
             return group;
        |->  ops->device_group : Init/increase reference count to/by 1.
             iommu_group_add_device  : Increase reference count by 1.
             return group;

We can see that ops->device_group and iommu_group_add_device will together
increase the iommu group reference count by 2. Actually we only need 1,
but not 2. So we need add iommu_group_put after iommu_group_add_device
to make sure iommu_group_get_for_dev only increase reference count by 1.

Signed-off-by: Peng Fan <van.freenix-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
Cc: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>
---

V1 thread: https://lkml.org/lkml/2015/11/3/304
Changes V2:
 I did not see the update about device_group when I worked out V1. So
 redo the patch and refine commit msg and rebased to latest linus'
 linux master tree.

 drivers/iommu/iommu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index abae363..9c1971b 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -852,10 +852,10 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev)
 	}
 
 	ret = iommu_group_add_device(group, dev);
-	if (ret) {
-		iommu_group_put(group);
+	iommu_group_put(group);
+
+	if (ret)
 		return ERR_PTR(ret);
-	}
 
 	return group;
 }
-- 
1.8.4

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

end of thread, other threads:[~2015-11-10  1:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-09  6:13 [RFC V2] iommu: correct group reference count Peng Fan
2015-11-09  6:13 ` Peng Fan
     [not found] ` <1447049608-6123-1-git-send-email-van.freenix-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-11-09 10:10   ` Will Deacon
2015-11-09 10:10     ` Will Deacon
2015-11-09 13:30     ` Peng Fan
2015-11-09 15:28   ` Alex Williamson
2015-11-09 15:28     ` Alex Williamson
     [not found]     ` <1447082889.4925.5.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-11-10  1:24       ` Peng Fan
2015-11-10  1:24         ` Peng Fan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.