Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1146053pxv; Fri, 9 Jul 2021 19:28:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyttjDDgIiy+RIj5/gUd6j3gE7nz0ZlX4BWhYXIRFipAaLKZ879ta4z6CA1unV8qXYP/UR4 X-Received: by 2002:a17:906:30d8:: with SMTP id b24mr19074577ejb.358.1625884129640; Fri, 09 Jul 2021 19:28:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625884129; cv=none; d=google.com; s=arc-20160816; b=nyLp8HFZ94RDKj+FznHs2TQDT06URPylMcJDhEvWPo2Rq/WVXN5yOn2TaE+sKufHcV QQwxxOu6LByLo3HokHBIZzbxw8zvPPNSyFpSLJ4/azh2e5oh1AVLCsZd/eNFCEp6NWnZ Hyxn7fcSuTcHifQW3dOlJTYFE+jZDbBtpuLowy0XzFJ0/+uAKSgGlPb0DxhySthOawzd 5QEdDCWBIQszNozudyiwc9+1pn8fMuvHVitorMRngmEk5eItUok6Js/Ryl8PU74jQ0Nd 3e4GXmN9f4TvxyO69wgTIe75l2w1riT0ObG6iK88tDQ6MOxW+sT1fSJsjYfthxCPvQS4 NspA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xtKp2myjcfkijdt9Hc+xG342pF6G9rZPzXZTvlnrJLQ=; b=FBqBcZsmI9HynHJeLq6uHwUm9Vi85s6/BAuRTmsF4qEr7bTIM//mq6bLFaEtd5ANdd cj4EpGlrxO9h6eZMU3BNAYR5FaxlarltZDTfv87h8Fjb79oCaU3dZFXn/k2cbmyC68Io FY9lY1IZknQJSLsKO90V1WwGwIfjXsT5ubJ1C1b5WzEobDxFvplG9klSxwAj4/H4tB0Z FrOMvlYgzl16aeHGG5ZnHbHbhzNEkMC+sEVbTLCViguJkX+UYXmBqURhLy/3Rjnz8PCH aGw4qg/wv7UrYACeZtBVJYmLRtOR1BEzWxh6S+mjThYHhvYvLLb6g+TWyVY+1J9MVDXx V7yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VLySR1No; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ee47si5123008edb.7.2021.07.09.19.28.26; Fri, 09 Jul 2021 19:28:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VLySR1No; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233748AbhGJC1J (ORCPT + 99 others); Fri, 9 Jul 2021 22:27:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:42738 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233431AbhGJC0F (ORCPT ); Fri, 9 Jul 2021 22:26:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C4AB1613E1; Sat, 10 Jul 2021 02:23:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883795; bh=dg6PZhYDKEu5IrfYdh2th0q3Fhb88QjwQKmagB8cjX4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VLySR1NoGl/ywAJ780fBS60WwUblR47Yg/apJG+MEdeObrNgHl6MAFkuaEHvvCEBO UP6BV+Fhpxc4eSzGBdNmUCl513v7t4N0hEUL7Qm+GZbfn9clsv9mzXPkveUNJ7Ee5p USq9EyIteJbRnYQ03MLFU5OTcrUffGscX8jaM2FdA5we3H+PhZrecY0mbXoRc4m8gu pAejzoPR45WB4MmJpthgGP1M2P/IIFsgCwQqfGEb3ksTM5Oa2n5D6MhwtyGu92LHRZ 8iDJEJDa9wHJNIta9b+jxJuDIU9tYfjGL+Pnfg7nvifs7zymsao9clNVifM2fUDtr+ /EArVdYZCtMYA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Xiyu Yang , Xin Tan , Will Deacon , Sasha Levin , linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org Subject: [PATCH AUTOSEL 5.12 060/104] iommu/arm-smmu: Fix arm_smmu_device refcount leak when arm_smmu_rpm_get fails Date: Fri, 9 Jul 2021 22:21:12 -0400 Message-Id: <20210710022156.3168825-60-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710022156.3168825-1-sashal@kernel.org> References: <20210710022156.3168825-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiyu Yang [ Upstream commit 1adf30f198c26539a62d761e45af72cde570413d ] arm_smmu_rpm_get() invokes pm_runtime_get_sync(), which increases the refcount of the "smmu" even though the return value is less than 0. The reference counting issue happens in some error handling paths of arm_smmu_rpm_get() in its caller functions. When arm_smmu_rpm_get() fails, the caller functions forget to decrease the refcount of "smmu" increased by arm_smmu_rpm_get(), causing a refcount leak. Fix this issue by calling pm_runtime_resume_and_get() instead of pm_runtime_get_sync() in arm_smmu_rpm_get(), which can keep the refcount balanced in case of failure. Signed-off-by: Xiyu Yang Signed-off-by: Xin Tan Link: https://lore.kernel.org/r/1623293672-17954-1-git-send-email-xiyuyang19@fudan.edu.cn Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- drivers/iommu/arm/arm-smmu/arm-smmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c index d8c6bfde6a61..128c2c87b4e5 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -74,7 +74,7 @@ static bool using_legacy_binding, using_generic_binding; static inline int arm_smmu_rpm_get(struct arm_smmu_device *smmu) { if (pm_runtime_enabled(smmu->dev)) - return pm_runtime_get_sync(smmu->dev); + return pm_runtime_resume_and_get(smmu->dev); return 0; } -- 2.30.2