mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	BAREBOX <barebox@lists.infradead.org>
Subject: Re: [PATCH 1/3] dma: add dma_xalloc() and dma_xzalloc()
Date: Fri, 16 Oct 2026 12:31:30 +0200	[thread overview]
Message-ID: <50e72463-4202-4dce-9203-144c109016d1@pengutronix.de> (raw)
In-Reply-To: <20261016-dma-alloc-v1-1-31fc7afe3954@pengutronix.de>



On 10/16/26 9:36 AM, Sascha Hauer wrote:
> dma_alloc() and dma_zalloc() are implemented with xmemalign() and
> can't fail, yet many of their callers check for NULL, while others
> rely on them never returning NULL.
> 
> As a first step towards making dma_alloc() and dma_zalloc() fallible
> like malloc() and calloc(), add dma_xalloc() and dma_xzalloc() as
> counterparts to xmalloc() and xzalloc() for the callers that rely on
> the allocation to always succeed.
> 
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

> ---
>  drivers/dma/map.c | 17 +++++++++++++++++
>  include/dma.h     | 12 ++++++++++++
>  2 files changed, 29 insertions(+)
> 
> diff --git a/drivers/dma/map.c b/drivers/dma/map.c
> index 11671f9f66..806439a05d 100644
> --- a/drivers/dma/map.c
> +++ b/drivers/dma/map.c
> @@ -9,6 +9,12 @@ void *dma_alloc(size_t size)
>  }
>  EXPORT_SYMBOL(dma_alloc);
>  
> +void *dma_xalloc(size_t size)
> +{
> +	return xmemalign(DMA_ALIGNMENT, ALIGN(size, DMA_ALIGNMENT));
> +}
> +EXPORT_SYMBOL(dma_xalloc);
> +
>  void *dma_zalloc(size_t size)
>  {
>  	void *buf;
> @@ -21,6 +27,17 @@ void *dma_zalloc(size_t size)
>  }
>  EXPORT_SYMBOL(dma_zalloc);
>  
> +void *dma_xzalloc(size_t size)
> +{
> +	void *buf;
> +
> +	buf = dma_xalloc(size);
> +	memset(buf, 0x00, size);
> +
> +	return buf;
> +}
> +EXPORT_SYMBOL(dma_xzalloc);
> +
>  void dma_sync_single_for_cpu(struct device *dev, dma_addr_t address,
>  			     size_t size, enum dma_data_direction dir)
>  {
> diff --git a/include/dma.h b/include/dma.h
> index c285b2095a..600b91c485 100644
> --- a/include/dma.h
> +++ b/include/dma.h
> @@ -28,17 +28,29 @@
>  
>  #ifdef CONFIG_HAS_DMA
>  void *dma_alloc(size_t size);
> +void *dma_xalloc(size_t size);
>  void *dma_zalloc(size_t size);
> +void *dma_xzalloc(size_t size);
>  #else
>  static inline void *dma_alloc(size_t size)
>  {
>  	return malloc(size);
>  }
>  
> +static inline void *dma_xalloc(size_t size)
> +{
> +	return xmalloc(size);
> +}
> +
>  static inline void *dma_zalloc(size_t size)
>  {
>  	return calloc(size, 1);
>  }
> +
> +static inline void *dma_xzalloc(size_t size)
> +{
> +	return xzalloc(size);
> +}
>  #endif
>  
>  static inline void dma_free(void *mem)
> 

-- 
Pengutronix e.K.                  |                             |
Steuerwalder Str. 21              | http://www.pengutronix.de/  |
31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |




  reply	other threads:[~2026-10-16 10:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16  7:36 [PATCH 0/3] dma: make dma_alloc() and dma_zalloc() fallible Sascha Hauer
2026-10-16  7:36 ` [PATCH 1/3] dma: add dma_xalloc() and dma_xzalloc() Sascha Hauer
2026-10-16 10:31   ` Ahmad Fatoum [this message]
2026-10-16  7:36 ` [PATCH 2/3] treewide: use dma_xalloc()/dma_xzalloc() where the result isn't checked Sascha Hauer
2026-10-16 10:35   ` Ahmad Fatoum
2026-10-16  7:36 ` [PATCH 3/3] dma: let dma_alloc() and dma_zalloc() fail Sascha Hauer
2026-10-16 10:35   ` Ahmad Fatoum

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=50e72463-4202-4dce-9203-144c109016d1@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.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