Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp3003089lqt; Tue, 23 Apr 2024 07:57:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXH1OwyXykEgeumxhKHDZ4lu3YUvOxyPOXT/dmoGWOCoyfEwiiWOcRSxyqu3oVTECZuM/TtJWIcABwrHHIpBjHDLQEjO0+8JGOjOiYKCw== X-Google-Smtp-Source: AGHT+IHx4pi968QDj/YBlDibujh7sU/i54ByHK3uFpgF25rkzvLt+kh6ziGokWTjKlav7S+aIfjo X-Received: by 2002:a25:830d:0:b0:dc3:7041:b81b with SMTP id s13-20020a25830d000000b00dc37041b81bmr13506324ybk.36.1713884274944; Tue, 23 Apr 2024 07:57:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713884274; cv=pass; d=google.com; s=arc-20160816; b=lyn5OmYICZb8B8RS7v8fRqUw1GxJeuIJKqs8l7HGmeIodTEYYf8XxwvY+tg2PYDwSo SIfQ5T/IQClkHh/9QoWLEHcx7/2CqxqvdMHOj4/4ZHem0ULKGy7YrIaXR0iajQ97w6b7 hV1e3N5abSIh0v5VONeCUIBYt+8jq3E7wwJ8qeGKv4KryVf5CZsrIdkdnyxkCnM0TR8v X1KPVdFeveUMMCQ34y1wXwZZ3XOdLLcv7/lxibRi66592R8TCfj+cOqC2Xfv90Zmm4ly ma74IxJ0l+oyS3ZzgQAhvN2pKniaprZMG/u9DtlK1FHAmz6LVg+U8KU7zP274yeDSqAp UJjQ== 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=DJkxtHqhgZHsEW6tFHhsuGDRyY1D69IDz218tw2fS/g=; fh=jtCZ+nyqQSERrmggaaQZ5e/wVxSomMgCQ3miUDocXKU=; b=TZWgBBOZY10OHqk85bcVVjXmHUF+hkFzP2MiHB0rdvAJRjDubKDBUdOfuXkpSde4uw aepcfY7GS6npwr1LHihLejl06aqJmnTQZNjS6qdNMPLDtqzAMZ9wPI2pATjZE5rcLXkK AD3Crcd3s2LBSHfifkNEWFq87teEWbbZS2gSw+aXoQIpE1MBntwwBaaz4E72t8H2vbd7 qBSTi2KvNv39DCbohkwqKXIDdnpd28cREfL0m7xsN8QDH3Fxa9Z1gCJQs2GKZeiJiH4j WvFveLDK59PVqiJC3w1mnbcC8QuCBzLR+euIiZ2bGcqquET0icnlgnZzaous53TpYJhQ V0zg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=MeezJZrF; 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-155404-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155404-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 11-20020a0562140ccb00b0069b5996a2b2si13063254qvx.510.2024.04.23.07.57.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 07:57:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-155404-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=MeezJZrF; 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-155404-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155404-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 A7E911C21D9B for ; Tue, 23 Apr 2024 14:57:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0661613C69A; Tue, 23 Apr 2024 14:57:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="MeezJZrF" Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 C63A713B7AB; Tue, 23 Apr 2024 14:57:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713884242; cv=none; b=iVIEVTYBNpG0u2OCuF5UP9IybSgtEgHM+/QCaSXByLgCaYavH6GYZE1lldlUpF1VVsokJB73Jy8faFIYlqAJ5EQ38JJiI02YBz9KNJ8jkmxdGu4PaSML6C2IEQzcW7fPNtNvPR/9T+9NfFYpMSeljbob5VyiZYmwt8mcCgx7ie8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713884242; c=relaxed/simple; bh=6Sg7pfkwoCdHyxPYWfO/0nEXEYlUdqzDZq+0lCLAjXs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O/sSr13mOT6VvBNgIKDB4BnfCyFYfqHa+6CeP84lFY3J67XgMnKYfcymrXBqJgL5gv6iMuJZsUmw/OqFIgMWQs4ZOtQUl0lsVPeZKXKwBcFeaqKiKs/XA8yztmId4frMI7xGVRJkopbHI08ynNJolyL/Pa37J5FRFdcpw/xkaZU= 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=MeezJZrF; arc=none smtp.client-ip=217.70.183.200 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 045542000F; Tue, 23 Apr 2024 14:57:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1713884237; 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=DJkxtHqhgZHsEW6tFHhsuGDRyY1D69IDz218tw2fS/g=; b=MeezJZrFFkR3jPaPfy3EAOhU/EaTtkTNzT6dlO6ziw0NB/w+j2zvYx3B6HKfGWQIA2jX3L kM0xRVdCv/L3FYNkwuupfif6z8wY6B5RAacA2kLL6pU4OC2AbSXmvb/CjO+xeH1H1wc/4d 6PIc7zMMFnmQdznnU+isuuzSzlDcuNU6gC9/8p6A3zba+A7OqA0GGmNRdQDDbWbH1Xvkyc 7WcyBvlX4RCYKkjK7x991gFa6T4+vvoyBFPSpV1dExU9at8etWLvhvDVLteQAK9Pbl25sN dfTL94v2X92SbClMEM3OPuTWp4Ci7MpmJhjPtz2sUWy/h1O5CG+C/fQJDM54CA== 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 v4 2/2] PCI: of: Attach created of_node to existing device Date: Tue, 23 Apr 2024 16:56:59 +0200 Message-ID: <20240423145703.604489-3-herve.codina@bootlin.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423145703.604489-1-herve.codina@bootlin.com> References: <20240423145703.604489-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(). 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