Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2823557lqp; Mon, 25 Mar 2024 10:09:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW+LNQzB7UUMtVcdrMJZrofnjI2K2LPVvZ2Czs8kYjCExumt3eiok8n2WSZBfGK3CvTYo87jDl9ZfqwL0vZ1dyjTFxz1537osgDCIUy/Q== X-Google-Smtp-Source: AGHT+IHu0RfU2kHFHg9519HYw+QPkwaPAbq0ZtwviiC2mUJwssD4kTuv6WsQIGby0R8L+rCaJLBl X-Received: by 2002:a05:6122:32c7:b0:4d4:3fc:2869 with SMTP id ck7-20020a05612232c700b004d403fc2869mr5220315vkb.15.1711386589078; Mon, 25 Mar 2024 10:09:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711386589; cv=pass; d=google.com; s=arc-20160816; b=D2bnUnxN2FPjpl+2AmY5m0ApzPqFU9jI+wODdEbjDhb6RunTfTOQpqKsA+xvo9rsq2 YidZleCT6PajPN9oFCqv/w9IupBMyG4OkALCTCxkKLS1XGJqxj4Ritzy+eZcQFN3ZmIo n272U3oqbMHuNQ3hszjO576pXBWyqQ8d7sGMZj/8jeChD0UchJ2qkRrxYCOeBLlSrRXr T6m6TF9SS/P6Y/YVB8rTBUWAL3SlEbEsw9bN+h1sP1eNUhTGIUcWAfyzbpjGTLXG75cZ PN3qLGKc8buDQo+huEddMHSo2tZASQM9vfBz0GfCcVpr98EjDnQbsumJ5lCdOQa5SEz+ VY4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=d4Y4TNaj1xi0aYzulhoQsLssE442tEhfmgHSUvRZqvI=; fh=jtCZ+nyqQSERrmggaaQZ5e/wVxSomMgCQ3miUDocXKU=; b=d6aI40jbnGQtLIB042tg4tJ9Q5QfcVhIRQXs3V1CR69iJLEHy+AyX4fP8cTCsg5Ura rQEuwnDsyk/Him9DHcjW35OYHsWHfZs/9oxyBJl7EIugAnUxyQXgxrdknrkRkIq7NX1p II7Fahp+ru+t3Y6JDb8xDoi1dPnuVjjz2rL3XRyzz+ykvGnp2MciIFJhY5KPCMGwvbTc uDgerm51BazICIBd8MFelyGr/Ajshzu+r+d+eDuNU7AqQGHRcHCZZ3C5E4sWA7x7Srwq eRIVgfdsmrvAgUELfZHnBi4IWjRYZyLe/6Yzu6UE5TPHyKuScveg7fsL2EGycXuu+3Cv tvcQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=K9UQGaXS; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-117397-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117397-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ds28-20020a05612225fc00b004d8719a7c73si929647vkb.169.2024.03.25.10.09.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 10:09:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117397-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=K9UQGaXS; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-117397-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117397-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C48381C32C3A for ; Mon, 25 Mar 2024 17:09:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6D22014C593; Mon, 25 Mar 2024 15:39:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="K9UQGaXS" Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 53F50745C2; Mon, 25 Mar 2024 15:39:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711381176; cv=none; b=sPB4EdEXtWpKszhpM3XV1cSa5uQ+Adj+lBSH1dG2x/eroO6xyldVpFuUOwwRUaxOaHmpYPqKDZ+mICvVLNNy0JwjwEJCmSI1X/MkDd6BANsonluNjRtos19vx9uvnYC/jEjNwhD03V0BON8EjFG+xyhxl2/BEWouhyAPOpjBTNQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711381176; c=relaxed/simple; bh=x9wwd1SZ4t/1SiLNINI5SYgdvu+Rc2H7HPms0m8bZsI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LtrozjXbMMYjgQ2Djf0ZFdf9/SI8X34YvFNsQVLkJC6Rir4C8RQ4XYNbN7tj5yjZIeWHPkXlFi1WE5TuqYe2xZpC+MZ97EdYswBOc+IPDtIGNeaXMMM6NmOwvCVNSnePctyCqrjMltL61AoHtT3HXSadzQ0y1ysfoNdyq3UhBEw= 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=K9UQGaXS; arc=none smtp.client-ip=217.70.183.201 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 Received: by mail.gandi.net (Postfix) with ESMTPA id C890E1BF207; Mon, 25 Mar 2024 15:39:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1711381172; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d4Y4TNaj1xi0aYzulhoQsLssE442tEhfmgHSUvRZqvI=; b=K9UQGaXS/zZtuoKlZI3CPRw8oAWdiSpcetOjfqb2b772p7/pOVch9Djb/qlCAM7zsPboBO vbPGrXZKJ+gdYp0XEI/1gCFgofEFauVfu2uXCJeEqZamrK7BRurVlXnkkqFaS3t5Ut815y iadbhPWT9YJBhfI07fkyipsKdCPqnwmZ2Us+457HyaxLHPxA2oBTc6Gq1bLA50M8GahN7l Gc2gShgKwWbYKNCf3eu9LNEBzks+jjfZmSaOywqHNbSjSJIInwaIM0b4k6Wq+1SAWYvvpy tOiX1s5ZHsYL+hpE+0CcP93lvQ8XjfSN0/N7+XBPovneR1CH4a1GtHmFllKW6g== From: Herve Codina To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Bjorn Helgaas , Lizhi Hou , Rob Herring Cc: Max Zhen , Sonal Santan , Stefano Stabellini , Jonathan Cameron , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Allan Nielsen , Horatiu Vultur , Steen Hegelund , Thomas Petazzoni , Herve Codina , stable@vger.kernel.org Subject: [PATCH v3 2/2] PCI: of: Attach created of_node to existing device Date: Mon, 25 Mar 2024 16:39:15 +0100 Message-ID: <20240325153919.199337-3-herve.codina@bootlin.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240325153919.199337-1-herve.codina@bootlin.com> References: <20240325153919.199337-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-GND-Sasl: herve.codina@bootlin.com The commit 407d1a51921e ("PCI: Create device tree node for bridge") creates of_node for PCI devices. During the insertion handling of these new DT nodes done by of_platform, new devices (struct device) are created. For each PCI devices a struct device is already present (created and handled by the PCI core). Having a second struct device to represent the exact same PCI device is not correct. On the of_node creation: - tell the of_platform that there is no need to create a device for this node (OF_POPULATED flag), - link this newly created of_node to the already present device, - tell fwnode that the device attached to this of_node is ready using fwnode_dev_initialized(). With this fix, the of_node are available in the sysfs device tree: /sys/devices/platform/soc/d0070000.pcie/ + of_node -> .../devicetree/base/soc/pcie@d0070000 + pci0000:00 + 0000:00:00.0 + of_node -> .../devicetree/base/soc/pcie@d0070000/pci@0,0 + 0000:01:00.0 + of_node -> .../devicetree/base/soc/pcie@d0070000/pci@0,0/dev@0,0 On the of_node removal, revert the operations. Fixes: 407d1a51921e ("PCI: Create device tree node for bridge") Cc: stable@vger.kernel.org Signed-off-by: Herve Codina --- drivers/pci/of.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/pci/of.c b/drivers/pci/of.c index 51e3dd0ea5ab..5afd2731e876 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -615,7 +615,8 @@ void of_pci_remove_node(struct pci_dev *pdev) np = pci_device_to_OF_node(pdev); if (!np || !of_node_check_flag(np, OF_DYNAMIC)) return; - pdev->dev.of_node = NULL; + + device_remove_of_node(&pdev->dev); of_changeset_revert(np->data); of_changeset_destroy(np->data); @@ -668,12 +669,22 @@ void of_pci_make_dev_node(struct pci_dev *pdev) if (ret) goto out_free_node; + /* + * This of_node will be added to an existing device. + * Avoid any device creation and use the existing device + */ + of_node_set_flag(np, OF_POPULATED); + np->fwnode.dev = &pdev->dev; + fwnode_dev_initialized(&np->fwnode, true); + ret = of_changeset_apply(cset); if (ret) goto out_free_node; np->data = cset; - pdev->dev.of_node = np; + + /* Add the of_node to the existing device */ + device_add_of_node(&pdev->dev, np); kfree(name); return; -- 2.44.0