Skip to content

Commit 746c9e9

Browse files
ozbenhrobherring
authored andcommitted
of/base: Fix PowerPC address parsing hack
We have a historical hack that treats missing ranges properties as the equivalent of an empty one. This is needed for ancient PowerMac "bad" device-trees, and shouldn't be enabled for any other PowerPC platform, otherwise we get some nasty layout of devices in sysfs or even duplication when a set of otherwise identically named devices is created multiple times under a different parent node with no ranges property. This fix is needed for the PowerNV i2c busses to be exposed properly and will fix a number of other embedded cases. Signed-off-by: Benjamin Herrenschmidt <[email protected]> CC: <[email protected]> Acked-by: Grant Likely <[email protected]> Signed-off-by: Rob Herring <[email protected]>
1 parent 9b6eab0 commit 746c9e9

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

drivers/of/address.c

+16-3
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,21 @@ static struct of_bus *of_match_bus(struct device_node *np)
450450
return NULL;
451451
}
452452

453+
static int of_empty_ranges_quirk(void)
454+
{
455+
if (IS_ENABLED(CONFIG_PPC)) {
456+
/* To save cycles, we cache the result */
457+
static int quirk_state = -1;
458+
459+
if (quirk_state < 0)
460+
quirk_state =
461+
of_machine_is_compatible("Power Macintosh") ||
462+
of_machine_is_compatible("MacRISC");
463+
return quirk_state;
464+
}
465+
return false;
466+
}
467+
453468
static int of_translate_one(struct device_node *parent, struct of_bus *bus,
454469
struct of_bus *pbus, __be32 *addr,
455470
int na, int ns, int pna, const char *rprop)
@@ -475,12 +490,10 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus,
475490
* This code is only enabled on powerpc. --gcl
476491
*/
477492
ranges = of_get_property(parent, rprop, &rlen);
478-
#if !defined(CONFIG_PPC)
479-
if (ranges == NULL) {
493+
if (ranges == NULL && !of_empty_ranges_quirk()) {
480494
pr_err("OF: no ranges; cannot translate\n");
481495
return 1;
482496
}
483-
#endif /* !defined(CONFIG_PPC) */
484497
if (ranges == NULL || rlen == 0) {
485498
offset = of_read_number(addr, na);
486499
memset(addr, 0, pna * 4);

0 commit comments

Comments
 (0)