diff mbox series

[030/113] ALSA: core: use snd_pcm_is_playback/capture()

Message ID 87wmkvztx8.wl-kuninori.morimoto.gx@renesas.com (mailing list archive)
State New, archived
Headers show
Series ALSA: add snd_pcm_is_playback/capture() macro | expand

Commit Message

Kuninori Morimoto Aug. 5, 2024, 12:37 a.m. UTC
We can use snd_pcm_is_playback/capture(). Let's use it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 sound/core/pcm.c           |  8 ++++----
 sound/core/pcm_compat.c    |  4 ++--
 sound/core/pcm_dmaengine.c |  6 +++---
 sound/core/pcm_lib.c       | 14 +++++++-------
 sound/core/pcm_local.h     |  4 ++--
 sound/core/pcm_memory.c    |  2 +-
 sound/core/pcm_native.c    | 30 +++++++++++++++---------------
 7 files changed, 34 insertions(+), 34 deletions(-)
diff mbox series

Patch

diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index dc37f3508dc7a..fdbfb13e4d18f 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -497,7 +497,7 @@  static int snd_pcm_stream_proc_init(struct snd_pcm_str *pstr)
 	char name[16];
 
 	sprintf(name, "pcm%i%c", pcm->device, 
-		pstr->stream == SNDRV_PCM_STREAM_PLAYBACK ? 'p' : 'c');
+		snd_pcm_is_playback(pstr->stream) ? 'p' : 'c');
 	entry = snd_info_create_card_entry(pcm->card, name,
 					   pcm->card->proc_root);
 	if (!entry)
@@ -642,7 +642,7 @@  int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count)
 	if (err < 0)
 		return err;
 	dev_set_name(pstr->dev, "pcmC%iD%i%c", pcm->card->number, pcm->device,
-		     stream == SNDRV_PCM_STREAM_PLAYBACK ? 'p' : 'c');
+		     snd_pcm_is_playback(stream) ? 'p' : 'c');
 	pstr->dev->groups = pcm_dev_attr_groups;
 	pstr->dev->type = &pcm_dev_type;
 	dev_set_drvdata(pstr->dev, pstr);
@@ -884,8 +884,8 @@  int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
 
 	if (snd_BUG_ON(!pcm || !rsubstream))
 		return -ENXIO;
-	if (snd_BUG_ON(stream != SNDRV_PCM_STREAM_PLAYBACK &&
-		       stream != SNDRV_PCM_STREAM_CAPTURE))
+	if (snd_BUG_ON(!snd_pcm_is_playback(stream) &&
+		       !snd_pcm_is_capture(stream)))
 		return -EINVAL;
 	*rsubstream = NULL;
 	pstr = &pcm->streams[stream];
diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
index a42ec7f5a1daf..47fbbbdb5a8c7 100644
--- a/sound/core/pcm_compat.c
+++ b/sound/core/pcm_compat.c
@@ -300,7 +300,7 @@  static int snd_pcm_ioctl_xferi_compat(struct snd_pcm_substream *substream,
 	    get_user(frames, &data32->frames))
 		return -EFAULT;
 
-	if (dir == SNDRV_PCM_STREAM_PLAYBACK)
+	if (snd_pcm_is_playback(dir))
 		err = snd_pcm_lib_write(substream, compat_ptr(buf), frames);
 	else
 		err = snd_pcm_lib_read(substream, compat_ptr(buf), frames);
@@ -359,7 +359,7 @@  static int snd_pcm_ioctl_xfern_compat(struct snd_pcm_substream *substream,
 		bufs[i] = compat_ptr(ptr);
 		bufptr++;
 	}
-	if (dir == SNDRV_PCM_STREAM_PLAYBACK)
+	if (snd_pcm_is_playback(dir))
 		err = snd_pcm_lib_writev(substream, bufs, frames);
 	else
 		err = snd_pcm_lib_readv(substream, bufs, frames);
