[PATCH v1 u-boot-marvell 4/5] arm64: mvebu: a37xx: add device-tree fixer for PCIe regions

Marek Behun marek.behun at nic.cz
Thu Apr 9 15:17:00 CEST 2020


> > +}
> > +
> > +int a3700_fdt_fix_pcie_regions(void *blob)
> > +{
> > +	u32 new_ranges[14], base;  
> 
> Where does this "14" come from? Is this a safe upper margin?

Yes, the way how the code below works, it won't overflow or anything.
I even test whether the "ranges" property from the dtc has the same
size, and if not, new_ranges is not written at all.

If the given device tree is changed somehow so that the ranges property
structure is changed, the problem it would cause is that the PCIe
driver won't work or it will cause segfaults or something (in U-Boot
and in Linux). But such change in device-tree would be incompatible with
Linux's driver anyway, so I don't think something like that will be
done.

> > +	const u32 *ranges;
> > +	int node, len;
> > +
> > +	node = fdt_path_offset(blob, PCIE_PATH);
> > +	if (node < 0)
> > +		return node;
> > +
> > +	ranges = fdt_getprop(blob, node, "ranges", &len);
> > +	if (!ranges)
> > +		return -ENOENT;
> > +
> > +	if (len != sizeof(new_ranges))
> > +		return -EINVAL;
> > +
> > +	memcpy(new_ranges, ranges, len);


More information about the U-Boot mailing list