[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220506094905.27bc99aa@fixe.home>
Date: Fri, 6 May 2022 09:49:05 +0200
From: Clément Léger <clement.leger@...tlin.com>
To: Rob Herring <robh@...nel.org>
Cc: Michael Ellerman <mpe@...erman.id.au>,
Benjamin Herrenschmidt <benh@...nel.crashing.org>,
Paul Mackerras <paulus@...ba.org>,
Frank Rowand <frowand.list@...il.com>,
Nathan Lynch <nathanl@...ux.ibm.com>,
Laurent Dufour <ldufour@...ux.ibm.com>,
Daniel Henrique Barboza <danielhb413@...il.com>,
David Gibson <david@...son.dropbear.id.au>,
Andrew Morton <akpm@...ux-foundation.org>,
David Hildenbrand <david@...hat.com>,
Ohhoon Kwon <ohoono.kwon@...sung.com>,
"Aneesh Kumar K.V" <aneesh.kumar@...ux.ibm.com>,
YueHaibing <yuehaibing@...wei.com>,
linuxppc-dev@...ts.ozlabs.org, linux-kernel@...r.kernel.org,
devicetree@...r.kernel.org,
Allan Nielsen <allan.nielsen@...rochip.com>,
Horatiu Vultur <horatiu.vultur@...rochip.com>,
Steen Hegelund <steen.hegelund@...rochip.com>,
Thomas Petazzoni <thomas.petazzoni@...tlin.com>
Subject: Re: [PATCH 1/3] of: dynamic: add of_property_alloc() and
of_property_free()
Le Thu, 5 May 2022 14:37:15 -0500,
Rob Herring <robh@...nel.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
Powered by blists - more mailing lists