[PATCH 1/3] of: dynamic: add of_property_alloc() and of_property_free()
Clément Léger
clement.leger at bootlin.com
Fri May 6 17:49:05 AEST 2022
Le Thu, 5 May 2022 14:37:15 -0500,
Rob Herring <robh at kernel.org> a écrit :
> > +
> > +/**
> > + * of_property_alloc - Allocate a property dynamically.
> > + * @name: Name of the new property
> > + * @value: Value that will be copied into the new property value
> > + * @value_len: length of @value to be copied into the new property value
> > + * @len: Length of new property value, must be greater than @value_len
>
> What's the usecase for the lengths being different? That doesn't seem
> like a common case, so perhaps handle it with a NULL value and
> non-zero length. Then the caller has to deal with populating
> prop->value.
That was actually something used by powerpc code but agreed, letting
the user recopy it's values seems fine to me and the usage will be more
clear.
> > /*
> > - * NOTE: There is no check for zero length value.
> > - * In case of a boolean property, this will allocate a value
> > - * of zero bytes. We do this to work around the use
> > - * of of_get_property() calls on boolean values.
> > + * Even if the property has no value, it must be set to a
> > + * non-null value since of_get_property() is used to check
> > + * some values that might or not have a values (ranges for
> > + * instance). Moreover, when the node is released, prop->value
> > + * is kfreed so the memory must come from kmalloc.
>
> Allowing for NULL value didn't turn out well...
>
> We know that we can do the kfree because OF_DYNAMIC is set IIRC...
>
> If we do 1 allocation for prop and value, then we can test
> for "prop->value == prop + 1" to determine if we need to free or not.
Sounds like a good idea.
--
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
More information about the Linuxppc-dev
mailing list