Skip to content

Commit

Permalink
of/unittest: Add test that of_address_to_resource() fails on non-tran…
Browse files Browse the repository at this point in the history
…slatable address

of_address_to_resource() on a non-translatable address should return an
error. Additionally, this case also triggers a spurious WARN for
missing #address-cells/#size-cells.

Link: https://lore.kernel.org/r/20250110215030.3637845-1-robh@kernel.org
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
  • Loading branch information
Rob Herring (Arm) committed Jan 12, 2025
1 parent 8600058 commit 4474806
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
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 4474806

Please sign in to comment.