From mboxrd@z Thu Jan 1 00:00:00 1970 From: Masahiro Yamada Date: Thu, 22 Jan 2015 19:25:17 +0900 Subject: [U-Boot] [PATCH v2 12/26] dm: core: Allow uclasses to specific the private data for a device's children In-Reply-To: <1421723575-4532-13-git-send-email-sjg@chromium.org> References: <1421723575-4532-1-git-send-email-sjg@chromium.org> <1421723575-4532-13-git-send-email-sjg@chromium.org> Message-ID: <20150122192516.199B.AA925319@jp.panasonic.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 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 > --- > > 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. Best Regards Masahiro Yamada