From nobody Mon Feb 9 06:25:40 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.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 14DB726F292; Fri, 17 Oct 2025 08:48:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760690901; cv=none; b=ZwSLv+7oOJk99a7uR8zJsKVFrknOW4QGs/Vauuo7YGP8GpkGwGC+38VA13cXQ7/hgbegOrmAwtqgL4MAAw4PRopmIzDJpSns9dewcAJ9AVrLDmx9RWY8R2/7UhFFyeZ9ZSu2TTUACvpTC1UFsjOzmhHQ4MpcYsEh0TzMVocxLck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760690901; c=relaxed/simple; bh=RVkyfa65ji+iVeG5m+BwMXCO2f+xUvygzZyer4ipAO8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MbAsEUAz8rNCrZDxNARqHw3U+f1LrZ+QvsxJ54x4Y0+Nma0vQukcO7Y0fuQhPAAmgtjCtWPV4OTLZ0GLow7kLiA/rKPahB7PgCfY1dtOwPBJK/IHuqh2N7hR0p5nOWJ4Au+C0mFyZi+WvSA4OOygjyi0bzBm47LnnGebpyo7ldA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Iwe0TBnp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Iwe0TBnp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC231C4CEE7; Fri, 17 Oct 2025 08:48:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760690900; bh=RVkyfa65ji+iVeG5m+BwMXCO2f+xUvygzZyer4ipAO8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Iwe0TBnpFzClt9Y20jsB2ePw+lmYNVEtgobf2uCd312bcIBSiTLvmqB/vK58wjCg7 Br8cEfkG6bbncGNfesJ5W91OmPOwRWmFvs04zN7PSjoqrvJsqXTJukcFan1g4IwhEZ jidHTOVTykUEe5TYltVzRTC07oxAsXm7vVk05eo84HxModSdqO8TrNr7gvz6P7u2aO CWEWQcvakcB4jIyvWtlrvBPrlZoCU6xTminoCCqSqphTFH83rFesouhB9DODt1Hfim MYc/Kiq60SPXBrXU49Wte2OqeH9t0bIvd2nCiOJbqo+q1QnpNuopvT2nlhWkgCE0BI BYIJrfhLwtHvQ== From: Lorenzo Pieralisi To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, devicetree@vger.kernel.org, Sascha Bischoff , Thomas Gleixner , Rob Herring , Frank Li , Marc Zyngier , Scott Branden , Bjorn Helgaas , Ray Jui , Manivannan Sadhasivam , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= Subject: [PATCH v3 5/5] irqchip/gic-its: Rework platform MSI deviceID detection Date: Fri, 17 Oct 2025 10:47:52 +0200 Message-ID: <20251017084752.1590264-6-lpieralisi@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251017084752.1590264-1-lpieralisi@kernel.org> References: <20251017084752.1590264-1-lpieralisi@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Current code retrieving platform devices MSI devID in the GIC ITS MSI parent helpers suffers from some minor issues: - It leaks a struct device_node reference - It is duplicated between GICv3 and GICv5 for no good reason - It does not use the OF phandle iterator code that simplifies the msi-parent property parsing Consolidate GIC v3 and v5 deviceID retrieval in a function that addresses the full set of issues in one go by merging GIC v3 and v5 code and converting the msi-parent parsing loop to the more modern OF phandle iterator API, fixing the struct device_node reference leak in the process. Signed-off-by: Lorenzo Pieralisi Cc: Sascha Bischoff Cc: Thomas Gleixner Cc: Rob Herring Cc: Frank Li Cc: Marc Zyngier --- drivers/irqchip/irq-gic-its-msi-parent.c | 91 ++++++------------------ 1 file changed, 23 insertions(+), 68 deletions(-) diff --git a/drivers/irqchip/irq-gic-its-msi-parent.c b/drivers/irqchip/irq= -gic-its-msi-parent.c index eb1473f1448a..12f45228c867 100644 --- a/drivers/irqchip/irq-gic-its-msi-parent.c +++ b/drivers/irqchip/irq-gic-its-msi-parent.c @@ -142,83 +142,38 @@ static int its_v5_pci_msi_prepare(struct irq_domain *= domain, struct device *dev, #define its_v5_pci_msi_prepare NULL #endif /* !CONFIG_PCI_MSI */ =20 -static int of_pmsi_get_dev_id(struct irq_domain *domain, struct device *de= v, - u32 *dev_id) +static int of_pmsi_get_msi_info(struct irq_domain *domain, struct device *= dev, u32 *dev_id, + phys_addr_t *pa) { - int ret, index =3D 0; + struct of_phandle_iterator it; + int ret; =20 /* Suck the DeviceID out of the msi-parent property */ - do { - struct of_phandle_args args; + of_for_each_phandle(&it, ret, dev->of_node, "msi-parent", "#msi-cells", -= 1) { + /* GICv5 ITS domain matches the MSI controller node parent */ + struct device_node *np __free(device_node) =3D pa ? of_get_parent(it.nod= e) + : of_node_get(it.node); =20 - ret =3D of_parse_phandle_with_args(dev->of_node, - "msi-parent", "#msi-cells", - index, &args); - if (args.np =3D=3D irq_domain_get_of_node(domain)) { - if (WARN_ON(args.args_count !=3D 1)) - return -EINVAL; - *dev_id =3D args.args[0]; - break; - } - index++; - } while (!ret); + if (np =3D=3D irq_domain_get_of_node(domain)) { + u32 args; =20 - if (ret) { - struct device_node *np =3D NULL; + if (WARN_ON(of_phandle_iterator_args(&it, &args, 1) !=3D 1)) + ret =3D -EINVAL; =20 - ret =3D of_map_id(dev->of_node, dev->id, "msi-map", "msi-map-mask", &np,= dev_id); - if (np) - of_node_put(np); - } + if (!ret && pa) + ret =3D its_translate_frame_address(it.node, pa); =20 - return ret; -} + if (!ret) + *dev_id =3D args; =20 -static int of_v5_pmsi_get_msi_info(struct irq_domain *domain, struct devic= e *dev, - u32 *dev_id, phys_addr_t *pa) -{ - int ret, index =3D 0; - /* - * Retrieve the DeviceID and the ITS translate frame node pointer - * out of the msi-parent property. - */ - do { - struct of_phandle_args args; - - ret =3D of_parse_phandle_with_args(dev->of_node, - "msi-parent", "#msi-cells", - index, &args); - if (ret) - break; - /* - * The IRQ domain fwnode is the msi controller parent - * in GICv5 (where the msi controller nodes are the - * ITS translate frames). - */ - if (args.np->parent =3D=3D irq_domain_get_of_node(domain)) { - if (WARN_ON(args.args_count !=3D 1)) - return -EINVAL; - *dev_id =3D args.args[0]; - - ret =3D its_translate_frame_address(args.np, pa); - if (ret) - return -ENODEV; - break; - } - index++; - } while (!ret); - - if (ret) { - struct device_node *np =3D NULL; - - ret =3D of_map_id(dev->of_node, dev->id, "msi-map", "msi-map-mask", &np,= dev_id); - if (np) { - ret =3D its_translate_frame_address(np, pa); - of_node_put(np); + of_node_put(it.node); + return ret; } } =20 - return ret; + struct device_node *msi_ctrl __free(device_node) =3D NULL; + + return of_map_id(dev->of_node, dev->id, "msi-map", "msi-map-mask", &msi_c= trl, dev_id); } =20 int __weak iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id) @@ -234,7 +189,7 @@ static int its_pmsi_prepare(struct irq_domain *domain, = struct device *dev, int ret; =20 if (dev->of_node) - ret =3D of_pmsi_get_dev_id(domain->parent, dev, &dev_id); + ret =3D of_pmsi_get_msi_info(domain->parent, dev, &dev_id, NULL); else ret =3D iort_pmsi_get_dev_id(dev, &dev_id); if (ret) @@ -262,7 +217,7 @@ static int its_v5_pmsi_prepare(struct irq_domain *domai= n, struct device *dev, if (!dev->of_node) return -ENODEV; =20 - ret =3D of_v5_pmsi_get_msi_info(domain->parent, dev, &dev_id, &pa); + ret =3D of_pmsi_get_msi_info(domain->parent, dev, &dev_id, &pa); if (ret) return ret; =20 --=20 2.50.1