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 7A1E742BC5B for ; Fri, 17 Jul 2026 14:52:57 +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=1784299982; cv=none; b=HqjpO8iqJbfIKlQtSDzC1bqW2IT83l0Yr28gxaV4qAABDipaRjh3zdm+Lhx6OaHgkMfhqhPghOFLPIXRzMh1J4sIaVVcisJlQWFv3eLxXDSG/KYedPx4qg4FECS3YVVLIx4nH/8Gvh59KHmV/XWFGHTqDKJQEZCuQwnLvXjqN/I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784299982; c=relaxed/simple; bh=tMsAVTi1Rho91NEqC+ysbz1hNyCDo4aBmOV0Y/x8Dvk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jig+rINnXScIXvrKxN+S95NdEZkBDxV16RFOwtCQkWtPkLhUdAfVnWt8FBuyS7oB77uuLlizyeCJu1ad4JeD91MAHfMeIm4KxuhRMP1GydkQl0Eyq68cKZCsGb/cRaxlkTcHDkhmQ+JLZ+MFmF/3NoqDKEb22e2RK/QEf0E/vxo= 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=0QiGp+KZ; 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="0QiGp+KZ" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 4CB784E40E1E; Fri, 17 Jul 2026 14:52:52 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 1CB3B60361; Fri, 17 Jul 2026 14:52:52 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 0974A11BD02F3; Fri, 17 Jul 2026 16:52:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1784299969; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=Qub0IEg5WmezvrGOXg10l3doEL53dANVAc5npPWax8c=; b=0QiGp+KZuEx/2sHroWQLoZWUrzhjC9CQJNfKqhkg3J03DtR2WqWX9t3bf5SMeQfnSy2yzA 4OuXVzZI3uds5zyzbKcWjrvHedNFeicQHyL0YRw+OmWwiWw3OCF3vUL8C7kaZ7GJZkpQYl EDcvZ8KQbfVx2kEC2we8aBYW5F7Kyp6J0wawVRBqiDEo7DLxZh0LGxA41X87DfOp2yuSS/ 1mJvXGtIMEojv+fFTCQ/eC2gpHqwXTzlh+9eDmEU5geZ7qWYgVCOPAPUd8BOD57AtqnZpx G6dt/q+OgSNFlglHkoVaYkVZjf5hIchQo0mKfkMGy0s29rmn9bru1oCD6l1gxg== From: Herve Codina To: Richard Cheng , Andrew Lunn , Rob Herring , Saravana Kannan , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Bjorn Helgaas , David Rhodes , Richard Fitzgerald , Charles Keepax , Linus Walleij , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Dan Williams , Ira Weiny , Li Ming , Lizhi Hou , Herve Codina 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 Subject: [PATCH v10 07/10] PCI: of: Clear fwnode->dev during root bridge node removal and error path Date: Fri, 17 Jul 2026 16:51:42 +0200 Message-ID: <20260717145147.823749-8-herve.codina@bootlin.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260717145147.823749-1-herve.codina@bootlin.com> References: <20260717145147.823749-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-gpio@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 --- 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 ee9eb384b377..6a533f9bbf3c 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -743,6 +743,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); @@ -808,7 +809,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; @@ -830,6 +831,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