From patchwork Tue Nov 10 01:56:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 7587601 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 26B6FC05C6 for ; Tue, 10 Nov 2015 01:59:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5C6FC20708 for ; Tue, 10 Nov 2015 01:59:04 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 83CB4206F3 for ; Tue, 10 Nov 2015 01:59:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZvyBE-0008TK-VS; Tue, 10 Nov 2015 01:57:04 +0000 Received: from mail-pa0-x241.google.com ([2607:f8b0:400e:c03::241]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZvyBA-0008Nb-6V for linux-arm-kernel@lists.infradead.org; Tue, 10 Nov 2015 01:57:00 +0000 Received: by pabfh17 with SMTP id fh17so27846007pab.3 for ; Mon, 09 Nov 2015 17:56:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=SJxMk1ciAk1Ze2LUHRGq3jgHgVPq1VV/sGxI5wUPBKo=; b=nWqbBbG6IktFxWdLVBcbnW5diiCqtHbgc3wQPO2ieGkNi6Bf5Wy643lWf20JeBk3Jm GGS4RfY7DbPCOMadeiLolJVgvSGY++cDhjVR2gkzEsmA/hZ8gpxv4beeMZgAU8W20EWr Vt6aLMwZOjYhYslHqz9UgzeJBBDa/G1dNepfv0hPgYpd9G2vRzxPxAA4l/cz2aOKE+va e33tsDS3w/zG6kNyXEsRNFQNWIuGCpW1HX8Qyk4PhkL8nTPkNeq2RnScIFR5ZCAo8VpC uVacMViK+Uzqv88uw5Rt6gfWAJLYMszy4HA43uHuUmcEsgJal+tTsm3lEtcjCpK+t2J4 23og== X-Received: by 10.67.24.97 with SMTP id ih1mr1639160pad.65.1447120599189; Mon, 09 Nov 2015 17:56:39 -0800 (PST) Received: from linux-jyl1.ap.freescale.net (gate-zmy3.freescale.com. [192.88.167.1]) by smtp.gmail.com with ESMTPSA id zk3sm669924pbb.41.2015.11.09.17.56.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2015 17:56:38 -0800 (PST) From: Peng Fan To: will.deacon@arm.com Subject: [RFC V3] iommu: arm-smmu: correct group reference count Date: Tue, 10 Nov 2015 09:56:26 +0800 Message-Id: <1447120586-17847-1-git-send-email-van.freenix@gmail.com> X-Mailer: git-send-email 1.8.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151109_175700_281168_13343A8B X-CRM114-Status: GOOD ( 13.40 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peng Fan , joro@8bytes.org, iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The basic flow for add a device: arm_smmu_add_device |->iommu_group_get_for_dev |->iommu_group_get return group; (1) |->ops->device_group : Init/increase reference count to/by 1. |->iommu_group_add_device : Increase reference count by 1. return group (2) |->return 0; Since we are adding one device, the flow is (2) and the group reference count will be increased by 2. So, we need to add iommu_group_put at the end of arm_smmu_add_device to decrease the count by 1. Signed-off-by: Peng Fan Cc: Will Deacon --- drivers/iommu/arm-smmu-v3.c | 7 ++++++- drivers/iommu/arm-smmu.c | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index 4e5118a..ac333ee 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -1825,8 +1825,10 @@ static int arm_smmu_add_device(struct device *dev) pci_for_each_dma_alias(pdev, __arm_smmu_get_pci_sid, &sid); for (i = 0; i < smmu_group->num_sids; ++i) { /* If we already know about this SID, then we're done */ - if (smmu_group->sids[i] == sid) + if (smmu_group->sids[i] == sid) { + iommu_group_put(group); return 0; + } } /* Check the SID is in range of the SMMU and our stream table */ @@ -1855,6 +1857,9 @@ static int arm_smmu_add_device(struct device *dev) /* Add the new SID */ sids[smmu_group->num_sids - 1] = sid; smmu_group->sids = sids; + + iommu_group_put(group); + return 0; out_put_group: diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index 47dc7a7..af6afce 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -1357,6 +1357,8 @@ static int arm_smmu_add_device(struct device *dev) if (IS_ERR(group)) return PTR_ERR(group); + iommu_group_put(group); + return 0; }