Message ID | 20210505124917.20388-1-andre.przywara@arm.com |
---|---|
State | Changes Requested |
Delegated to: | Simon Glass |
Headers | show |
Series | common: fdt_support: Observe index in fdt_getprop_u32_default_node() | expand |
Hi Andre, On Wed, 5 May 2021 at 06:50, Andre Przywara <andre.przywara@arm.com> wrote: > > fdt_getprop_u32_default_node() promises to take the "cell" number into > account when returning the value of a property array. > > However it actually misses out on this, always returning the first cell > only instead. This was so far not a problem, since every user always > asks for cell 0. > > Observe the index value when accessing the property, and also fix the > parameter names to the more commonly used propname, offset and index > names, to improve readability of the function. > > Signed-off-by: Andre Przywara <andre.przywara@arm.com> > --- > common/fdt_support.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) Can you please add a test while you are here? Regards, Simon
diff --git a/common/fdt_support.c b/common/fdt_support.c index e624bbdf404..8dc45483f79 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -26,31 +26,31 @@ DECLARE_GLOBAL_DATA_PTR; * fdt_getprop_u32_default_node - Return a node's property or a default * * @fdt: ptr to device tree - * @off: offset of node - * @cell: cell offset in property - * @prop: property name + * @offset: offset of node + * @index: cell offset in property + * @propname: property name * @dflt: default value if the property isn't found * * Convenience function to return a node's property or a default value if * the property doesn't exist. */ -u32 fdt_getprop_u32_default_node(const void *fdt, int off, int cell, - const char *prop, const u32 dflt) +u32 fdt_getprop_u32_default_node(const void *fdt, int offset, int index, + const char *propname, const u32 dflt) { const fdt32_t *val; int len; - val = fdt_getprop(fdt, off, prop, &len); + val = fdt_getprop(fdt, offset, propname, &len); /* Check if property exists */ if (!val) return dflt; /* Check if property is long enough */ - if (len < ((cell + 1) * sizeof(uint32_t))) + if (len < ((index + 1) * sizeof(uint32_t))) return dflt; - return fdt32_to_cpu(*val); + return fdt32_to_cpu(val[index]); } /**
fdt_getprop_u32_default_node() promises to take the "cell" number into account when returning the value of a property array. However it actually misses out on this, always returning the first cell only instead. This was so far not a problem, since every user always asks for cell 0. Observe the index value when accessing the property, and also fix the parameter names to the more commonly used propname, offset and index names, to improve readability of the function. Signed-off-by: Andre Przywara <andre.przywara@arm.com> --- common/fdt_support.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)