Skip to content

Commit 4474806

Browse files
committed
of/unittest: Add test that of_address_to_resource() fails on non-translatable 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/[email protected] Signed-off-by: Rob Herring (Arm) <[email protected]>
1 parent 8600058 commit 4474806

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

drivers/of/unittest-data/tests-platform.dtsi

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,18 @@
3434
};
3535
};
3636
};
37+
38+
platform-tests-2 {
39+
// No #address-cells or #size-cells
40+
node {
41+
#address-cells = <1>;
42+
#size-cells = <1>;
43+
44+
test-device@100 {
45+
compatible = "test-sub-device";
46+
reg = <0x100 1>;
47+
};
48+
};
49+
};
3750
};
3851
};

drivers/of/unittest.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,7 @@ static void __init of_unittest_bus_3cell_ranges(void)
13801380
static void __init of_unittest_reg(void)
13811381
{
13821382
struct device_node *np;
1383+
struct resource res;
13831384
int ret;
13841385
u64 addr, size;
13851386

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

13981399
of_node_put(np);
1400+
1401+
np = of_find_node_by_path("/testcase-data/platform-tests-2/node/test-device@100");
1402+
if (!np) {
1403+
pr_err("missing testcase data\n");
1404+
return;
1405+
}
1406+
1407+
ret = of_address_to_resource(np, 0, &res);
1408+
unittest(ret == -EINVAL, "of_address_to_resource(%pOF) expected error on untranslatable address\n",
1409+
np);
1410+
1411+
of_node_put(np);
1412+
13991413
}
14001414

14011415
struct of_unittest_expected_res {

0 commit comments

Comments
 (0)