From nobody Sat Feb 7 17:48:39 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 2D122217723; Fri, 16 Jan 2026 12:57:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768568281; cv=none; b=JTjuv9UyA/AI86OOU0dBYELQT48OfA2bYfouazuS8ZVMbYjso59v18YibJwhgPWQiwK4zxsIpkhO2Dbafz5C7vfYdQfcFDaL1SSc+rkuzeWAAnED/Ilic5iDaYl6A0q6eDxFsd+ymU2wiDVJ0rJIVVVdVifYXnAK1c8X2iAbyKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768568281; c=relaxed/simple; bh=JPavpiMWH9fnbCMhydtcUUmZ9VS9PmQhmFdCqXKHAyc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=B8YChqsC/aLUhWygiCPkOzpEdW5QkWx9r3iLhwWiCMF6PgBNCatx70uk6AsLaqAeXE4cJJifFh6ggmeeITLCH/04IhhIJooJCaV9ODN+bqmKAR/P5w66xLk5zCBH2bl+RYafGyjch7Lu5fcdt+Chcm9rLPZLYKCqlvTT3cVbt94= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=HK7m9FsA; arc=none smtp.client-ip=192.198.163.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="HK7m9FsA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1768568280; x=1800104280; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JPavpiMWH9fnbCMhydtcUUmZ9VS9PmQhmFdCqXKHAyc=; b=HK7m9FsAjQthmqvfT40Zs+nl73Ao1nLIQSrMONEk3FRz0eN74SfJUlqo O+xNyUXV6X3iGv0WkidkhFUci9VqHqXE8TtnDmPSbZEN06KQCQHDK8/9y Bcqz+4Co+QAakClEGy2hp0Y+Th5+1p5HToIVFr5AhrTALlMleueNhlziq ITfCQRKdRn8L63qQ4Au0GP+XvpsWZ1B4lJqUddD4BXPT+JSLi2za1Lm2u igrgsTiw5KY9N7Vdrk1ONSG0D/i/rhEFqJjbprkqN5Y7LMZccds4AmGGt jkRC23IQQ8B/WoxvhPSnsYTkXDaWP/v6Rwh2Y3SBTt/sUTkPP1LaXRKmO g==; X-CSE-ConnectionGUID: N4y/8DjTSFGEV31soKCqBQ== X-CSE-MsgGUID: eCWR9NRUSiKwiYD4zI//lg== X-IronPort-AV: E=McAfee;i="6800,10657,11673"; a="80603128" X-IronPort-AV: E=Sophos;i="6.21,231,1763452800"; d="scan'208";a="80603128" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2026 04:58:00 -0800 X-CSE-ConnectionGUID: bG/S2c3zSNWOsFkxRWoCWw== X-CSE-MsgGUID: gqTCZmLfQVSTCPQGhnDxBg== X-ExtLoop1: 1 Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.245.178]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2026 04:57:56 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: "Jinhui Guo" , Keith Busch , "Anthony Pighin (Nokia)" , Alex Williamson , Jonathan Cameron , Bjorn Helgaas , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH 1/3] PCI: Use lockdep_assert_held(pci_bus_sem) to verify lock is held Date: Fri, 16 Jan 2026 14:57:40 +0200 Message-Id: <20260116125742.1890-2-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260116125742.1890-1-ilpo.jarvinen@linux.intel.com> References: <20260116125742.1890-1-ilpo.jarvinen@linux.intel.com> 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="utf-8" Content-Transfer-Encoding: quoted-printable The function comment for pci_bus_max_d3cold_delay() declares pci_bus_sem must be held while calling the function which can be automatically checked. Add lockdep_assert_held(pci_bus_sem) to confirm pci_bus_sem is held. Also mark the comment line with Context prefix. Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/pci.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 75a98819db6f..29a365e2dd57 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -4622,7 +4623,7 @@ bool pcie_wait_for_link(struct pci_dev *pdev, bool ac= tive) * spec says 100 ms, but firmware can lower it and we allow drivers to * increase it as well. * - * Called with @pci_bus_sem locked for reading. + * Context: Called with @pci_bus_sem locked for reading. */ static int pci_bus_max_d3cold_delay(const struct pci_bus *bus) { @@ -4630,6 +4631,8 @@ static int pci_bus_max_d3cold_delay(const struct pci_= bus *bus) int min_delay =3D 100; int max_delay =3D 0; =20 + lockdep_assert_held(&pci_bus_sem); + list_for_each_entry(pdev, &bus->devices, bus_list) { if (pdev->d3cold_delay < min_delay) min_delay =3D pdev->d3cold_delay; --=20 2.39.5 From nobody Sat Feb 7 17:48:39 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 A2FA51F239B; Fri, 16 Jan 2026 12:58:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768568298; cv=none; b=s5te7P62HFdohqGVa2tMxeV6J8Riw02H1sD1ftHUlGC/YM4oDWojVUXfkVtQ0nYeXhMszjdpIX5meIDRjfjkK6ah46YJBj7IfDcalPVjUaX2W61B5KALsiu9I5g53i1gYkS1OAdNiWgfAYUWkP9+OXl5cusKNz10a5411dNxjNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768568298; c=relaxed/simple; bh=QzALkc0FClKUjD4YmlWD7AzxG4iZBETWjIfTKmES/ps=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=ibg+gyWQq0Nj8sZEh3AMNk5cT0jEpxY9Tp0rX44gcTAn2mZth/HA8JBIpj6n92sMmQ2pJE1/gA/HCqTQjA3ZBrIcoPAwf1JyRQCpc9Dn9fvm1xhX2OzCW7aPP8bYYCRK9Jk+GtXtl3OYLUOLnFsiLLpnHSJs2eJfLMJqrB4VTKw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=H77XL9sH; arc=none smtp.client-ip=192.198.163.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="H77XL9sH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1768568289; x=1800104289; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QzALkc0FClKUjD4YmlWD7AzxG4iZBETWjIfTKmES/ps=; b=H77XL9sH0vKulw+0/qNyA+OpK5EUeckJ8BP72lIu+BbB3GXkmdh5VXtt XGrc/70KPaiEktRMnn1zxtDbzZMLn+aAiy7PQXGl7yS9rBXYjLcDAgXI4 Tv/fUC36j5fJe1mUZLBszxy5qcU9v1Oesa2d1UiTTKX0HCVKqRA3VJkjJ L9gjVnjVST+RLjModtu5g0simU/xCQNRy3AWfvpcZ89CfbG0uPJVdFwYK EmrYwx1Y2i/GCrUVpnkD02EjMWL7DoIr8JB+4vtyrXXnMZk4XXKYm8JQ3 n2nYWgIiVY66ll5gm4lKDUDNimnTGqhOSxjxFwnXlRrv4XNanJCk+Zzwx w==; X-CSE-ConnectionGUID: R14NHzCDQA+d0nZEg3m3lA== X-CSE-MsgGUID: ZkuL8OT9RQ+6KCbJ7XMdeQ== X-IronPort-AV: E=McAfee;i="6800,10657,11673"; a="80603144" X-IronPort-AV: E=Sophos;i="6.21,231,1763452800"; d="scan'208";a="80603144" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2026 04:58:08 -0800 X-CSE-ConnectionGUID: iTSk9lfmTT+eBDRnrhx7jw== X-CSE-MsgGUID: Skt5wwrRStGRDCwIhz8bCQ== X-ExtLoop1: 1 Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.245.178]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2026 04:58:05 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: "Jinhui Guo" , Keith Busch , "Anthony Pighin (Nokia)" , Alex Williamson , Jonathan Cameron , Bjorn Helgaas , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH 2/3] PCI: Use device_lock_assert() to verify device lock is held Date: Fri, 16 Jan 2026 14:57:41 +0200 Message-Id: <20260116125742.1890-3-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260116125742.1890-1-ilpo.jarvinen@linux.intel.com> References: <20260116125742.1890-1-ilpo.jarvinen@linux.intel.com> 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="utf-8" Content-Transfer-Encoding: quoted-printable Multiple function comments say the function should be called with device_lock held. Check that by calling device_lock_assert(). Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/pci.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 29a365e2dd57..e1333539c7b7 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4970,6 +4970,7 @@ static void pci_dev_save_and_disable(struct pci_dev *= dev) * races with ->remove() by the device lock, which must be held by * the caller. */ + device_lock_assert(&dev->dev); if (err_handler && err_handler->reset_prepare) err_handler->reset_prepare(dev); else if (dev->driver) @@ -5040,7 +5041,9 @@ const struct pci_reset_fn_method pci_reset_fn_methods= [] =3D { * device including MSI, bus mastering, BARs, decoding IO and memory space= s, * etc. * - * Returns 0 if the device function was successfully reset or negative if = the + * Context: The caller must hold the device lock. + * + * Return: 0 if the device function was successfully reset or negative if = the * device doesn't support resetting a single function. */ int __pci_reset_function_locked(struct pci_dev *dev) @@ -5049,6 +5052,7 @@ int __pci_reset_function_locked(struct pci_dev *dev) const struct pci_reset_fn_method *method; =20 might_sleep(); + device_lock_assert(&dev->dev); =20 /* * A reset method returns -ENOTTY if it doesn't support this device and @@ -5171,13 +5175,17 @@ EXPORT_SYMBOL_GPL(pci_reset_function); * over the reset. It also differs from pci_reset_function() in that it * requires the PCI device lock to be held. * - * Returns 0 if the device function was successfully reset or negative if = the + * Context: The caller must hold the device lock. + * + * Return: 0 if the device function was successfully reset or negative if = the * device doesn't support resetting a single function. */ int pci_reset_function_locked(struct pci_dev *dev) { int rc; =20 + device_lock_assert(&dev->dev); + if (!pci_reset_supported(dev)) return -ENOTTY; =20 --=20 2.39.5 From nobody Sat Feb 7 17:48:39 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (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 9CC59225A38; Fri, 16 Jan 2026 12:58:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768568302; cv=none; b=j25f4oGcJxxSKGnDhWcVIeRqWPbDD7fX1Hjly3JIZpGEl4c1KqcHiyXOeShrTcxsdzGknUIebopDZftSlByENBWiwOUvjCZVz7AIhUhbkEwXG4qcDunefG93ie9Rw0dHlBhgk5R5gmle9vkAzx+ZEuJgBqVKsu01tH3U8eSDEac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768568302; c=relaxed/simple; bh=UDXrYaw3rI48vBK1SRp/7YhpPlUFuB+2Nhwv4YDnGnw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=PiO98700RJGoz6vD9EHCOX9GRBsW3zUwfLsShMC6kNC2lUNqd16HUCOLlVXg3R82ocoEzl/TGMV5arYPd+Gx5z39F1tX4/xQpFRcWbAU5P0umkyagQe3A5Q1Jn/OuInPlS5pUXd5EYpxuN5iUFWi22Y0eXFzB7hywL6XbVjvZhM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=IMS92Xb9; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="IMS92Xb9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1768568298; x=1800104298; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UDXrYaw3rI48vBK1SRp/7YhpPlUFuB+2Nhwv4YDnGnw=; b=IMS92Xb98SDgsiN/jA+/cOPudS7yLqjRKhjgHGu9A86iqQZ/WPCspu10 NcqscoWiAV5OGdfejTdyzaQzaRuNcnjofJbL8rPjMCI471rZQ1yEdKYiJ BX+F4lpfXrhXaPr5DH4ekg+ko5DqaiD5Lc9YxuMsbK0IN19CmoGjmnR9F w9TKgTKnvaQNhjm/F2Hbeaj2rdyzsaiLeSAM+huxDmaPQ19IXprGTy2Hx muboNla3+SoBzBgwvzFythmyHOMTJ1yvI73wsuyyshFdRg3XpRaquucs0 sZrb0tV4742V9VHgXhNU23Y6YyozGVHEeXfTNO4OU0960PTIDVWih6sOn w==; X-CSE-ConnectionGUID: uSZj3yjTR0iAZOZUhfJHyw== X-CSE-MsgGUID: 24BL9NFoRYm+GvDQ25TH+g== X-IronPort-AV: E=McAfee;i="6800,10657,11673"; a="73511154" X-IronPort-AV: E=Sophos;i="6.21,231,1763452800"; d="scan'208";a="73511154" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2026 04:58:18 -0800 X-CSE-ConnectionGUID: hc6jFAjiR/2FaSiib9+J2Q== X-CSE-MsgGUID: mnUbxwsYT1qEmIwvmSPa/Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,231,1763452800"; d="scan'208";a="209371180" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.245.178]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2026 04:58:14 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: "Jinhui Guo" , Keith Busch , "Anthony Pighin (Nokia)" , Alex Williamson , Jonathan Cameron , Bjorn Helgaas , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH 3/3] PCI: Consolidate pci_bus/slot_lock/unlock/trylock() Date: Fri, 16 Jan 2026 14:57:42 +0200 Message-Id: <20260116125742.1890-4-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260116125742.1890-1-ilpo.jarvinen@linux.intel.com> References: <20260116125742.1890-1-ilpo.jarvinen@linux.intel.com> 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="utf-8" Content-Transfer-Encoding: quoted-printable pci_bus/slot_lock/unlock/trylock() largely duplicate the bus iteration loop with variation only due to slot filter handling. The only differences in the loops is where the struct bus is found (directly in the argument vs in slot->bus) and whether slot filter is applied. Those difference are simple to handle using function parameters. Consolidate the bus iteration loop to one place by creating __pci_bus_{lock,unlock,trylock}() and call them from the non-underscore locking functions. Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/pci.c | 103 ++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 54 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index e1333539c7b7..622920c1529f 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -5242,13 +5242,18 @@ static bool pci_bus_resettable(struct pci_bus *bus) return true; } =20 +static void pci_bus_lock(struct pci_bus *bus); +static void pci_bus_unlock(struct pci_bus *bus); +static int pci_bus_trylock(struct pci_bus *bus); + /* Lock devices from the top of the tree down */ -static void pci_bus_lock(struct pci_bus *bus) +static void __pci_bus_lock(struct pci_bus *bus, struct pci_slot *slot) { struct pci_dev *dev; =20 - pci_dev_lock(bus->self); list_for_each_entry(dev, &bus->devices, bus_list) { + if (slot && (!dev->slot || dev->slot !=3D slot)) + continue; if (dev->subordinate) pci_bus_lock(dev->subordinate); else @@ -5257,28 +5262,28 @@ static void pci_bus_lock(struct pci_bus *bus) } =20 /* Unlock devices from the bottom of the tree up */ -static void pci_bus_unlock(struct pci_bus *bus) +static void __pci_bus_unlock(struct pci_bus *bus, struct pci_slot *slot) { struct pci_dev *dev; =20 list_for_each_entry(dev, &bus->devices, bus_list) { + if (slot && (!dev->slot || dev->slot !=3D slot)) + continue; if (dev->subordinate) pci_bus_unlock(dev->subordinate); else pci_dev_unlock(dev); } - pci_dev_unlock(bus->self); } =20 /* Return 1 on successful lock, 0 on contention */ -static int pci_bus_trylock(struct pci_bus *bus) +static int __pci_bus_trylock(struct pci_bus *bus, struct pci_slot *slot) { struct pci_dev *dev; =20 - if (!pci_dev_trylock(bus->self)) - return 0; - list_for_each_entry(dev, &bus->devices, bus_list) { + if (slot && (!dev->slot || dev->slot !=3D slot)) + continue; if (dev->subordinate) { if (!pci_bus_trylock(dev->subordinate)) goto unlock; @@ -5288,12 +5293,44 @@ static int pci_bus_trylock(struct pci_bus *bus) return 1; =20 unlock: - list_for_each_entry_continue_reverse(dev, &bus->devices, bus_list) { + list_for_each_entry_continue_reverse(dev, + &slot->bus->devices, bus_list) { + if (slot && (!dev->slot || dev->slot !=3D slot)) + continue; if (dev->subordinate) pci_bus_unlock(dev->subordinate); else pci_dev_unlock(dev); } + return 0; +} + +/* Lock devices from the top of the tree down */ +static void pci_bus_lock(struct pci_bus *bus) +{ + pci_dev_lock(bus->self); + __pci_bus_lock(bus, NULL); +} + +/* Unlock devices from the bottom of the tree up */ +static void pci_bus_unlock(struct pci_bus *bus) +{ + __pci_bus_unlock(bus, NULL); + pci_dev_unlock(bus->self); +} + +/* Return 1 on successful lock, 0 on contention */ +static int pci_bus_trylock(struct pci_bus *bus) +{ + if (!pci_dev_trylock(bus->self)) + return 0; + + if (!__pci_bus_trylock(bus, NULL)) + goto unlock; + + return 1; + +unlock: pci_dev_unlock(bus->self); return 0; } @@ -5321,61 +5358,19 @@ static bool pci_slot_resettable(struct pci_slot *sl= ot) /* Lock devices from the top of the tree down */ static void pci_slot_lock(struct pci_slot *slot) { - struct pci_dev *dev; - - list_for_each_entry(dev, &slot->bus->devices, bus_list) { - if (!dev->slot || dev->slot !=3D slot) - continue; - if (dev->subordinate) - pci_bus_lock(dev->subordinate); - else - pci_dev_lock(dev); - } + __pci_bus_lock(slot->bus, slot); } =20 /* Unlock devices from the bottom of the tree up */ static void pci_slot_unlock(struct pci_slot *slot) { - struct pci_dev *dev; - - list_for_each_entry(dev, &slot->bus->devices, bus_list) { - if (!dev->slot || dev->slot !=3D slot) - continue; - if (dev->subordinate) - pci_bus_unlock(dev->subordinate); - else - pci_dev_unlock(dev); - } + __pci_bus_unlock(slot->bus, slot); } =20 /* Return 1 on successful lock, 0 on contention */ static int pci_slot_trylock(struct pci_slot *slot) { - struct pci_dev *dev; - - list_for_each_entry(dev, &slot->bus->devices, bus_list) { - if (!dev->slot || dev->slot !=3D slot) - continue; - if (dev->subordinate) { - if (!pci_bus_trylock(dev->subordinate)) { - goto unlock; - } - } else if (!pci_dev_trylock(dev)) - goto unlock; - } - return 1; - -unlock: - list_for_each_entry_continue_reverse(dev, - &slot->bus->devices, bus_list) { - if (!dev->slot || dev->slot !=3D slot) - continue; - if (dev->subordinate) - pci_bus_unlock(dev->subordinate); - else - pci_dev_unlock(dev); - } - return 0; + return __pci_bus_trylock(slot->bus, slot); } =20 /* --=20 2.39.5