From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.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 033DF390C85; Wed, 8 Jul 2026 10:05:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783505102; cv=none; b=eTUHx7zyEgrKT81yfYZgLxGJq/mlmVOtfi4LuX4/4I7T7u69s0sPiR9a2fIz7KfnXtRB0Hh0KHU/QxcgagtEp3L8dploHiD/ymj0xRrx2VVAs9B0qv2X3U0f8QvtxSdmk6KL6L29jTwkqYepnYYriVfSmGXCp/ePBv9MsEF3Yis= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783505102; c=relaxed/simple; bh=eUh+5UzkPAkfltHyU1QGS+i+4QgZNpJJd4qiosfXErA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g5BdMOJ7pr5KnAzpbXPpND66Swya5ae6QqfX6czkDCMcOX5qsroBNSEVOLnR493NQAmRhSowYSDX/oKDvhN1popjoLMQWGT6bpeACIc7AT065YHpHiS1idgL1/yGsGsUsvCsJXjIdJ05ML9xYzLEM6MqD9q/iF9HxNwahfC4eDw= 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=If5RS9o7; arc=none smtp.client-ip=185.246.84.56 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="If5RS9o7" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id DECA11A0EDA; Wed, 8 Jul 2026 10:04:59 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id B019260337; Wed, 8 Jul 2026 10:04:59 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 39DE611BC340C; Wed, 8 Jul 2026 12:04:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1783505097; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=E+KjPslG8Yq6DlZpnY2eoa5wVJm9c3ayc/UZANasGp8=; b=If5RS9o7JNDODqDsh/6bZ5BjqoCHD5VdxUloPTNoe1aXK1WxB+uue9+c1uhRt1Ew+ncd4K 878mMjPCPv2mz69O+h28+mmNBVnz8zJBllGxpHdOh09Y/1Nu7uAnFSiWVEpfzuTKyfwv/W 0S9zomQV0Ttzy4Dlt0/+ZNUy5N+mDMzrCcR+Wpd1YglOQvtcmnYEN50QM8b0AmwonNE2B6 xg29JLex4dHJNqz+ls4geoUtev7vvY6xmnL3lztCkWyOHP+/lU9wudmpz+Mkgs0FCpyvWA ZAjnwBli2VnnMSeASclSjxBAxDwAakb98+hxWb2VeT48kGN6PIuhqS81qcOA2A== 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 v9 7/9] PCI: of: Clear fwnode->dev during root bridge node removal Date: Wed, 8 Jul 2026 12:02:57 +0200 Message-ID: <20260708100302.517792-8-herve.codina@bootlin.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260708100302.517792-1-herve.codina@bootlin.com> References: <20260708100302.517792-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. Avoid this dangling fwnode->dev pointer by clearing it in of_pci_remove_host_bridge_node(). 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 | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/pci/of.c b/drivers/pci/of.c index ee9eb384b377..8dd558a490bb 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); -- 2.54.0