[U-Boot] [PATCH v2 12/26] dm: core: Allow uclasses to specific the private data for a device's children
Simon Glass
sjg at chromium.org
Thu Jan 22 15:58:05 CET 2015
On 22 January 2015 at 03:25, Masahiro Yamada <yamada.m at jp.panasonic.com> wrote:
> Hi Simon,
>
>
>
> Perhaps a typo in this subject, too
>
> dm: core: Allow uclasses to specific the private data for a device's children
>
> s/to specific/to specify/ ??
>
>
> On Mon, 19 Jan 2015 20:12:41 -0700
> Simon Glass <sjg at chromium.org> wrote:
>
>> In many cases the per-child private data for a device's children is defined
>> by the uclass rather than the individual driver. For example, a SPI bus
>> needs to store information about each of its children, but all SPI drivers
>> store the same information. It makes sense to allow the uclass to define
>> this data.
>>
>> If the driver provides a size value for its per-child private data, then use
>> it. Failng that, fall back to that provided by the uclass.
>>
>> Signed-off-by: Simon Glass <sjg at chromium.org>
>> ---
>>
>> Changes in v2: None
>>
>> drivers/core/device-remove.c | 4 ++++
>> drivers/core/device.c | 4 ++++
>> include/dm/uclass.h | 4 ++++
>> test/dm/bus.c | 31 +++++++++++++++++++++++++++++--
>> 4 files changed, 41 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c
>> index 56c358a..3a5f48d 100644
>> --- a/drivers/core/device-remove.c
>> +++ b/drivers/core/device-remove.c
>> @@ -126,6 +126,10 @@ void device_free(struct udevice *dev)
>> }
>> if (dev->parent) {
>> size = dev->parent->driver->per_child_auto_alloc_size;
>> + if (!size) {
>> + size = dev->parent->uclass->uc_drv->
>> + per_child_auto_alloc_size;
>> + }
>> if (size) {
>> free(dev->parent_priv);
>> dev->parent_priv = NULL;
>
>
> Hmm, do we need to check the per_child_auto_alloc_size?
> Is it better and simpler to check dev->parent_priv like this?
>
> if (dev->parent && !dev->parent_priv) {
> free(dev->parent_priv);
> dev->parent_priv = NULL;
> }
>
> Or further more simpily
>
> if (dev->parent) {
> free(dev->parent_priv);
> dev->parent_priv = NULL;
> }
>
> When free() is given with NULL pointer, it returns without doing anything,
> I think.
It is possible that the driver will allocate this memory itself, so in
that case we should not free it. The driver is responsible for that.
- Simon
More information about the U-Boot
mailing list