Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751556AbbKIGNr (ORCPT ); Mon, 9 Nov 2015 01:13:47 -0500 Received: from mail-pa0-f46.google.com ([209.85.220.46]:32922 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750814AbbKIGNq (ORCPT ); Mon, 9 Nov 2015 01:13:46 -0500 From: Peng Fan To: joro@8bytes.org, will.deacon@arm.com Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Peng Fan Subject: [RFC V2] iommu: correct group reference count Date: Mon, 9 Nov 2015 14:13:28 +0800 Message-Id: <1447049608-6123-1-git-send-email-van.freenix@gmail.com> X-Mailer: git-send-email 1.8.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1712 Lines: 53 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 Cc: Joerg Roedel Cc: Will Deacon --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/