public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Heiko Schocher <hs@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC PATCH 11/12] dm: refactor device_probe() and device_remove() with devm_kzalloc()
Date: Wed, 08 Jul 2015 07:14:36 +0200	[thread overview]
Message-ID: <559CB1BC.6040305@denx.de> (raw)
In-Reply-To: <1436329782-9179-12-git-send-email-yamada.masahiro@socionext.com>

Hello Masahiro,

Am 08.07.2015 um 06:29 schrieb Masahiro Yamada:
> 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 <yamada.masahiro@socionext.com>
> ---
>
>   drivers/core/device-remove.c | 23 -----------------------
>   drivers/core/device.c        | 25 +++++++------------------
>   2 files changed, 7 insertions(+), 41 deletions(-)

Nice statistic ... this effect should also popup in drivers code.

Reviewed-by: Heiko Schocher<hs@denx.de>

bye,
Heiko
>
> 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;
>

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

  reply	other threads:[~2015-07-08  5:14 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-08  4:29 [U-Boot] [RFC PATCH 00/12] Devres (Managed Device Resource) for U-Boot Masahiro Yamada
2015-07-08  4:29 ` [U-Boot] [RFC PATCH 01/12] x86: delete unneeded declarations of disable_irq() and enable_irq() Masahiro Yamada
2015-07-08  4:46   ` Bin Meng
2015-07-09  0:22     ` Simon Glass
2015-07-08  4:29 ` [U-Boot] [RFC PATCH 02/12] linux_compat: remove cpu_relax() define Masahiro Yamada
2015-07-08  5:01   ` Heiko Schocher
2015-07-08  5:19     ` Masahiro Yamada
2015-07-09  0:22   ` Simon Glass
2015-07-08  4:29 ` [U-Boot] [RFC PATCH 03/12] linux_compat: move vzalloc() to header file as an inline function Masahiro Yamada
2015-07-08  5:01   ` Heiko Schocher
2015-07-09  0:22   ` Simon Glass
2015-07-08  4:29 ` [U-Boot] [RFC PATCH 04/12] linux_compat: handle __GFP_ZERO in kmalloc() Masahiro Yamada
2015-07-08  5:03   ` Heiko Schocher
2015-07-09  0:22   ` Simon Glass
2015-07-08  4:29 ` [U-Boot] [RFC PATCH 05/12] dm: add DM_FLAG_BOUND flag Masahiro Yamada
2015-07-09  0:22   ` Simon Glass
2015-07-08  4:29 ` [U-Boot] [RFC PATCH 06/12] devres: introduce Devres (Managed Device Resource) framework Masahiro Yamada
2015-07-08  5:07   ` Heiko Schocher
2015-07-09  0:22   ` Simon Glass
2015-07-09  5:16     ` Masahiro Yamada
2015-07-09  5:41       ` Albert ARIBAUD
2015-07-09 13:31         ` Simon Glass
2015-07-09 15:03           ` Albert ARIBAUD
2015-07-09 15:12             ` Simon Glass
2015-07-08  4:29 ` [U-Boot] [RFC PATCH 07/12] devres: add devm_kmalloc() and friends (managed memory allocation) Masahiro Yamada
2015-07-09  0:23   ` Simon Glass
2015-07-08  4:29 ` [U-Boot] [RFC PATCH 08/12] dm: refactor device_bind() and device_unbind() with devm_kzalloc() Masahiro Yamada
2015-07-08  4:29 ` [U-Boot] [RFC PATCH 09/12] dm: merge fail_alloc labels Masahiro Yamada
2015-07-08  4:29 ` [U-Boot] [RFC PATCH 10/12] linux_compat: introduce GFP_DMA flag for kmalloc() Masahiro Yamada
2015-07-08  5:10   ` Heiko Schocher
2015-07-08  5:15     ` Masahiro Yamada
2015-07-08  4:29 ` [U-Boot] [RFC PATCH 11/12] dm: refactor device_probe() and device_remove() with devm_kzalloc() Masahiro Yamada
2015-07-08  5:14   ` Heiko Schocher [this message]
2015-07-08  4:29 ` [U-Boot] [RFC PATCH 12/12] devres: add debug command to dump devres Masahiro Yamada
2015-07-08  7:37   ` Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=559CB1BC.6040305@denx.de \
    --to=hs@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox