Skip to content

Commit

Permalink
Merge tag 'devicetree-fixes-for-6.13-2' of git://git.kernel.org/pub/s…
Browse files Browse the repository at this point in the history
…cm/linux/kernel/git/robh/linux

Pull devicetree fixes from Rob Herring:
 "Another fix and testcase to avoid the newly added WARN in the case of
  non-translatable addresses"

* tag 'devicetree-fixes-for-6.13-2' of git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux:
  of/address: Fix WARN when attempting translating non-translatable addresses
  of/unittest: Add test that of_address_to_resource() fails on non-translatable address
  • Loading branch information
Linus Torvalds committed Jan 17, 2025
2 parents ed9add2 + 6e5773d commit 5955239
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
18 changes: 15 additions & 3 deletions drivers/of/address.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,15 @@ static int of_bus_default_flags_match(struct device_node *np)
return of_property_present(np, "#address-cells") && (of_bus_n_addr_cells(np) == 3);
}

static int of_bus_default_match(struct device_node *np)
{
/*
* Check for presence first since of_bus_n_addr_cells() will warn when
* walking parent nodes.
*/
return of_property_present(np, "#address-cells");
}

/*
* Array of bus specific translators
*/
Expand Down Expand Up @@ -384,7 +393,7 @@ static const struct of_bus of_busses[] = {
{
.name = "default",
.addresses = "reg",
.match = NULL,
.match = of_bus_default_match,
.count_cells = of_bus_default_count_cells,
.map = of_bus_default_map,
.translate = of_bus_default_translate,
Expand All @@ -399,7 +408,6 @@ static const struct of_bus *of_match_bus(struct device_node *np)
for (i = 0; i < ARRAY_SIZE(of_busses); i++)
if (!of_busses[i].match || of_busses[i].match(np))
return &of_busses[i];
BUG();
return NULL;
}

Expand Down Expand Up @@ -521,6 +529,8 @@ static u64 __of_translate_address(struct device_node *node,
if (parent == NULL)
return OF_BAD_ADDR;
bus = of_match_bus(parent);
if (!bus)
return OF_BAD_ADDR;

/* Count address cells & copy address locally */
bus->count_cells(dev, &na, &ns);
Expand Down Expand Up @@ -564,6 +574,8 @@ static u64 __of_translate_address(struct device_node *node,

/* Get new parent bus and counts */
pbus = of_match_bus(parent);
if (!pbus)
return OF_BAD_ADDR;
pbus->count_cells(dev, &pna, &pns);
if (!OF_CHECK_COUNTS(pna, pns)) {
pr_err("Bad cell count for %pOF\n", dev);
Expand Down Expand Up @@ -703,7 +715,7 @@ const __be32 *__of_get_address(struct device_node *dev, int index, int bar_no,

/* match the parent's bus type */
bus = of_match_bus(parent);
if (strcmp(bus->name, "pci") && (bar_no >= 0))
if (!bus || (strcmp(bus->name, "pci") && (bar_no >= 0)))
return NULL;

/* Get "reg" or "assigned-addresses" property */
Expand Down
13 changes: 13 additions & 0 deletions drivers/of/unittest-data/tests-platform.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,18 @@
};
};
};

platform-tests-2 {
// No #address-cells or #size-cells
node {
#address-cells = <1>;
#size-cells = <1>;

test-device@100 {
compatible = "test-sub-device";
reg = <0x100 1>;
};
};
};
};
};
14 changes: 14 additions & 0 deletions drivers/of/unittest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,7 @@ static void __init of_unittest_bus_3cell_ranges(void)
static void __init of_unittest_reg(void)
{
struct device_node *np;
struct resource res;
int ret;
u64 addr, size;

Expand All @@ -1396,6 +1397,19 @@ static void __init of_unittest_reg(void)
np, addr);

of_node_put(np);

np = of_find_node_by_path("/testcase-data/platform-tests-2/node/test-device@100");
if (!np) {
pr_err("missing testcase data\n");
return;
}

ret = of_address_to_resource(np, 0, &res);
unittest(ret == -EINVAL, "of_address_to_resource(%pOF) expected error on untranslatable address\n",
np);

of_node_put(np);

}

struct of_unittest_expected_res {
Expand Down

0 comments on commit 5955239

Please sign in to comment.