Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit e7985f4

Browse files
Marc Zyngierrobherring
authored andcommitted
of: property: Fix fw_devlink handling of interrupt-map
Commit d976c6f ("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. Having 2 versions of parsing code for "interrupt-map" was a bad idea. Now that the common parsing parts have been refactored into of_irq_parse_imap_parent(), rework the code here to use it instead and fix the pointer arithmetic. Note that the dependency will be a bit different than the original code when the interrupt-map points to another interrupt-map. In this case, the original code would resolve to the final interrupt controller. Now the dependency is the parent interrupt-map (which itself should have a dependency to the parent). It is possible that a node with an interrupt-map has no driver. Fixes: d976c6f ("of: property: Add fw_devlink support for interrupt-map property") Signed-off-by: Marc Zyngier <maz@kernel.org> Co-developed-by: Rob Herring (Arm) <robh@kernel.org> Cc: Saravana Kannan <saravanak@google.com> Tested-by: Marc Zyngier <maz@kernel.org> Tested-by: Anup Patel <apatel@ventanamicro.com> Link: https://lore.kernel.org/r/20240529-dt-interrupt-map-fix-v2-2-ef86dc5bcd2a@kernel.org Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
1 parent 935df1b commit e7985f4

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

drivers/of/property.c

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,10 +1306,10 @@ static struct device_node *parse_interrupts(struct device_node *np,
13061306
static struct device_node *parse_interrupt_map(struct device_node *np,
13071307
const char *prop_name, int index)
13081308
{
1309-
const __be32 *imap, *imap_end, *addr;
1309+
const __be32 *imap, *imap_end;
13101310
struct of_phandle_args sup_args;
13111311
u32 addrcells, intcells;
1312-
int i, imaplen;
1312+
int imaplen;
13131313

13141314
if (!IS_ENABLED(CONFIG_OF_IRQ))
13151315
return NULL;
@@ -1322,33 +1322,23 @@ static struct device_node *parse_interrupt_map(struct device_node *np,
13221322
addrcells = of_bus_n_addr_cells(np);
13231323

13241324
imap = of_get_property(np, "interrupt-map", &imaplen);
1325-
if (!imap || imaplen <= (addrcells + intcells))
1325+
imaplen /= sizeof(*imap);
1326+
if (!imap)
13261327
return NULL;
1327-
imap_end = imap + imaplen;
13281328

1329-
while (imap < imap_end) {
1330-
addr = imap;
1331-
imap += addrcells;
1329+
imap_end = imap + imaplen;
13321330

1333-
sup_args.np = np;
1334-
sup_args.args_count = intcells;
1335-
for (i = 0; i < intcells; i++)
1336-
sup_args.args[i] = be32_to_cpu(imap[i]);
1337-
imap += intcells;
1331+
for (int i = 0; imap + addrcells + intcells + 1 < imap_end; i++) {
1332+
imap += addrcells + intcells;
13381333

1339-
/*
1340-
* Upon success, the function of_irq_parse_raw() returns
1341-
* interrupt controller DT node pointer in sup_args.np.
1342-
*/
1343-
if (of_irq_parse_raw(addr, &sup_args))
1334+
imap = of_irq_parse_imap_parent(imap, imap_end - imap, &sup_args);
1335+
if (!imap)
13441336
return NULL;
13451337

1346-
if (!index)
1338+
if (i == index)
13471339
return sup_args.np;
13481340

13491341
of_node_put(sup_args.np);
1350-
imap += sup_args.args_count + 1;
1351-
index--;
13521342
}
13531343

13541344
return NULL;

0 commit comments

Comments
 (0)