devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of: property: Fix fw_devlink handling of interrupt-map
@ 2024-05-28 16:41 Marc Zyngier
  2024-05-28 17:14 ` Rob Herring (Arm)
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Marc Zyngier @ 2024-05-28 16:41 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-arm-kernel, linux-riscv
  Cc: Anup Patel, Saravana Kannan, Rob Herring

Commit d976c6f4b32c ("of: property: Add fw_devlink support for
interrupt-map property") tried to do what it says on the tin,
but failed on a couple of points:

- it confuses bytes and cells. Not a huge deal, except when it
  comes to pointer arithmetic

- it doesn't really handle anything but interrupt-maps that have
  their parent #address-cells set to 0

The combinations of the two leads to some serious fun on my M1
box, with plenty of WARN-ON() firing all over the shop, and
amusing values being generated for interrupt specifiers.

Address both issues so that I can boot my machines again.

Fixes: d976c6f4b32c ("of: property: Add fw_devlink support for interrupt-map property")
Signed-off-by: Marc Zyngier <maz@kernel.org>
Cc: Anup Patel <apatel@ventanamicro.com>
Cc: Saravana Kannan <saravanak@google.com>
Cc: Rob Herring (Arm) <robh@kernel.org>
---
 drivers/of/property.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/of/property.c b/drivers/of/property.c
index 1c83e68f805b..9adebc63bea9 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -1322,7 +1322,13 @@ static struct device_node *parse_interrupt_map(struct device_node *np,
 	addrcells = of_bus_n_addr_cells(np);
 
 	imap = of_get_property(np, "interrupt-map", &imaplen);
-	if (!imap || imaplen <= (addrcells + intcells))
+	imaplen /= sizeof(*imap);
+
+	/*
+	 * Check that we have enough runway for the child unit interrupt
+	 * specifier and a phandle. That's the bare minimum we can expect.
+	 */
+	if (!imap || imaplen <= (addrcells + intcells + 1))
 		return NULL;
 	imap_end = imap + imaplen;
 
@@ -1346,8 +1352,14 @@ static struct device_node *parse_interrupt_map(struct device_node *np,
 		if (!index)
 			return sup_args.np;
 
-		of_node_put(sup_args.np);
+		/*
+		 * Account for the full parent unit interrupt specifier
+		 * (address cells, interrupt cells, and phandle).
+		 */
+		imap += of_bus_n_addr_cells(sup_args.np);
 		imap += sup_args.args_count + 1;
+
+		of_node_put(sup_args.np);
 		index--;
 	}
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2024-05-29 16:47 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-28 16:41 [PATCH] of: property: Fix fw_devlink handling of interrupt-map Marc Zyngier
2024-05-28 17:14 ` Rob Herring (Arm)
2024-05-28 17:23 ` Saravana Kannan
2024-05-29  5:15 ` Anup Patel
2024-05-29  6:33   ` Marc Zyngier
2024-05-29 10:16     ` Anup Patel
2024-05-29 10:44       ` Marc Zyngier
2024-05-29 11:28         ` Anup Patel
2024-05-29 12:00           ` Marc Zyngier
2024-05-29 15:17             ` Conor Dooley
2024-05-29 16:37               ` Anup Patel
2024-05-29 13:51           ` Rob Herring
2024-05-29 16:46             ` Rob Herring
2024-05-29 13:44     ` Rob Herring
2024-05-29 14:00       ` Marc Zyngier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).