From nobody Sun Dec 14 06:42:48 2025 Received: from sg-1-102.ptr.blmpb.com (sg-1-102.ptr.blmpb.com [118.26.132.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A6ED238C1F for ; Fri, 12 Dec 2025 13:38:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=118.26.132.102 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765546696; cv=none; b=R6OEEMaSRe6age9EDQJhjcjBYjyx2m5PCxp7V1KcYnxUBgQFpvyHrHoiElB+cXP8hudR6y6jXObNIx6HL5B9zMux3rFhIiM7P+GxlBN5R+GqpblJ8YJNaqTt30Ue+sYmGY13dl/Va1IWivgvEljwdv/hXQHaVzdpdTjMLQbvNAg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765546696; c=relaxed/simple; bh=rJ+wUJ0ZQN5cf9uHHw+LRHss2EaA0VXJDDempjZpzs0=; h=Message-Id:Cc:From:Date:Subject:Mime-Version:Content-Type:To; b=DCrLbyUAb6DWZd7zTyq7jlFST+F9UWN3JctyUUJ0efuFguNFeN3lJULLW/37fEFKV7pXw9IxG/CasmrkF4wrj4qw076tlPWangqRsxMsavv5hl4G8dleix21B2JaRnd3BgpRX9zWTZDlifrSZUrt/NoeBWTl2HNca5F41BSyioY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=nT6tt5Br; arc=none smtp.client-ip=118.26.132.102 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="nT6tt5Br" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1765546681; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=oAjUxi/jSH9JUSsh/4RDgmel17P3oiVwVjj9KTXKORU=; b=nT6tt5BrlC5mTGI54U9tnypyNlrJHKEflWitx2yTR9DnfzlcZQx3Lbb3nZ+HkiaTHBeyBS kXL9qZ7C3S4XRdRXWIlh+JJJOeiJncmmOfy4Yh7rT3EZzz+zKoRsYhohH8GtevJOW2T1d7 ssR+eJ4sZyJ1P3Ms8lXVWVubpWrYBuDOVlOcawhIu/REQj1t0y4bE/JNCK6FjgXd4rujfu iOF1pnotYkHyzi/92+oSzWYMocppAWkb6uKSPWKYH/r6mSyuHaERfq1CaXNKY80+4jgJ6H pOkMYxCvOftOQim0yJCzOG+v7qbTk5JBlRFp+WeeA4FYQ0ILNHDDhOQsB6Rh0A== Message-Id: <20251212133737.2367-1-guojinhui.liam@bytedance.com> Content-Transfer-Encoding: quoted-printable X-Mailer: git-send-email 2.17.1 Cc: , , , From: "Jinhui Guo" Date: Fri, 12 Dec 2025 21:37:37 +0800 Subject: [PATCH v2] PCI: Fix incorrect unlocking in pci_slot_trylock() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Original-From: Jinhui Guo X-Lms-Return-Path: To: , , , , Content-Type: text/plain; charset="utf-8" Commit a4e772898f8b ("PCI: Add missing bridge lock to pci_bus_lock()") delegates the bridge device's pci_dev_trylock() to pci_bus_trylock() in pci_slot_trylock(), but it forgets to remove the corresponding pci_dev_unlock() when pci_bus_trylock() fails. Before the commit, the code did: if (!pci_dev_trylock(dev)) /* <- lock bridge device */ goto unlock; if (dev->subordinate) { if (!pci_bus_trylock(dev->subordinate)) { pci_dev_unlock(dev); /* <- unlock bridge device */ goto unlock; } } After the commit the bridge-device lock is no longer taken, but the pci_dev_unlock(dev) on the failure path was left in place, leading to the bug. This yields one of two errors: 1. A warning that the lock is being unlocked when no one holds it. 2. An incorrect unlock of a lock that belongs to another thread. Fix it by removing the now-redundant pci_dev_unlock(dev) on the failure path. Fixes: a4e772898f8b ("PCI: Add missing bridge lock to pci_bus_lock()") Cc: stable@vger.kernel.org Signed-off-by: Jinhui Guo Acked-by: Ilpo J=C3=A4rvinen --- Hi, all v1: https://lore.kernel.org/all/20251211123635.2215-1-guojinhui.liam@byteda= nce.com/ Changelog in v1 -> v2 - The v1 commit message was too brief, so I=E2=80=99ve sent v2 with more d= etail. - Remove the braces from the if (!pci_bus_trylock(dev->subordinate)) state= ment. Sorry for the noise. Best Regards, Jinhui drivers/pci/pci.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 13dbb405dc31..59319e08fca6 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -5346,10 +5346,8 @@ static int pci_slot_trylock(struct pci_slot *slot) if (!dev->slot || dev->slot !=3D slot) continue; if (dev->subordinate) { - if (!pci_bus_trylock(dev->subordinate)) { - pci_dev_unlock(dev); + if (!pci_bus_trylock(dev->subordinate)) goto unlock; - } } else if (!pci_dev_trylock(dev)) goto unlock; } --=20 2.20.1