Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1147607pxv; Fri, 9 Jul 2021 19:31:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnND+nk3J2ij2fnL04T8UxEhB5hXb+s4v2Qs03rGnat5tHQf2dAC1jPaUgjtDhKxN2DcGI X-Received: by 2002:a05:6402:4c5:: with SMTP id n5mr49696710edw.322.1625884309146; Fri, 09 Jul 2021 19:31:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625884309; cv=none; d=google.com; s=arc-20160816; b=a8JDHnb4EIu1LDSM30DG0eMYkOiskWN+0Zr2tQ88UtKJ1ANMiWgZgngkmjRe36O/dA jQ82CYaICoI1y+YAstSdrvV0Pk5Xb+oxTIOKLFAb14ysu+WHA5SGFmXjnv7ZxftDB0X9 l8UfgOan0M3jadzD9iwu907so3KQqFvHRnNRsVeRXhsQXHahzvGe1AL4WG2YebpUypdq WmHlh6/Ri9I1uGHjHw8GotgBHltEjyHPkuI0HWVfTpS4WFInckhBLLxrUm0BEKh+EdHh KUzAJ/+rEV4jNPHLk3vn74KjnHtSmnpz7dMO1Lnf/rms5FZPMg5y0jRTt5zlFtGMqOYz Rnzg== 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=lzFF9XQxQfXyeEV/czqihlL6j0npAldLHiaepIad9IY=; b=ohIAX5H6pJC98jG0NByaC5k29TKHjtRarhlj7S15B8wYnY8Ur7Qu5T0Bu/+wz0WSKl IvT/qRWy7FtnOfT32s3jOb/S7wDn8HnuyHcTMFqR5mDIJ729Uw7Az5nibE3BeeQyr109 exaEh0hQn2FjKhzLRE/fXjS6BKE18CpOR3A+jVxe90I9kC4y3eypLj9Ekm9oQ4xAoaZ7 b8KfTAeVcNbBFKod/6k198Ji6gqWAq86iFwkTnZj+BPfolpkcjT2CJ1wDcr0errTWxOw Jrc8pAGEjqqaVw6sPuCXygGHSdPHFJ8uYmtLUcnCIyfeJ+huAz3z81x61baHbg+E1KNE xQ9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=T+fy2BUG; 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 16si9650784ejj.242.2021.07.09.19.31.26; Fri, 09 Jul 2021 19:31: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=T+fy2BUG; 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 S234201AbhGJCdR (ORCPT + 99 others); Fri, 9 Jul 2021 22:33:17 -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 S234235AbhGJC3R (ORCPT ); Fri, 9 Jul 2021 22:29:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7C68B6143E; Sat, 10 Jul 2021 02:25:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883942; bh=LTVGr3f4WlwQKL+UpiRVjG7mfst75GqkV/0rmOgPNRw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T+fy2BUGifbytIs6zFt6gLzABm3TBBWBBmdqY/gbsUB3qYUu3xTlezQw6YIfWih6D SrBMdCiogUC5hLX8VL1bJ91LhuTUrn7dRXFU7Q0N38VTF8SPi80ZktBjrO01I46vpV iCj7Ptx+n/OzQ4Vt563WuvKRg04gvdQF8PaFL5Bvg0/9dmV3PghYcQtkZoKrGieI5X qMATxjD6TtDJ9PrAFZXKBH8Eabd9djW2i1esMvUxYbGuvUQVF4UUOnH8itBtI0MVAh ghD+XFd1ECxiAfLbQ/Uy8B5HtOMSiPZzmoSEevRpqIbShs8UjHgDpfUQ47EEPArEnA OzJ7bRvPPs/eA== 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.10 56/93] iommu/arm-smmu: Fix arm_smmu_device refcount leak when arm_smmu_rpm_get fails Date: Fri, 9 Jul 2021 22:23:50 -0400 Message-Id: <20210710022428.3169839-56-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710022428.3169839-1-sashal@kernel.org> References: <20210710022428.3169839-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 bcbacf22331d..052f0a1bf037 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