From patchwork Thu Dec 1 04:01:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 28186 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp65612wrr; Wed, 30 Nov 2022 20:19:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf5wrwKzEL4Jq5ltxXd/K7Nd/agrkp0agQe4/91keh2Ozu72GNsfag2rNhNvdS624kGpmklY X-Received: by 2002:a63:f308:0:b0:43b:ddc9:1d13 with SMTP id l8-20020a63f308000000b0043bddc91d13mr57661097pgh.284.1669868342838; Wed, 30 Nov 2022 20:19:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669868342; cv=none; d=google.com; s=arc-20160816; b=l603/NTygRr3dSPwss4OyhDTeoKpY9WMyLcUA54KrM5MzljWWifO2p2zKrlJ7DVwyo cQAWHhc462+Nr/7NZq1qdKQSge+bB2DwbNCXtU2gvXVPu+EhZBI5tWT51RBAVFET685y K5dg1/0f97sIFHlBpuN2zCiDjUT1S8r6kGQYqhcF/yeabohtRoZGjnAjefwemMSFsPVG jYrXsZeleYwvwtKtoOXegOjWtOmLl8m97624YCXXQvjsiFhGopbbehZx10sXiQrh77+P jqfr6kfYx7BjrFfgHitcE51uKanzTHrX8mKUPUjLb8gUNLZvpTfA3CulJN1epOaK0vma HzQg== 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=8lQq3xHOoahTDBhnDkrNVkpv/4eXQeOK+e0TWQxwTXI=; b=nRxC8p3K7n5zEsNVjwQeM4lxiKPn+sWq5vVB7RaGRZBjKEFqQjJXQncOzLWIXYbBuL M9yE5nicgxRTEXJlYQ3VN/aOk+YPOsNVYN/zK5i9+AmW8T2SV5H8Xb3OpsxsoDrYeP9v 4TwMwCGTj7CQCKd2VNUAlKHWfTPcrmRS/wM8M4Rk92+rWFzquV0GobKJHurkvYn6v4b3 /8zZF5VOULqVjCpzImsPChUZR5XYcVSuW/wjnFbIJj7vhNsUuYfO6g892KWDzB4l1VVQ zbuDsM6sWwq4xPvVf4G5ZC7qtHNKQMiEfOJjKPIKdPz600fRzvDSQnzZiEc5wiaYQxv1 e7Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="aZZq9ES/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j1-20020a056a00130100b005721983cbe7si3759162pfu.318.2022.11.30.20.18.35; Wed, 30 Nov 2022 20:19:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="aZZq9ES/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229682AbiLAEJD (ORCPT + 99 others); Wed, 30 Nov 2022 23:09:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbiLAEIw (ORCPT ); Wed, 30 Nov 2022 23:08:52 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8885E77422 for ; Wed, 30 Nov 2022 20:08:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669867731; x=1701403731; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yXwiYNvS9neESZJSKR531+MusOXMqiOrzDRp1zDx7kM=; b=aZZq9ES/lwJnKG8Rm8qMtCMnO8l/9QX5s/8rrHCf/1UiQmOJNGTUs3nh GWvJLfRE3QpQDdJHIGw9PrMsIoOrHvHmQbkjJbzbB3IjyeQTTlHrnpyu3 a6musvFkqH/jmAkDaaJ3hpOToAz5vUMSXXOrDS1BW5xmMpQXJYao/ORXF PMVb0c5Pn/7Xj1WJpv0AIST/iakYUvSeU4sDOnPlnYunLcjTWXH3hTk22 MfmHJ8rMl5AFmD5Oew6eSFNMmUT7XDTTPqTM5p/qDTmgmnrOy9nMA1R// buRmTK5X0IqamNmMrBx+jceKtxKU2nB8htH/NhcSXku435wMz25S03dT8 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10547"; a="377745765" X-IronPort-AV: E=Sophos;i="5.96,207,1665471600"; d="scan'208";a="377745765" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2022 20:08:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10547"; a="707911661" X-IronPort-AV: E=Sophos;i="5.96,207,1665471600"; d="scan'208";a="707911661" Received: from allen-box.sh.intel.com ([10.239.159.48]) by fmsmga008.fm.intel.com with ESMTP; 30 Nov 2022 20:08:48 -0800 From: Lu Baolu To: Joerg Roedel Cc: Xiongfeng Wang , Yang Yingliang , Jacob Pan , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] iommu/vt-d: Fix PCI device refcount leak in dmar_dev_scope_init() Date: Thu, 1 Dec 2022 12:01:27 +0800 Message-Id: <20221201040127.1962750-5-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221201040127.1962750-1-baolu.lu@linux.intel.com> References: <20221201040127.1962750-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750983867815324584?= X-GMAIL-MSGID: =?utf-8?q?1750983867815324584?= From: Xiongfeng Wang for_each_pci_dev() is implemented by pci_get_device(). The comment of pci_get_device() says that it will increase the reference count for the returned pci_dev and also decrease the reference count for the input pci_dev @from if it is not NULL. If we break for_each_pci_dev() loop with pdev not NULL, we need to call pci_dev_put() to decrease the reference count. Add the missing pci_dev_put() for the error path to avoid reference count leak. Fixes: 2e4552893038 ("iommu/vt-d: Unify the way to process DMAR device scope array") Signed-off-by: Xiongfeng Wang Link: https://lore.kernel.org/r/20221121113649.190393-3-wangxiongfeng2@huawei.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/dmar.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index 5a8f780e7ffd..bc94059a5b87 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -820,6 +820,7 @@ int __init dmar_dev_scope_init(void) info = dmar_alloc_pci_notify_info(dev, BUS_NOTIFY_ADD_DEVICE); if (!info) { + pci_dev_put(dev); return dmar_dev_scope_status; } else { dmar_pci_bus_add_dev(info);