Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1144490pxv; Fri, 9 Jul 2021 19:25:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYdkWvRICwx8WaJysyHZ34erJBD+MI4kP020X/pI5yOLk/pBfTcYPewjhq50AohVngtn8U X-Received: by 2002:a05:6402:1103:: with SMTP id u3mr50589832edv.342.1625883913412; Fri, 09 Jul 2021 19:25:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625883913; cv=none; d=google.com; s=arc-20160816; b=zGIoxOZRFtr7CYvrLSlHWLhUf1QmakvCebSFWAw0YfUsp9khhFZv07ruZTZqmHWIuQ FEzj/bw3YriCUMHFL7Qd13pcaHcXvyzJkIiRUOH9oBX3WGr019a6MhaM/t5EkJ1QUqxd 24aNcwbd6Iy9W2Lz+OmoX9HyMQN+UrTr+wx3zR1thnBrO9Qx949nkyQ9uy/mJqcEb1Ab lH+DoQSVxrdzLGOnVAYwTpgkgH+F1o/DYLZDugYdG5EFlQm+SRlfAWYSg4pGR14C9za/ ZtHqDZE/bL/48lUOG7JJeXCvMA9La06a846JKHXiz+C3XCgPRGVOgCK2q5Mqxmpgawo8 cXiA== 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=xvYXSByRGBlhrpxgL0s48UxHLfKMCdyspJS2KoE0H7E=; b=LmyrETOyBAQN/Qnj7f8qQnG4oc8KGeP4Af9/5DdaSCazNEmDCDtqrVPlQOzoCttWLO f5blHheRZ/IzvtLxwRnI5eIAKORrOhuX+1s8lGC6+cxdhET2rwU+AysAQcD0CbdmMt2r fDjnUerYrfc/9VJZAvWqeBJplixUdLLW59fCbD+3BZmZH6c7rPHHhzv4FZ/OapS7hKyG v5nS8GP1RGEAAu+DKg8EyLQH8xAhU/lhnCHbnTH8aV9G4zi877pXKFhCTq2Ia9bJlnU0 h4+ah4EHY3VSTqJ92TjbBArqV2R+fiVblJGNJA8BOh5fb9dyhzPNWIOwd+6IYwqKtzOJ f7pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Q15A0w0K; 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 jz26si8973347ejc.709.2021.07.09.19.24.50; Fri, 09 Jul 2021 19:25:13 -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=Q15A0w0K; 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 S233070AbhGJCXV (ORCPT + 99 others); Fri, 9 Jul 2021 22:23:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:38484 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232772AbhGJCWG (ORCPT ); Fri, 9 Jul 2021 22:22:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0AD81613ED; Sat, 10 Jul 2021 02:19:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883556; bh=w4ldn3ob9QOxbsAs9pNu3leleo9bN8XQ4UgnfzhSaKk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q15A0w0K1YQr1E1d26Z13xrb4gAY4Lliil/sdB+q2ssZGW+vOWxEpOwMukW3NUJvu 4x15apdd12x00miTCr0y1Vaqv7iJ4pIuKf6KLw2k289QZQUmX7LnqLO07duNYnlQ3u 8hif5+b6Oh6twTOiSQh6NH3j580Kpa5nKi7Tx9abxWQq8se1O6Yu6bi9C/5Ua71Azb RbQLeA1NoOCPJhhZrtJzogg0cc1mUxyNICmFLohV7aSnZC6V5zdEg409RykNyzOtjS YPBJwVgIJkJSEayMB01ZgAhnaD9jXWjByOawJdOtsd6uBas5wWVSpI7yjBkhU1jvf4 j1hBVgUvZ99KQ== 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.13 065/114] iommu/arm-smmu: Fix arm_smmu_device refcount leak when arm_smmu_rpm_get fails Date: Fri, 9 Jul 2021 22:16:59 -0400 Message-Id: <20210710021748.3167666-65-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710021748.3167666-1-sashal@kernel.org> References: <20210710021748.3167666-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 6f72c4d208ca..ee6cac9e7c02 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