Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1630935rdb; Mon, 8 Jan 2024 05:44:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IFB8BNEKQv9Kxgwa+gKXT6Ule7VsxuzB1mWjOVNV5fhMzaOSRumWdtcW9ZUJMOBZbDr/WQC X-Received: by 2002:a05:620a:4052:b0:783:1299:dc0 with SMTP id i18-20020a05620a405200b0078312990dc0mr2989807qko.5.1704721454368; Mon, 08 Jan 2024 05:44:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704721454; cv=none; d=google.com; s=arc-20160816; b=rx23FTZzfnIX74NA40lpunjZbSPv68rYBODtvRwhHVxh0E9UHjX3S7y3JXqKfB9zLd LRRfxDw6fyHR33W+clt8ItY2EkbCzeBne1Zz/vZ/Ph369pthdCbehzC6+iXKbWXbh/eS TtJqr7CDpqFrQbklUkZ8ym1kc7Gf8bhQGFsGi+vKlPaX+I+cu94YO5iqVNF2Nus6sDSg fTT26UdNokochIYEFTJBBIlgiMVf8UxtzYxKp/6n8xjTKYXFTJuaQwBHiEMo0sFmx1k9 XyplWtLjQB5gLwGkbpu4qP4ccJEfirQHg/UHIMyBnDCawUBNq6iFKQiFiB43SuWQ9ZSG ui6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:organization:references :in-reply-to:message-id:subject:cc:to:from:date; bh=QQbXmEB+dy3U/2rN5wlLFB2zjf6a+/Qrb9bRrfYD9Tk=; fh=0W5f0lO646H9ej4e207bbRNxdVmEdA5bSqgVnTXYIq8=; b=C0PIgto6epLG70teaWsqnJSmkYzvGGMrZ53AIEcjEETVBTend5nZ6ubgjnX5NicUyy VKDnJdNKS1VA82wA+ehLe6viKpItxB+aTbMcB8tAeVV5l8YV+UIZoyFFZfxx8ZjuDZSb wtGpjMEZNYpWGbLKalkLdGY0Wt04uqp+A+RHco2TfXDADS2x+2vWk4uipFhg4unI8ukk 3gvrCRVdKrB4YNkoW5iS6XyxYjOtiYq68XVQX2KlvkGo4XwlqDYU+yIQQtsNEmYqhZ8R bK6qnmcI0QlS3QClyZDcPQ17Dm5FNdc4l/gPNDc9M+Cra14FCRvHD2eXI0T3p7wzZW0i vl1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-19638-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19638-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id j20-20020a05620a289400b0076d81c85ecesi7889289qkp.723.2024.01.08.05.44.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 05:44:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19638-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-19638-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19638-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E8F081C229B6 for ; Mon, 8 Jan 2024 13:44:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 390D645946; Mon, 8 Jan 2024 13:44:06 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 623E245944; Mon, 8 Jan 2024 13:44:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4T7wFh3KSQz67MmR; Mon, 8 Jan 2024 21:41:28 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 725321400D9; Mon, 8 Jan 2024 21:44:01 +0800 (CST) Received: from localhost (10.202.227.76) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 8 Jan 2024 13:44:00 +0000 Date: Mon, 8 Jan 2024 13:44:00 +0000 From: Jonathan Cameron To: Ira Weiny CC: Dan Williams , Smita Koralahalli , Shiju Jose , Yazen Ghannam , "Davidlohr Bueso" , Dave Jiang , "Alison Schofield" , Vishal Verma , Ard Biesheuvel , , , , Bjorn Helgaas Subject: Re: [PATCH v5 8/9] PCI: Define scoped based management functions Message-ID: <20240108134400.00001357@Huawei.com> In-Reply-To: <20231220-cxl-cper-v5-8-1bb8a4ca2c7a@intel.com> References: <20231220-cxl-cper-v5-0-1bb8a4ca2c7a@intel.com> <20231220-cxl-cper-v5-8-1bb8a4ca2c7a@intel.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: lhrpeml100004.china.huawei.com (7.191.162.219) To lhrpeml500005.china.huawei.com (7.191.163.240) On Wed, 20 Dec 2023 16:17:35 -0800 Ira Weiny wrote: > Users of pci_dev_get() can benefit from a scoped based put. Also, > locking a PCI device is often done within a single scope. > > Define a pci_dev_put() free function and a PCI device lock guard. These > will initially be used in new CXL event processing code but is defined > in a separate patch for others to pickup and use/backport easier. > > Cc: Bjorn Helgaas > Signed-off-by: Ira Weiny With the extra text buried deep in the discussion LGTM. I've not been that thorough on documenting my own similar cleanup.h series, so might well steal some of that for the ones I have outstanding for device_handle_put() and fwnode_handle_put() ;) Reviewed-by: Jonathan Cameron > > --- > Changes for v5: > [Jonathan: New patch] > --- > include/linux/pci.h | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/include/linux/pci.h b/include/linux/pci.h > index 60ca768bc867..290d0a2651b2 100644 > --- a/include/linux/pci.h > +++ b/include/linux/pci.h > @@ -1170,6 +1170,7 @@ int pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge); > u8 pci_common_swizzle(struct pci_dev *dev, u8 *pinp); > struct pci_dev *pci_dev_get(struct pci_dev *dev); > void pci_dev_put(struct pci_dev *dev); > +DEFINE_FREE(pci_dev_put, struct pci_dev *, if (_T) pci_dev_put(_T)) > void pci_remove_bus(struct pci_bus *b); > void pci_stop_and_remove_bus_device(struct pci_dev *dev); > void pci_stop_and_remove_bus_device_locked(struct pci_dev *dev); > @@ -1871,6 +1872,7 @@ void pci_cfg_access_unlock(struct pci_dev *dev); > void pci_dev_lock(struct pci_dev *dev); > int pci_dev_trylock(struct pci_dev *dev); > void pci_dev_unlock(struct pci_dev *dev); > +DEFINE_GUARD(pci_dev, struct pci_dev *, pci_dev_lock(_T), pci_dev_unlock(_T)) > > /* > * PCI domain support. Sometimes called PCI segment (eg by ACPI), >