From: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
To: <alsa-devel@alsa-project.org>, <linux-kernel@vger.kernel.org>
Cc: <perex@perex.cz>, <tiwai@suse.com>,
<pierre-louis.bossart@linux.intel.com>, <broonie@kernel.org>,
<joe@perches.com>, <lgirdwood@gmail.com>, <lars@metafoo.de>,
<kuninori.morimoto.gx@renesas.com>, <nicolas.ferre@microchip.com>,
<Cristian.Birsan@microchip.com>,
Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
Subject: [RFC PATCH 1/6] ALSA: core: pcm: Create helpers to allocate/free struct snd_pcm_runtime
Date: Wed, 19 May 2021 13:48:37 +0300 [thread overview]
Message-ID: <20210519104842.977895-2-codrin.ciubotariu@microchip.com> (raw)
In-Reply-To: <20210519104842.977895-1-codrin.ciubotariu@microchip.com>
Create helpers to be able to reuse code for allocation and freeing of
struct snd_pcm_runtime.
Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
---
include/sound/pcm.h | 2 ++
sound/core/pcm.c | 82 +++++++++++++++++++++++++++------------------
2 files changed, 52 insertions(+), 32 deletions(-)
diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index 2e1200d17d0c..025b4d2ba0fe 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -574,6 +574,8 @@ static inline int snd_pcm_suspend_all(struct snd_pcm *pcm)
}
#endif
int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg);
+struct snd_pcm_runtime *snd_pcm_runtime_alloc(void);
+void snd_pcm_runtime_free(struct snd_pcm_runtime *runtime);
int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct file *file,
struct snd_pcm_substream **rsubstream);
void snd_pcm_release_substream(struct snd_pcm_substream *substream);
diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index b163164a83ec..8ecb14b27460 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -876,6 +876,53 @@ static int snd_pcm_dev_free(struct snd_device *device)
return snd_pcm_free(pcm);
}
+struct snd_pcm_runtime *snd_pcm_runtime_alloc(void)
+{
+ struct snd_pcm_runtime *runtime;
+ size_t size;
+
+ runtime = kzalloc(sizeof(*runtime), GFP_KERNEL);
+ if (!runtime)
+ return NULL;
+
+ size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status));
+ runtime->status = alloc_pages_exact(size, GFP_KERNEL);
+ if (!runtime->status) {
+ kfree(runtime);
+ return NULL;
+ }
+ memset(runtime->status, 0, size);
+
+ size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control));
+ runtime->control = alloc_pages_exact(size, GFP_KERNEL);
+ if (!runtime->control) {
+ free_pages_exact(runtime->status,
+ PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status)));
+ kfree(runtime);
+ return NULL;
+ }
+ memset(runtime->control, 0, size);
+
+ init_waitqueue_head(&runtime->sleep);
+ init_waitqueue_head(&runtime->tsleep);
+
+ runtime->status->state = SNDRV_PCM_STATE_OPEN;
+
+ return runtime;
+}
+EXPORT_SYMBOL_GPL(snd_pcm_runtime_alloc);
+
+void snd_pcm_runtime_free(struct snd_pcm_runtime *runtime)
+{
+ free_pages_exact(runtime->status,
+ PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status)));
+ free_pages_exact(runtime->control,
+ PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control)));
+ kfree(runtime->hw_constraints.rules);
+ kfree(runtime);
+}
+EXPORT_SYMBOL_GPL(snd_pcm_runtime_free);
+
int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
struct file *file,
struct snd_pcm_substream **rsubstream)
@@ -885,7 +932,6 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
struct snd_pcm_runtime *runtime;
struct snd_card *card;
int prefer_subdevice;
- size_t size;
if (snd_BUG_ON(!pcm || !rsubstream))
return -ENXIO;
@@ -939,33 +985,10 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
if (substream == NULL)
return -EAGAIN;
- runtime = kzalloc(sizeof(*runtime), GFP_KERNEL);
- if (runtime == NULL)
+ runtime = snd_pcm_runtime_alloc();
+ if (!runtime)
return -ENOMEM;
- size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status));
- runtime->status = alloc_pages_exact(size, GFP_KERNEL);
- if (runtime->status == NULL) {
- kfree(runtime);
- return -ENOMEM;
- }
- memset(runtime->status, 0, size);
-
- size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control));
- runtime->control = alloc_pages_exact(size, GFP_KERNEL);
- if (runtime->control == NULL) {
- free_pages_exact(runtime->status,
- PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status)));
- kfree(runtime);
- return -ENOMEM;
- }
- memset(runtime->control, 0, size);
-
- init_waitqueue_head(&runtime->sleep);
- init_waitqueue_head(&runtime->tsleep);
-
- runtime->status->state = SNDRV_PCM_STATE_OPEN;
-
substream->runtime = runtime;
substream->private_data = pcm->private_data;
substream->ref_count = 1;
@@ -985,11 +1008,6 @@ void snd_pcm_detach_substream(struct snd_pcm_substream *substream)
runtime = substream->runtime;
if (runtime->private_free != NULL)
runtime->private_free(runtime);
- free_pages_exact(runtime->status,
- PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status)));
- free_pages_exact(runtime->control,
- PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control)));
- kfree(runtime->hw_constraints.rules);
/* Avoid concurrent access to runtime via PCM timer interface */
if (substream->timer) {
spin_lock_irq(&substream->timer->lock);
@@ -998,7 +1016,7 @@ void snd_pcm_detach_substream(struct snd_pcm_substream *substream)
} else {
substream->runtime = NULL;
}
- kfree(runtime);
+ snd_pcm_runtime_free(runtime);
put_pid(substream->pid);
substream->pid = NULL;
substream->pstr->substream_opened--;
--
2.27.0
next prev parent reply other threads:[~2021-05-19 10:49 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-19 10:48 [RFC PATCH 0/6] soc-pcm: Add separate snd_pcm_runtime for BEs Codrin Ciubotariu
2021-05-19 10:48 ` Codrin Ciubotariu [this message]
2021-05-19 10:48 ` [RFC PATCH 2/6] ALSA: pcm: Export constraints initialization functions Codrin Ciubotariu
2021-05-19 10:48 ` [RFC PATCH 3/6] ALSA: pcm: Check for substream->ops before substream->ops->mmap Codrin Ciubotariu
2021-05-19 10:48 ` [RFC PATCH 4/6] ALSA: pcm: Create function for snd_pcm_runtime initialization Codrin Ciubotariu
2021-05-19 10:48 ` [RFC PATCH 5/6] ASoC: soc-pcm: Create new snd_pcm_runtime for BE DAIs Codrin Ciubotariu
2021-05-19 10:48 ` [RFC PATCH 6/6] ASoC: dmaengine: Allocate buffer if substream is unmanaged Codrin Ciubotariu
2021-05-19 14:15 ` [RFC PATCH 0/6] soc-pcm: Add separate snd_pcm_runtime for BEs Takashi Iwai
2021-05-19 15:08 ` Codrin.Ciubotariu
2021-05-19 15:41 ` Takashi Iwai
2021-05-20 13:59 ` Codrin.Ciubotariu
2021-05-21 14:26 ` Takashi Iwai
2021-05-24 19:33 ` Codrin.Ciubotariu
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=20210519104842.977895-2-codrin.ciubotariu@microchip.com \
--to=codrin.ciubotariu@microchip.com \
--cc=Cristian.Birsan@microchip.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=joe@perches.com \
--cc=kuninori.morimoto.gx@renesas.com \
--cc=lars@metafoo.de \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolas.ferre@microchip.com \
--cc=perex@perex.cz \
--cc=pierre-louis.bossart@linux.intel.com \
--cc=tiwai@suse.com \
/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
all inboxes | Powered by JetHome®