Skip to content

Commit 5955239

Browse files
committed
Merge tag 'devicetree-fixes-for-6.13-2' of git://git.kernel.org/pub/scm/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
2 parents ed9add2 + 6e5773d commit 5955239

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

drivers/of/address.c

+15-3
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,15 @@ static int of_bus_default_flags_match(struct device_node *np)
340340
return of_property_present(np, "#address-cells") && (of_bus_n_addr_cells(np) == 3);
341341
}
342342

343+
static int of_bus_default_match(struct device_node *np)
344+
{
345+
/*
346+
* Check for presence first since of_bus_n_addr_cells() will warn when
347+
* walking parent nodes.
348+
*/
349+
return of_property_present(np, "#address-cells");
350+
}
351+
343352
/*
344353
* Array of bus specific translators
345354
*/
@@ -384,7 +393,7 @@ static const struct of_bus of_busses[] = {
384393
{
385394
.name = "default",
386395
.addresses = "reg",
387-
.match = NULL,
396+
.match = of_bus_default_match,
388397
.count_cells = of_bus_default_count_cells,
389398
.map = of_bus_default_map,
390399
.translate = of_bus_default_translate,
@@ -399,7 +408,6 @@ static const struct of_bus *of_match_bus(struct device_node *np)
399408
for (i = 0; i < ARRAY_SIZE(of_busses); i++)
400409
if (!of_busses[i].match || of_busses[i].match(np))
401410
return &of_busses[i];
402-
BUG();
403411
return NULL;
404412
}
405413

@@ -521,6 +529,8 @@ static u64 __of_translate_address(struct device_node *node,
521529
if (parent == NULL)
522530
return OF_BAD_ADDR;
523531
bus = of_match_bus(parent);
532+
if (!bus)
533+
return OF_BAD_ADDR;
524534

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

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

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

709721
/* Get "reg" or "assigned-addresses" property */

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

+13
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

+14
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)