From patchwork Wed Jul 8 04:29:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 492713 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id B40C81402B8 for ; Wed, 8 Jul 2015 14:31:11 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2071B4B97D; Wed, 8 Jul 2015 06:31:04 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KiyLZf4LKBUU; Wed, 8 Jul 2015 06:31:04 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 330184B965; Wed, 8 Jul 2015 06:30:47 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7E4EF4B97A for ; Wed, 8 Jul 2015 06:30:36 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gooTi8HgUYdJ for ; Wed, 8 Jul 2015 06:30:36 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from conuserg010-v.nifty.com (conuserg010.nifty.com [202.248.44.36]) by theia.denx.de (Postfix) with ESMTPS id 0A5194B971 for ; Wed, 8 Jul 2015 06:30:34 +0200 (CEST) Received: from beagle.diag.org (KD111107182039.au-net.ne.jp [111.107.182.39]) (authenticated) by conuserg010-v.nifty.com with ESMTP id t684TmDq015410; Wed, 8 Jul 2015 13:30:07 +0900 X-Nifty-SrcIP: [111.107.182.39] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Wed, 8 Jul 2015 13:29:41 +0900 Message-Id: <1436329782-9179-12-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1436329782-9179-1-git-send-email-yamada.masahiro@socionext.com> References: <1436329782-9179-1-git-send-email-yamada.masahiro@socionext.com> Cc: Tom Rini Subject: [U-Boot] [RFC PATCH 11/12] dm: refactor device_probe() and device_remove() with devm_kzalloc() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The memory is automatically released on driver removal, so we do not need to do so explicitly in device_free(). The helper function alloc_priv() is no longer needed because devm_kzalloc() now understands the GFP_DMA flag. Signed-off-by: Masahiro Yamada Reviewed-by: Heiko Schocher --- drivers/core/device-remove.c | 23 ----------------------- drivers/core/device.c | 25 +++++++------------------ 2 files changed, 7 insertions(+), 41 deletions(-) diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c index 0417535..78551e4 100644 --- a/drivers/core/device-remove.c +++ b/drivers/core/device-remove.c @@ -111,29 +111,6 @@ int device_unbind(struct udevice *dev) */ void device_free(struct udevice *dev) { - int size; - - if (dev->driver->priv_auto_alloc_size) { - free(dev->priv); - dev->priv = NULL; - } - size = dev->uclass->uc_drv->per_device_auto_alloc_size; - if (size) { - free(dev->uclass_priv); - dev->uclass_priv = NULL; - } - 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; - } - } - devres_release_probe(dev); } diff --git a/drivers/core/device.c b/drivers/core/device.c index 25b9b63..e5291e2 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -179,27 +179,13 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, -1, devp); } -static void *alloc_priv(int size, uint flags) -{ - void *priv; - - if (flags & DM_FLAG_ALLOC_PRIV_DMA) { - priv = memalign(ARCH_DMA_MINALIGN, size); - if (priv) - memset(priv, '\0', size); - } else { - priv = calloc(1, size); - } - - return priv; -} - int device_probe_child(struct udevice *dev, void *parent_priv) { const struct driver *drv; int size = 0; int ret; int seq; + gfp_t flags = GFP_KERNEL; if (!dev) return -EINVAL; @@ -210,9 +196,12 @@ int device_probe_child(struct udevice *dev, void *parent_priv) drv = dev->driver; assert(drv); + if (drv->flags & DM_FLAG_ALLOC_PRIV_DMA) + flags |= GFP_DMA; + /* Allocate private data if requested */ if (drv->priv_auto_alloc_size) { - dev->priv = alloc_priv(drv->priv_auto_alloc_size, drv->flags); + dev->priv = devm_kzalloc(dev, drv->priv_auto_alloc_size, flags); if (!dev->priv) { ret = -ENOMEM; goto fail; @@ -221,7 +210,7 @@ int device_probe_child(struct udevice *dev, void *parent_priv) /* Allocate private data if requested */ size = dev->uclass->uc_drv->per_device_auto_alloc_size; if (size) { - dev->uclass_priv = calloc(1, size); + dev->uclass_priv = devm_kzalloc(dev, size, GFP_KERNEL); if (!dev->uclass_priv) { ret = -ENOMEM; goto fail; @@ -236,7 +225,7 @@ int device_probe_child(struct udevice *dev, void *parent_priv) per_child_auto_alloc_size; } if (size) { - dev->parent_priv = alloc_priv(size, drv->flags); + dev->parent_priv = devm_kzalloc(dev, size, flags); if (!dev->parent_priv) { ret = -ENOMEM; goto fail;