diff --git a/sound/core/pcm_dmaengine.c b/sound/core/pcm_dmaengine.c
index b134a51b3fd58..30db37652038f 100644
--- a/sound/core/pcm_dmaengine.c
+++ b/sound/core/pcm_dmaengine.c
@@ -72,7 +72,7 @@  int snd_hwparams_to_dma_slave_config(const struct snd_pcm_substream *substream,
 	else
 		buswidth = DMA_SLAVE_BUSWIDTH_8_BYTES;
 
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+	if (snd_pcm_is_playback(substream)) {
 		slave_config->direction = DMA_MEM_TO_DEV;
 		slave_config->dst_addr_width = buswidth;
 	} else {
@@ -108,7 +108,7 @@  void snd_dmaengine_pcm_set_config_from_dai_data(
 	const struct snd_dmaengine_dai_dma_data *dma_data,
 	struct dma_slave_config *slave_config)
 {
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+	if (snd_pcm_is_playback(substream)) {
 		slave_config->dst_addr = dma_data->addr;
 		slave_config->dst_maxburst = dma_data->maxburst;
 		if (dma_data->flags & SND_DMAENGINE_PCM_DAI_FLAG_PACK)
@@ -444,7 +444,7 @@  int snd_dmaengine_pcm_refine_runtime_hwparams(
 		if (dma_caps.residue_granularity <= DMA_RESIDUE_GRANULARITY_SEGMENT)
 			hw->info |= SNDRV_PCM_INFO_BATCH;
 
-		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+		if (snd_pcm_is_playback(substream))
 			addr_widths = dma_caps.dst_addr_widths;
 		else
 			addr_widths = dma_caps.src_addr_widths;
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index 6e7905749c4a3..34f45deaf493b 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -253,7 +253,7 @@  static void update_audio_tstamp(struct snd_pcm_substream *substream,
 		audio_frames = runtime->hw_ptr_wrap + runtime->status->hw_ptr;
 
 		if (runtime->audio_tstamp_config.report_delay) {
-			if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+			if (snd_pcm_is_playback(substream))
 				audio_frames -=  runtime->delay;
 			else
 				audio_frames +=  runtime->delay;
@@ -464,7 +464,7 @@  static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
 		return 0;
 	}
 
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
+	if (snd_pcm_is_playback(substream) &&
 	    runtime->silence_size > 0)
 		snd_pcm_playback_silence(substream, new_hw_ptr);
 
@@ -1947,7 +1947,7 @@  static int wait_for_avail(struct snd_pcm_substream *substream,
 			      snd_pcm_uframes_t *availp)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
-	int is_playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
+	int is_playback = snd_pcm_is_playback(substream);
 	wait_queue_entry_t wait;
 	int err = 0;
 	snd_pcm_uframes_t avail = 0;
@@ -2069,7 +2069,7 @@  static int fill_silence(struct snd_pcm_substream *substream, int channel,
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
 
-	if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
+	if (!snd_pcm_is_playback(substream))
 		return 0;
 	if (substream->ops->fill_silence)
 		return substream->ops->fill_silence(substream, channel,
@@ -2100,7 +2100,7 @@  static int do_transfer(struct snd_pcm_substream *substream, int c,
 	struct iov_iter iter;
 	int err, type;
 
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+	if (snd_pcm_is_playback(substream))
 		type = ITER_SOURCE;
 	else
 		type = ITER_DEST;
@@ -2283,7 +2283,7 @@  snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
 	if (err < 0)
 		return err;
 
-	is_playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
+	is_playback = snd_pcm_is_playback(substream);
 	if (interleaved) {
 		if (runtime->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED &&
 		    runtime->channels > 1)
@@ -2605,7 +2605,7 @@  int snd_pcm_add_chmap_ctls(struct snd_pcm *pcm, int stream,
 	info->stream = stream;
 	info->chmap = chmap;
 	info->max_channels = max_channels;
-	if (stream == SNDRV_PCM_STREAM_PLAYBACK)
+	if (snd_pcm_is_playback(stream))
 		knew.name = "Playback Channel Map";
 	else
 		knew.name = "Capture Channel Map";
diff --git a/sound/core/pcm_local.h b/sound/core/pcm_local.h
index ecb21697ae3a4..f08030e56aab6 100644
--- a/sound/core/pcm_local.h
+++ b/sound/core/pcm_local.h
@@ -35,7 +35,7 @@  void snd_pcm_playback_silence(struct snd_pcm_substream *substream,
 static inline snd_pcm_uframes_t
 snd_pcm_avail(struct snd_pcm_substream *substream)
 {
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+	if (snd_pcm_is_playback(substream))
 		return snd_pcm_playback_avail(substream->runtime);
 	else
 		return snd_pcm_capture_avail(substream->runtime);
@@ -44,7 +44,7 @@  snd_pcm_avail(struct snd_pcm_substream *substream)
 static inline snd_pcm_uframes_t
 snd_pcm_hw_avail(struct snd_pcm_substream *substream)
 {
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+	if (snd_pcm_is_playback(substream))
 		return snd_pcm_playback_hw_avail(substream->runtime);
 	else
 		return snd_pcm_capture_hw_avail(substream->runtime);
diff --git a/sound/core/pcm_memory.c b/sound/core/pcm_memory.c
index 506386959f084..2d55d3bf72d5b 100644
--- a/sound/core/pcm_memory.c
+++ b/sound/core/pcm_memory.c
@@ -63,7 +63,7 @@  static int do_alloc_pages(struct snd_card *card, int type, struct device *dev,
 		__update_allocated_size(card, size);
 	}
 
-	if (str == SNDRV_PCM_STREAM_PLAYBACK)
+	if (snd_pcm_is_playback(str))
 		dir = DMA_TO_DEVICE;
 	else
 		dir = DMA_FROM_DEVICE;
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 4057f9f10aeec..5e57ab50f4c0f 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -972,7 +972,7 @@  static int snd_pcm_sw_params(struct snd_pcm_substream *substream,
 		runtime->silence_size = params->silence_size;
 		params->boundary = runtime->boundary;
 		if (snd_pcm_running(substream)) {
-			if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
+			if (snd_pcm_is_playback(substream) &&
 			    runtime->silence_size > 0)
 				snd_pcm_playback_silence(substream, ULONG_MAX);
 			err = snd_pcm_update_state(substream, runtime);
@@ -999,7 +999,7 @@  snd_pcm_calc_delay(struct snd_pcm_substream *substream)
 {
 	snd_pcm_uframes_t delay;
 
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+	if (snd_pcm_is_playback(substream))
 		delay = snd_pcm_playback_hw_avail(substream->runtime);
 	else
 		delay = snd_pcm_capture_avail(substream->runtime);
@@ -1419,7 +1419,7 @@  static int snd_pcm_pre_start(struct snd_pcm_substream *substream,
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	if (runtime->state != SNDRV_PCM_STATE_PREPARED)
 		return -EBADFD;
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
+	if (snd_pcm_is_playback(substream) &&
 	    !snd_pcm_playback_data(substream))
 		return -EPIPE;
 	runtime->trigger_tstamp_latched = false;
@@ -1459,7 +1459,7 @@  static void snd_pcm_post_start(struct snd_pcm_substream *substream,
 	runtime->hw_ptr_buffer_jiffies = (runtime->buffer_size * HZ) / 
 							    runtime->rate;
 	__snd_pcm_set_state(runtime, state);
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
+	if (snd_pcm_is_playback(substream) &&
 	    runtime->silence_size > 0)
 		snd_pcm_playback_silence(substream, ULONG_MAX);
 	snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MSTART);
@@ -1798,7 +1798,7 @@  static int snd_pcm_do_resume(struct snd_pcm_substream *substream,
 	/* DMA not running previously? */
 	if (runtime->suspended_state != SNDRV_PCM_STATE_RUNNING &&
 	    (runtime->suspended_state != SNDRV_PCM_STATE_DRAINING ||
-	     substream->stream != SNDRV_PCM_STREAM_PLAYBACK))
+	     !snd_pcm_is_playback(substream)))
 		return 0;
 	return substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_RESUME);
 }
@@ -1904,7 +1904,7 @@  static void snd_pcm_post_reset(struct snd_pcm_substream *substream,
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	guard(pcm_stream_lock_irq)(substream);
 	runtime->control->appl_ptr = runtime->status->hw_ptr;
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
+	if (snd_pcm_is_playback(substream) &&
 	    runtime->silence_size > 0)
 		snd_pcm_playback_silence(substream, ULONG_MAX);
 }
@@ -2021,7 +2021,7 @@  static int snd_pcm_do_drain_init(struct snd_pcm_substream *substream,
 				 snd_pcm_state_t state)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+	if (snd_pcm_is_playback(substream)) {
 		switch (runtime->state) {
 		case SNDRV_PCM_STATE_PREPARED:
 			/* start playback stream if possible */
@@ -2130,7 +2130,7 @@  static int snd_pcm_drain(struct snd_pcm_substream *substream,
 		to_check = NULL;
 		group = snd_pcm_stream_group_ref(substream);
 		snd_pcm_group_for_each_entry(s, substream) {
-			if (s->stream != SNDRV_PCM_STREAM_PLAYBACK)
+			if (!snd_pcm_is_playback(s))
 				continue;
 			runtime = s->runtime;
 			if (runtime->state == SNDRV_PCM_STATE_DRAINING) {
@@ -2916,7 +2916,7 @@  static int do_pcm_hwsync(struct snd_pcm_substream *substream)
 {
 	switch (substream->runtime->state) {
 	case SNDRV_PCM_STATE_DRAINING:
-		if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
+		if (snd_pcm_is_capture(substream))
 			return -EBADFD;
 		fallthrough;
 	case SNDRV_PCM_STATE_RUNNING:
@@ -3215,7 +3215,7 @@  static int snd_pcm_xferi_frames_ioctl(struct snd_pcm_substream *substream,
 		return -EFAULT;
 	if (copy_from_user(&xferi, _xferi, sizeof(xferi)))
 		return -EFAULT;
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+	if (snd_pcm_is_playback(substream))
 		result = snd_pcm_lib_write(substream, xferi.buf, xferi.frames);
 	else
 		result = snd_pcm_lib_read(substream, xferi.buf, xferi.frames);
@@ -3244,7 +3244,7 @@  static int snd_pcm_xfern_frames_ioctl(struct snd_pcm_substream *substream,
 	bufs = memdup_user(xfern.bufs, sizeof(void *) * runtime->channels);
 	if (IS_ERR(bufs))
 		return PTR_ERR(no_free_ptr(bufs));
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+	if (snd_pcm_is_playback(substream))
 		result = snd_pcm_lib_writev(substream, bufs, xfern.frames);
 	else
 		result = snd_pcm_lib_readv(substream, bufs, xfern.frames);
@@ -3433,7 +3433,7 @@  int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
 	case SNDRV_PCM_IOCTL_FORWARD:
 	{
 		/* provided only for OSS; capture-only and no value returned */
-		if (substream->stream != SNDRV_PCM_STREAM_CAPTURE)
+		if (!snd_pcm_is_capture(substream))
 			return -EINVAL;
 		result = snd_pcm_forward(substream, *frames);
 		return result < 0 ? result : 0;
@@ -3596,7 +3596,7 @@  static __poll_t snd_pcm_poll(struct file *file, poll_table *wait)
 	pcm_file = file->private_data;
 
 	substream = pcm_file->substream;
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+	if (snd_pcm_is_playback(substream))
 		ok = EPOLLOUT | EPOLLWRNORM;
 	else
 		ok = EPOLLIN | EPOLLRDNORM;
@@ -3620,7 +3620,7 @@  static __poll_t snd_pcm_poll(struct file *file, poll_table *wait)
 			mask = ok;
 		break;
 	case SNDRV_PCM_STATE_DRAINING:
-		if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
+		if (snd_pcm_is_capture(substream)) {
 			mask = ok;
 			if (!avail)
 				mask |= EPOLLERR;
@@ -3876,7 +3876,7 @@  int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file,
 	size_t dma_bytes;
 	int err;
 
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+	if (snd_pcm_is_playback(substream)) {
 		if (!(area->vm_flags & (VM_WRITE|VM_READ)))
 			return -EINVAL;
 	} else {