From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 460FB5208BA; Thu, 1 Oct 2026 14:29:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790864977; cv=none; b=aOQzTYOrOCw1ED6F0GiA2NXSv/315UE+/oqznxRLk55Ghoxxnr/XG6pC5m5AX3M6SQvrYhOwLSlogeo4Km7O3y/akrp9WHc/61F21gA73ThAQRy9kM0qLPjnuykL6g2rCxzOtz66vIP+L07SbOq6DCGEwGupzhJwdL2PyXYhWhA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790864977; c=relaxed/simple; bh=yZqxjQ8fdgALToubPfisyGu29t7CZxxWw5oRM34RS1M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Tr0Uz24/n4MGH6dUjjQ8RmlKkI0lp2m4v6j9WK5OrOR0P7TbVoEhAVzqNaHWlZhOFO5Thry51HyNzP2VgAIaQEt9QisKj5audJqIdhez+2pBUXp5M/Cjm52Po0OtBPvA9+M2/9Dzm/dgpqg7hU9r0IexDzhirgb/p1cKR8zBuyE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=nkgHr3JK; arc=none smtp.client-ip=185.246.85.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="nkgHr3JK" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 720AF4E4153F; Thu, 1 Oct 2026 14:29:24 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 42D5960341; Thu, 1 Oct 2026 14:29:24 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id E363E10328176; Thu, 1 Oct 2026 16:29:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1790864961; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=MZWIL+2PnnIxORtPMeMG5BPHqe/9YA3Fv4kBuRYMrA0=; b=nkgHr3JKcJLN7VI9tIzpyA7TGrZuiZw24ZNhZYJvLMJURmqwwcemaNPHbGsutef/8hSrCV 8UWWRCe2VXlDVEWb993nEt+UCZh0c93HTxQzoJ3vR0eBBHTkXD1Vu39Fs/emgRPTGr7v93 smqcKqJ8qPLmQsVcOV9dYPnwdAxz0jKaGm6DhJU1X7ZXkAbcDYbD0KAraE1Zt2FDdMozzK ZRpKckMtet+J8xW4+mHEi6uaz4H30imOM8PM0IZrMBv50Oofapc3QhicnwPdNvyysZofj6 VzW3Sp6ojl4hLgnh3D81lNi1Yqos/e4d/mF1r6T54owsWkbif0f0ZR1b2R36FQ== From: Herve Codina To: Richard Cheng , Andrew Lunn , Rob Herring , Saravana Kannan , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Bjorn Helgaas , Charles Keepax , Richard Fitzgerald , David Rhodes , Linus Walleij , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Bartosz Golaszewski , Len Brown , Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Dan Williams , Ira Weiny , Li Ming , Herve Codina , Lizhi Hou Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-sound@vger.kernel.org, patches@opensource.cirrus.com, linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org, linux-cxl@vger.kernel.org, Allan Nielsen , Horatiu Vultur , Daniel Machon , Steen Hegelund , Luca Ceresoli , Thomas Petazzoni , stable@vger.kernel.org, Manivannan Sadhasivam , Bartosz Golaszewski Subject: [PATCH v12 07/10] PCI: of: Clear fwnode->dev during root bridge node removal and error path Date: Thu, 1 Oct 2026 16:28:07 +0200 Message-ID: <20261001142815.277550-8-herve.codina@bootlin.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261001142815.277550-1-herve.codina@bootlin.com> References: <20261001142815.277550-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 During the of_pci_make_host_bridge_node() call, an OF node is created dynamically and its fwnode device (fwnode->dev) is set to the PCI root bridge device using the fw_devlink_set_device(&np->fwnode, &bridge->dev) call. On removal, of_pci_remove_host_bridge_node() is called and calls device_remove_of_node() which in turn set to NULL the related dev->fwnode. Later in the removal sequence, device_del() is called and runs its cleanup logic: if (dev->fwnode && dev->fwnode->dev == dev) fw_devlink_set_device(dev->fwnode, NULL); Because dev->fwnode has been cleared earlier, fw_devlink_set_device() is not called and leaves fwnode->dev unchanged. This fwnode device (fwnode->dev) becomes an dangling pointer. If any reference to the OF node is held after this removal, the pointer is still accessible using the OF node (np->fwnode.dev) but points to a freed area. The exact same issue is present in the of_pci_make_host_bridge_node() error path leading to the exact same dangling fwnode->dev. Avoid this dangling fwnode->dev pointer by clearing it in of_pci_remove_host_bridge_node() and in of_pci_make_host_bridge_node() error path. Fixes: 1f340724419e ("PCI: of: Create device tree PCI host bridge node") Cc: stable@vger.kernel.org Signed-off-by: Herve Codina Reviewed-by: Richard Cheng Acked-by: Manivannan Sadhasivam Reviewed-by: Bartosz Golaszewski --- drivers/pci/of.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/pci/of.c b/drivers/pci/of.c index 0f45c5b72458..29b63a9090ae 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -822,6 +822,7 @@ void of_pci_remove_host_bridge_node(struct pci_host_bridge *bridge) if (!np || !of_node_check_flag(np, OF_DYNAMIC)) return; + fw_devlink_set_device(&np->fwnode, NULL); device_remove_of_node(&bridge->bus->dev); device_remove_of_node(&bridge->dev); of_changeset_revert(np->data); @@ -887,7 +888,7 @@ void of_pci_make_host_bridge_node(struct pci_host_bridge *bridge) ret = of_changeset_apply(cset); if (ret) - goto out_free_node; + goto out_clear_devlink_dev; np->data = cset; @@ -909,6 +910,8 @@ void of_pci_make_host_bridge_node(struct pci_host_bridge *bridge) out_revert_cset: np->data = NULL; of_changeset_revert(cset); +out_clear_devlink_dev: + fw_devlink_set_device(&np->fwnode, NULL); out_free_node: of_node_put(np); out_destroy_cset: -- 2.55.0