All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: alsa-devel@alsa-project.org
Cc: Hans Hu <HansHu@zhaoxin.com>
Subject: [PATCH 2/8] ALSA: memalloc: Simplify snd_malloc_dev_pages() calls
Date: Mon, 27 Aug 2018 10:59:47 +0200	[thread overview]
Message-ID: <20180827085953.10614-3-tiwai@suse.de> (raw)
In-Reply-To: <20180827085953.10614-1-tiwai@suse.de>

snd_malloc_dev_pages() and snd_free_dev_pages() are local functions
and the parameters passed there are all contained in snd_dma_buffer
object.  As a code-simplification, pass snd_dma_buffer object and
assign the address there like other allocators do (except for
snd_malloc_pages() which is called from outside, hence we can't change
easily).

Only code refactoring, no functional changes.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/core/memalloc.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c
index d85df01bf055..cc051bfe2f6f 100644
--- a/sound/core/memalloc.c
+++ b/sound/core/memalloc.c
@@ -82,26 +82,22 @@ EXPORT_SYMBOL(snd_free_pages);
 
 #ifdef CONFIG_HAS_DMA
 /* allocate the coherent DMA pages */
-static void *snd_malloc_dev_pages(struct device *dev, size_t size, dma_addr_t *dma)
+static void snd_malloc_dev_pages(struct snd_dma_buffer *dmab, size_t size)
 {
 	gfp_t gfp_flags;
 
-	if (WARN_ON(!dma))
-		return NULL;
 	gfp_flags = GFP_KERNEL
 		| __GFP_COMP	/* compound page lets parts be mapped */
 		| __GFP_NORETRY /* don't trigger OOM-killer */
 		| __GFP_NOWARN; /* no stack trace print - this call is non-critical */
-	return dma_alloc_coherent(dev, size, dma, gfp_flags);
+	dmab->area = dma_alloc_coherent(dmab->dev.dev, size, &dmab->addr,
+					gfp_flags);
 }
 
 /* free the coherent DMA pages */
-static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr,
-			       dma_addr_t dma)
+static void snd_free_dev_pages(struct snd_dma_buffer *dmab)
 {
-	if (ptr == NULL)
-		return;
-	dma_free_coherent(dev, size, ptr, dma);
+	dma_free_coherent(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr);
 }
 
 #ifdef CONFIG_GENERIC_ALLOCATOR
@@ -195,7 +191,7 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size,
 		dmab->dev.type = SNDRV_DMA_TYPE_DEV;
 #endif /* CONFIG_GENERIC_ALLOCATOR */
 	case SNDRV_DMA_TYPE_DEV:
-		dmab->area = snd_malloc_dev_pages(device, size, &dmab->addr);
+		snd_malloc_dev_pages(dmab, size);
 		break;
 #endif
 #ifdef CONFIG_SND_DMA_SGBUF
@@ -270,7 +266,7 @@ void snd_dma_free_pages(struct snd_dma_buffer *dmab)
 		break;
 #endif /* CONFIG_GENERIC_ALLOCATOR */
 	case SNDRV_DMA_TYPE_DEV:
-		snd_free_dev_pages(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr);
+		snd_free_dev_pages(dmab);
 		break;
 #endif
 #ifdef CONFIG_SND_DMA_SGBUF
-- 
2.18.0

  parent reply	other threads:[~2018-08-27  9:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-27  8:59 [PATCH 0/8] ALSA: non-cached memalloc helper Takashi Iwai
2018-08-27  8:59 ` [PATCH 1/8] ALSA: memalloc: Don't align the size to power-of-two Takashi Iwai
2018-08-27  8:59 ` Takashi Iwai [this message]
2018-08-27  8:59 ` [PATCH 3/8] ALSA: memalloc: Add non-cached buffer type Takashi Iwai
2018-08-27  8:59 ` [PATCH 4/8] ALSA: hda: Check the non-cached stream buffers more explicitly Takashi Iwai
2018-08-27  8:59 ` [PATCH 5/8] ALSA: hda: Use new non-cached allocation for non-snoop mode Takashi Iwai
2018-08-27  8:59 ` [PATCH 6/8] ALSA: hda: Remove substream allocation/free ops Takashi Iwai
2018-08-27  8:59 ` [PATCH 7/8] ALSA: intel8x0: Use the new non-cached allocation for 440MX workaround Takashi Iwai
2018-08-27  8:59 ` [PATCH 8/8] ALSA: intel_hdmi: Use the new non-cached allocation Takashi Iwai

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=20180827085953.10614-3-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=HansHu@zhaoxin.com \
    --cc=alsa-devel@alsa-project.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.