Skip to contentSkip to conversation

ALSA: PCM state reference optimization

PATCH In review Takashi Iwai 5 participants 20 messages Sep 26, 2022 – Sep 27, 2022

Subsystems (5)
USB Sound ASoC Intel ASoC drivers +1 more subsystems
lore
Share & tools
lore
#0 lore raw

cover ALSA: PCM state reference optimization

Hi,

this is a patch set for simplifying the reference to the current PCM state by having the local copy in runtime instead of relying on runtime->status indirection. This also hardens against the attack by modifying the mmapped status record.

The first patch does the basic job in the core PCM side, and the second patch flips the PCM status mmap to read-only for hardening, while the remaining patches are for drivers to follow the core change.

The conversions are straightforward. In most places, it's just replacing runtime->status->state with runtime->state.

Takashi

===

Takashi Iwai (11):
ALSA: pcm: Avoid reference to status->state
ALSA: pcm: Make mmap status read-only
ALSA: aloop: Replace runtime->status->state reference to

    runtime->state
  ALSA: firewire: Replace runtime->status->state reference to
    runtime->state
  ALSA: hda: Replace runtime->status->state reference to runtime->state
  ALSA: asihpi: Replace runtime->status->state reference to
    runtime->state
  ALSA: usb-audio: Replace runtime->status->state reference to
    runtime->state
  ALSA: usx2y: Replace runtime->status->state reference to
    runtime->state
  ASoC: intel: Replace runtime->status->state reference to
    runtime->state
  ASoC: sh: Replace runtime->status->state reference to runtime->state
  usb: gadget: Replace runtime->status->state reference to
    runtime->state
 drivers/usb/gadget/function/u_uac1_legacy.c |   4 +-
 include/sound/pcm.h                         |  20 ++-
 sound/core/oss/pcm_oss.c                    |  42 +++----
 sound/core/pcm.c                            |   9 +-
 sound/core/pcm_compat.c                     |   4 +-
 sound/core/pcm_lib.c                        |  16 +--
 sound/core/pcm_native.c                     | 128 ++++++++++----------
 sound/drivers/aloop.c                       |   4 +-
 sound/firewire/bebob/bebob_pcm.c            |   4 +-
 sound/firewire/dice/dice-pcm.c              |   4 +-
 sound/firewire/digi00x/digi00x-pcm.c        |   4 +-
 sound/firewire/fireface/ff-pcm.c            |   4 +-
 sound/firewire/fireworks/fireworks_pcm.c    |   4 +-
 sound/firewire/motu/motu-pcm.c              |   4 +-
 sound/firewire/oxfw/oxfw-pcm.c              |   8 +-
 sound/firewire/tascam/tascam-pcm.c          |   4 +-
 sound/hda/hdmi_chmap.c                      |   2 +-
 sound/pci/asihpi/asihpi.c                   |   2 +-
 sound/soc/intel/skylake/skl-pcm.c           |   4 +-
 sound/soc/sh/rz-ssi.c                       |   2 +-
 sound/usb/pcm.c                             |   4 +-
 sound/usb/usx2y/usbusx2yaudio.c             |   3 +-
 sound/usb/usx2y/usx2yhwdeppcm.c             |   3 +-
 23 files changed, 150 insertions(+), 133 deletions(-)

===

Cc Bard Liao <[email protected]>
Cc Cezary Rojewski <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Kai Vehmanen <[email protected]>
Cc Liam Girdwood <[email protected]>
Cc Mark Brown <[email protected]>
Cc Peter Ujfalusi <[email protected]>
Cc Pierre-Louis Bossart <[email protected]>
Cc Ranjani Sridharan <[email protected]>
Cc Takashi Sakamoto <[email protected]>
Signature · 1 line
2.35.3
#1 lore raw

PATCH 1/11 ALSA: pcm: Avoid reference to status->state

In the PCM core and driver code, there are lots place referring to the current PCM state via runtime->status->state. This patch introduced a local PCM state in runtime itself and replaces those references with runtime->state. It has improvements in two aspects:

- The reduction of a indirect access leads to more code optimization

- It avoids a possible (unexpected) modification of the state via mmap of the status record

The status->state is updated together with runtime->state, so that user-space can still read the current state via mmap like before, too.

This patch touches only the ALSA core code. The changes in each driver will follow in later patches.

---
 include/sound/pcm.h      |  20 +++++-
 sound/core/oss/pcm_oss.c |  42 ++++++-------
 sound/core/pcm.c         |   9 +--
 sound/core/pcm_compat.c  |   4 +-
 sound/core/pcm_lib.c     |  16 ++---
 sound/core/pcm_native.c  | 127 ++++++++++++++++++++-------------------
 6 files changed, 118 insertions(+), 100 deletions(-)
include/sound/pcm.h +18 -2
index 8c48a5bce88c..7b1a022910e8 100644
@@ -346,6 +346,8 @@ static inline void snd_pcm_pack_audio_tstamp_report(__u32 *data, __u32 *accuracy
 
 struct snd_pcm_runtime {
 	/* -- Status -- */
+	snd_pcm_state_t state;		/* stream state */
+	snd_pcm_state_t suspended_state; /* suspended stream state */
 	struct snd_pcm_substream *trigger_master;
 	struct timespec64 trigger_tstamp;	/* trigger timestamp */
 	bool trigger_tstamp_latched;     /* trigger timestamp latched in low-level driver/hardware */
@@ -678,11 +680,25 @@ void snd_pcm_stream_unlock_irqrestore(struct snd_pcm_substream *substream,
  */
 static inline int snd_pcm_running(struct snd_pcm_substream *substream)
 {
-	return (substream->runtime->status->state == SNDRV_PCM_STATE_RUNNING ||
-		(substream->runtime->status->state == SNDRV_PCM_STATE_DRAINING &&
+	return (substream->runtime->state == SNDRV_PCM_STATE_RUNNING ||
+		(substream->runtime->state == SNDRV_PCM_STATE_DRAINING &&
 		 substream->stream == SNDRV_PCM_STREAM_PLAYBACK));
 }
 
+/**
+ * __snd_pcm_set_state - Change the current PCM state
+ * @runtime: PCM runtime to set
+ * @state: the current state to set
+ *
+ * Call within the stream lock
+ */
+static inline void __snd_pcm_set_state(struct snd_pcm_runtime *runtime,
+				       snd_pcm_state_t state)
+{
+	runtime->state = state;
+	runtime->status->state = state; /* copy for mmap */
+}
+
 /**
  * bytes_to_samples - Unit conversion of the size from bytes to samples
  * @runtime: PCM runtime instance
sound/core/oss/pcm_oss.c +21 -21

124 lines not on this page · raw message

sound/core/pcm.c +5 -4
index 82925709fa12..9d95e3731123 100644
@@ -387,7 +387,7 @@ static void snd_pcm_substream_proc_hw_params_read(struct snd_info_entry *entry,
 		snd_iprintf(buffer, "closed\n");
 		goto unlock;
 	}
-	if (runtime->status->state == SNDRV_PCM_STATE_OPEN) {
+	if (runtime->state == SNDRV_PCM_STATE_OPEN) {
 		snd_iprintf(buffer, "no setup\n");
 		goto unlock;
 	}
@@ -424,7 +424,7 @@ static void snd_pcm_substream_proc_sw_params_read(struct snd_info_entry *entry,
 		snd_iprintf(buffer, "closed\n");
 		goto unlock;
 	}
-	if (runtime->status->state == SNDRV_PCM_STATE_OPEN) {
+	if (runtime->state == SNDRV_PCM_STATE_OPEN) {
 		snd_iprintf(buffer, "no setup\n");
 		goto unlock;
 	}
@@ -970,7 +970,7 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
 	init_waitqueue_head(&runtime->sleep);
 	init_waitqueue_head(&runtime->tsleep);
 
-	runtime->status->state = SNDRV_PCM_STATE_OPEN;
+	__snd_pcm_set_state(runtime, SNDRV_PCM_STATE_OPEN);
 	mutex_init(&runtime->buffer_mutex);
 	atomic_set(&runtime->buffer_accessing, 0);
 
@@ -1112,7 +1112,8 @@ static int snd_pcm_dev_disconnect(struct snd_device *device)
 			if (snd_pcm_running(substream))
 				snd_pcm_stop(substream, SNDRV_PCM_STATE_DISCONNECTED);
 			/* to be sure, set the state unconditionally */
-			substream->runtime->status->state = SNDRV_PCM_STATE_DISCONNECTED;
+			__snd_pcm_set_state(substream->runtime,
+					    SNDRV_PCM_STATE_DISCONNECTED);
 			wake_up(&substream->runtime->sleep);
 			wake_up(&substream->runtime->tsleep);
 		}
sound/core/pcm_compat.c +2 -2
index 917c5b4f19d7..42c2ada8e888 100644
@@ -295,7 +295,7 @@ static int snd_pcm_ioctl_xferi_compat(struct snd_pcm_substream *substream,
 		return -ENOTTY;
 	if (substream->stream != dir)
 		return -EINVAL;
-	if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN)
+	if (substream->runtime->state == SNDRV_PCM_STATE_OPEN)
 		return -EBADFD;
 
 	if (get_user(buf, &data32->buf) ||
@@ -341,7 +341,7 @@ static int snd_pcm_ioctl_xfern_compat(struct snd_pcm_substream *substream,
 		return -ENOTTY;
 	if (substream->stream != dir)
 		return -EINVAL;
-	if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN)
+	if (substream->runtime->state == SNDRV_PCM_STATE_OPEN)
 		return -EBADFD;
 
 	ch = substream->runtime->channels;
sound/core/pcm_lib.c +8 -8
index 40751e5aff09..8b6aeb8a78f7 100644
@@ -186,7 +186,7 @@ int snd_pcm_update_state(struct snd_pcm_substream *substream,
 	avail = snd_pcm_avail(substream);
 	if (avail > runtime->avail_max)
 		runtime->avail_max = avail;
-	if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
+	if (runtime->state == SNDRV_PCM_STATE_DRAINING) {
 		if (avail >= runtime->buffer_size) {
 			snd_pcm_drain_done(substream);
 			return -EPIPE;
@@ -1911,7 +1911,7 @@ static int wait_for_avail(struct snd_pcm_substream *substream,
 
 		snd_pcm_stream_lock_irq(substream);
 		set_current_state(TASK_INTERRUPTIBLE);
-		switch (runtime->status->state) {
+		switch (runtime->state) {
 		case SNDRV_PCM_STATE_SUSPENDED:
 			err = -ESTRPIPE;
 			goto _endloop;
@@ -2099,14 +2099,14 @@ static int pcm_sanity_check(struct snd_pcm_substream *substream)
 	runtime = substream->runtime;
 	if (snd_BUG_ON(!substream->ops->copy_user && !runtime->dma_area))
 		return -EINVAL;
-	if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
+	if (runtime->state == SNDRV_PCM_STATE_OPEN)
 		return -EBADFD;
 	return 0;
 }
 
 static int pcm_accessible_state(struct snd_pcm_runtime *runtime)
 {
-	switch (runtime->status->state) {
+	switch (runtime->state) {
 	case SNDRV_PCM_STATE_PREPARED:
 	case SNDRV_PCM_STATE_RUNNING:
 	case SNDRV_PCM_STATE_PAUSED:
@@ -2225,7 +2225,7 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
 		goto _end_unlock;
 
 	runtime->twake = runtime->control->avail_min ? : 1;
-	if (runtime->status->state == SNDRV_PCM_STATE_RUNNING)
+	if (runtime->state == SNDRV_PCM_STATE_RUNNING)
 		snd_pcm_update_hw_ptr(substream);
 
 	/*
@@ -2233,7 +2233,7 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
 	 * thread may start capture
 	 */
 	if (!is_playback &&
-	    runtime->status->state == SNDRV_PCM_STATE_PREPARED &&
+	    runtime->state == SNDRV_PCM_STATE_PREPARED &&
 	    size >= runtime->start_threshold) {
 		err = snd_pcm_start(substream);
 		if (err < 0)
@@ -2247,7 +2247,7 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
 		snd_pcm_uframes_t cont;
 		if (!avail) {
 			if (!is_playback &&
-			    runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
+			    runtime->state == SNDRV_PCM_STATE_DRAINING) {
 				snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP);
 				goto _end_unlock;
 			}
@@ -2303,7 +2303,7 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
 		xfer += frames;
 		avail -= frames;
 		if (is_playback &&
-		    runtime->status->state == SNDRV_PCM_STATE_PREPARED &&
+		    runtime->state == SNDRV_PCM_STATE_PREPARED &&
 		    snd_pcm_playback_hw_avail(runtime) >= (snd_pcm_sframes_t)runtime->start_threshold) {
 			err = snd_pcm_start(substream);
 			if (err < 0)
sound/core/pcm_native.c +64 -63

418 lines not on this page · raw message

Signature · 1 line
2.35.3
#2 lore raw

PATCH 2/11 ALSA: pcm: Make mmap status read-only

In reply to Takashi Iwai

The mmap status record should be read-only. Modifying it from user-space may screw up things unexpectedly, so let's clear the write bits at exposing it.

---
 sound/core/pcm_native.c | 1 +
 1 file changed, 1 insertion(+)
sound/core/pcm_native.c +1 -0
index d9485b1ab719..33769ca78cc8 100644
@@ -3668,6 +3668,7 @@ static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file
 	area->vm_ops = &snd_pcm_vm_ops_status;
 	area->vm_private_data = substream;
 	area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
+	area->vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
 	return 0;
 }
 
Signature · 1 line
2.35.3
#3 lore raw

PATCH 3/11 ALSA: aloop: Replace runtime->status->state reference to runtime->state

In reply to Takashi Iwai

The recent change in ALSA core allows drivers to get the current PCM state directly from runtime object. Replace the calls accordingly.

---
 sound/drivers/aloop.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sound/drivers/aloop.c +2 -2
index 12f12a294df5..a38e602b4fc6 100644
@@ -535,7 +535,7 @@ static void copy_play_buf(struct loopback_pcm *play,
 
 	/* check if playback is draining, trim the capture copy size
 	 * when our pointer is at the end of playback ring buffer */
-	if (runtime->status->state == SNDRV_PCM_STATE_DRAINING &&
+	if (runtime->state == SNDRV_PCM_STATE_DRAINING &&
 	    snd_pcm_playback_hw_avail(runtime) < runtime->buffer_size) { 
 	    	snd_pcm_uframes_t appl_ptr, appl_ptr1, diff;
 		appl_ptr = appl_ptr1 = runtime->control->appl_ptr;
@@ -730,7 +730,7 @@ static void loopback_snd_timer_period_elapsed(struct loopback_cable *cable,
 
 	if (event == SNDRV_TIMER_EVENT_MSTOP) {
 		if (!dpcm_play ||
-		    dpcm_play->substream->runtime->status->state !=
+		    dpcm_play->substream->runtime->state !=
 				SNDRV_PCM_STATE_DRAINING) {
 			spin_unlock_irqrestore(&cable->lock, flags);
 			return;
Signature · 1 line
2.35.3
#4 lore raw

PATCH 4/11 ALSA: firewire: Replace runtime->status->state reference to runtime->state

In reply to Takashi Iwai

The recent change in ALSA core allows drivers to get the current PCM state directly from runtime object. Replace the calls accordingly.

Cc Takashi Sakamoto <[email protected]>
---
 sound/firewire/bebob/bebob_pcm.c         | 4 ++--
 sound/firewire/dice/dice-pcm.c           | 4 ++--
 sound/firewire/digi00x/digi00x-pcm.c     | 4 ++--
 sound/firewire/fireface/ff-pcm.c         | 4 ++--
 sound/firewire/fireworks/fireworks_pcm.c | 4 ++--
 sound/firewire/motu/motu-pcm.c           | 4 ++--
 sound/firewire/oxfw/oxfw-pcm.c           | 8 ++++----
 sound/firewire/tascam/tascam-pcm.c       | 4 ++--
 8 files changed, 18 insertions(+), 18 deletions(-)
sound/firewire/bebob/bebob_pcm.c +2 -2
index f8d9a2041264..ce49eef0fcba 100644
@@ -214,7 +214,7 @@ static int pcm_hw_params(struct snd_pcm_substream *substream,
 	struct snd_bebob *bebob = substream->private_data;
 	int err = 0;
 
-	if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
+	if (substream->runtime->state == SNDRV_PCM_STATE_OPEN) {
 		unsigned int rate = params_rate(hw_params);
 		unsigned int frames_per_period = params_period_size(hw_params);
 		unsigned int frames_per_buffer = params_buffer_size(hw_params);
@@ -236,7 +236,7 @@ static int pcm_hw_free(struct snd_pcm_substream *substream)
 
 	mutex_lock(&bebob->mutex);
 
-	if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)
+	if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
 		bebob->substreams_counter--;
 
 	snd_bebob_stream_stop_duplex(bebob);
sound/firewire/dice/dice-pcm.c +2 -2
index a69ca1111b03..d64366217d57 100644
@@ -266,7 +266,7 @@ static int pcm_hw_params(struct snd_pcm_substream *substream,
 	struct snd_dice *dice = substream->private_data;
 	int err = 0;
 
-	if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
+	if (substream->runtime->state == SNDRV_PCM_STATE_OPEN) {
 		unsigned int rate = params_rate(hw_params);
 		unsigned int events_per_period = params_period_size(hw_params);
 		unsigned int events_per_buffer = params_buffer_size(hw_params);
@@ -293,7 +293,7 @@ static int pcm_hw_free(struct snd_pcm_substream *substream)
 
 	mutex_lock(&dice->mutex);
 
-	if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)
+	if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
 		--dice->substreams_counter;
 
 	snd_dice_stream_stop_duplex(dice);
sound/firewire/digi00x/digi00x-pcm.c +2 -2
index b7f6eda09f9f..3bd1575c9d9c 100644
@@ -190,7 +190,7 @@ static int pcm_hw_params(struct snd_pcm_substream *substream,
 	struct snd_dg00x *dg00x = substream->private_data;
 	int err = 0;
 
-	if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
+	if (substream->runtime->state == SNDRV_PCM_STATE_OPEN) {
 		unsigned int rate = params_rate(hw_params);
 		unsigned int frames_per_period = params_period_size(hw_params);
 		unsigned int frames_per_buffer = params_buffer_size(hw_params);
@@ -212,7 +212,7 @@ static int pcm_hw_free(struct snd_pcm_substream *substream)
 
 	mutex_lock(&dg00x->mutex);
 
-	if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)
+	if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
 		--dg00x->substreams_counter;
 
 	snd_dg00x_stream_stop_duplex(dg00x);
sound/firewire/fireface/ff-pcm.c +2 -2
index f978cc2fed7d..ec915671a79b 100644
@@ -230,7 +230,7 @@ static int pcm_hw_params(struct snd_pcm_substream *substream,
 	struct snd_ff *ff = substream->private_data;
 	int err = 0;
 
-	if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
+	if (substream->runtime->state == SNDRV_PCM_STATE_OPEN) {
 		unsigned int rate = params_rate(hw_params);
 		unsigned int frames_per_period = params_period_size(hw_params);
 		unsigned int frames_per_buffer = params_buffer_size(hw_params);
@@ -252,7 +252,7 @@ static int pcm_hw_free(struct snd_pcm_substream *substream)
 
 	mutex_lock(&ff->mutex);
 
-	if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)
+	if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
 		--ff->substreams_counter;
 
 	snd_ff_stream_stop_duplex(ff);
sound/firewire/fireworks/fireworks_pcm.c +2 -2
index a0d5db1d8eb2..c3c21860b245 100644
@@ -250,7 +250,7 @@ static int pcm_hw_params(struct snd_pcm_substream *substream,
 	struct snd_efw *efw = substream->private_data;
 	int err = 0;
 
-	if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
+	if (substream->runtime->state == SNDRV_PCM_STATE_OPEN) {
 		unsigned int rate = params_rate(hw_params);
 		unsigned int frames_per_period = params_period_size(hw_params);
 		unsigned int frames_per_buffer = params_buffer_size(hw_params);
@@ -272,7 +272,7 @@ static int pcm_hw_free(struct snd_pcm_substream *substream)
 
 	mutex_lock(&efw->mutex);
 
-	if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)
+	if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
 		--efw->substreams_counter;
 
 	snd_efw_stream_stop_duplex(efw);
sound/firewire/motu/motu-pcm.c +2 -2
index 8e1437371263..d410c2efbde5 100644
@@ -210,7 +210,7 @@ static int pcm_hw_params(struct snd_pcm_substream *substream,
 	struct snd_motu *motu = substream->private_data;
 	int err = 0;
 
-	if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
+	if (substream->runtime->state == SNDRV_PCM_STATE_OPEN) {
 		unsigned int rate = params_rate(hw_params);
 		unsigned int frames_per_period = params_period_size(hw_params);
 		unsigned int frames_per_buffer = params_buffer_size(hw_params);
@@ -232,7 +232,7 @@ static int pcm_hw_free(struct snd_pcm_substream *substream)
 
 	mutex_lock(&motu->mutex);
 
-	if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)
+	if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
 		--motu->substreams_counter;
 
 	snd_motu_stream_stop_duplex(motu);
sound/firewire/oxfw/oxfw-pcm.c +4 -4
index 2dfa7e179cb6..5f43a0b826d2 100644
@@ -239,7 +239,7 @@ static int pcm_capture_hw_params(struct snd_pcm_substream *substream,
 	struct snd_oxfw *oxfw = substream->private_data;
 	int err = 0;
 
-	if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
+	if (substream->runtime->state == SNDRV_PCM_STATE_OPEN) {
 		unsigned int rate = params_rate(hw_params);
 		unsigned int channels = params_channels(hw_params);
 		unsigned int frames_per_period = params_period_size(hw_params);
@@ -262,7 +262,7 @@ static int pcm_playback_hw_params(struct snd_pcm_substream *substream,
 	struct snd_oxfw *oxfw = substream->private_data;
 	int err = 0;
 
-	if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
+	if (substream->runtime->state == SNDRV_PCM_STATE_OPEN) {
 		unsigned int rate = params_rate(hw_params);
 		unsigned int channels = params_channels(hw_params);
 		unsigned int frames_per_period = params_period_size(hw_params);
@@ -286,7 +286,7 @@ static int pcm_capture_hw_free(struct snd_pcm_substream *substream)
 
 	mutex_lock(&oxfw->mutex);
 
-	if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)
+	if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
 		--oxfw->substreams_count;
 
 	snd_oxfw_stream_stop_duplex(oxfw);
@@ -301,7 +301,7 @@ static int pcm_playback_hw_free(struct snd_pcm_substream *substream)
 
 	mutex_lock(&oxfw->mutex);
 
-	if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)
+	if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
 		--oxfw->substreams_count;
 
 	snd_oxfw_stream_stop_duplex(oxfw);
sound/firewire/tascam/tascam-pcm.c +2 -2
index 36c1353f2494..f6da571707ac 100644
@@ -119,7 +119,7 @@ static int pcm_hw_params(struct snd_pcm_substream *substream,
 	struct snd_tscm *tscm = substream->private_data;
 	int err = 0;
 
-	if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
+	if (substream->runtime->state == SNDRV_PCM_STATE_OPEN) {
 		unsigned int rate = params_rate(hw_params);
 		unsigned int frames_per_period = params_period_size(hw_params);
 		unsigned int frames_per_buffer = params_buffer_size(hw_params);
@@ -141,7 +141,7 @@ static int pcm_hw_free(struct snd_pcm_substream *substream)
 
 	mutex_lock(&tscm->mutex);
 
-	if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)
+	if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
 		--tscm->substreams_counter;
 
 	snd_tscm_stream_stop_duplex(tscm);
Signature · 1 line
2.35.3
#5 lore raw

PATCH 5/11 ALSA: hda: Replace runtime->status->state reference to runtime->state

In reply to Takashi Iwai

The recent change in ALSA core allows drivers to get the current PCM state directly from runtime object. Replace the calls accordingly.

---
 sound/hda/hdmi_chmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/hda/hdmi_chmap.c +1 -1
index aad5c4bf4d34..5d8e1d944b0a 100644
@@ -774,7 +774,7 @@ static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
 	substream = snd_pcm_chmap_substream(info, ctl_idx);
 	if (!substream || !substream->runtime)
 		return 0; /* just for avoiding error from alsactl restore */
-	switch (substream->runtime->status->state) {
+	switch (substream->runtime->state) {
 	case SNDRV_PCM_STATE_OPEN:
 	case SNDRV_PCM_STATE_SETUP:
 		break;
Signature · 1 line
2.35.3
#6 lore raw

PATCH 6/11 ALSA: asihpi: Replace runtime->status->state reference to runtime->state

In reply to Takashi Iwai

The recent change in ALSA core allows drivers to get the current PCM state directly from runtime object. Replace the calls accordingly.

---
 sound/pci/asihpi/asihpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/pci/asihpi/asihpi.c +1 -1
index 5e1f9f10051b..8de43aaa10aa 100644
@@ -632,7 +632,7 @@ static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
 
 			/*? workaround linked streams don't
 			transition to SETUP 20070706*/
-			s->runtime->status->state = SNDRV_PCM_STATE_SETUP;
+			__snd_pcm_set_state(s->runtime, SNDRV_PCM_STATE_SETUP);
 
 			if (card->support_grouping) {
 				snd_printdd("%d group\n", s->number);
Signature · 1 line
2.35.3
#7 lore raw

PATCH 7/11 ALSA: usb-audio: Replace runtime->status->state reference to runtime->state

In reply to Takashi Iwai

The recent change in ALSA core allows drivers to get the current PCM state directly from runtime object. Replace the calls accordingly.

---
 sound/usb/pcm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sound/usb/pcm.c +2 -2
index e721fc12acde..8ed165f036a0 100644
@@ -1395,7 +1395,7 @@ static int prepare_playback_urb(struct snd_usb_substream *subs,
 	transfer_done = subs->transfer_done;
 
 	if (subs->lowlatency_playback &&
-	    runtime->status->state != SNDRV_PCM_STATE_DRAINING) {
+	    runtime->state != SNDRV_PCM_STATE_DRAINING) {
 		unsigned int hwptr = subs->hwptr_done / stride;
 
 		/* calculate the byte offset-in-buffer of the appl_ptr */
@@ -1583,7 +1583,7 @@ static int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substrea
 		return 0;
 	case SNDRV_PCM_TRIGGER_SUSPEND:
 	case SNDRV_PCM_TRIGGER_STOP:
-		stop_endpoints(subs, substream->runtime->status->state == SNDRV_PCM_STATE_DRAINING);
+		stop_endpoints(subs, substream->runtime->state == SNDRV_PCM_STATE_DRAINING);
 		snd_usb_endpoint_set_callback(subs->data_endpoint,
 					      NULL, NULL, NULL);
 		subs->running = 0;
Signature · 1 line
2.35.3
#8 lore raw

PATCH 8/11 ALSA: usx2y: Replace runtime->status->state reference to runtime->state

In reply to Takashi Iwai

The recent change in ALSA core allows drivers to get the current PCM state directly from runtime object. Replace the calls accordingly.

---
 sound/usb/usx2y/usbusx2yaudio.c | 3 +--
 sound/usb/usx2y/usx2yhwdeppcm.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
sound/usb/usx2y/usbusx2yaudio.c +1 -2
index 9cd5e3aae4f7..5197599e7aa6 100644
@@ -822,8 +822,7 @@ static int snd_usx2y_pcm_hw_free(struct snd_pcm_substream *substream)
 		usx2y_urbs_release(subs);
 		if (!cap_subs->pcm_substream ||
 		    !cap_subs->pcm_substream->runtime ||
-		    !cap_subs->pcm_substream->runtime->status ||
-		    cap_subs->pcm_substream->runtime->status->state < SNDRV_PCM_STATE_PREPARED) {
+		    cap_subs->pcm_substream->runtime->state < SNDRV_PCM_STATE_PREPARED) {
 			atomic_set(&cap_subs->state, STATE_STOPPED);
 			usx2y_urbs_release(cap_subs);
 		}
sound/usb/usx2y/usx2yhwdeppcm.c +1 -2
index 240349b644f3..767a227d54da 100644
@@ -374,8 +374,7 @@ static int snd_usx2y_usbpcm_hw_free(struct snd_pcm_substream *substream)
 		usx2y_usbpcm_urbs_release(subs);
 		if (!cap_subs->pcm_substream ||
 		    !cap_subs->pcm_substream->runtime ||
-		    !cap_subs->pcm_substream->runtime->status ||
-		    cap_subs->pcm_substream->runtime->status->state < SNDRV_PCM_STATE_PREPARED) {
+		    cap_subs->pcm_substream->runtime->state < SNDRV_PCM_STATE_PREPARED) {
 			atomic_set(&cap_subs->state, STATE_STOPPED);
 			if (cap_subs2)
 				atomic_set(&cap_subs2->state, STATE_STOPPED);
Signature · 1 line
2.35.3
#9 lore raw

PATCH 9/11 ASoC: intel: Replace runtime->status->state reference to runtime->state

In reply to Takashi Iwai

The recent change in ALSA core allows drivers to get the current PCM state directly from runtime object. Replace the calls accordingly.

Cc Cezary Rojewski <[email protected]>
Cc Pierre-Louis Bossart <[email protected]>
Cc Liam Girdwood <[email protected]>
Cc Peter Ujfalusi <[email protected]>
Cc Bard Liao <[email protected]>
Cc Ranjani Sridharan <[email protected]>
Cc Kai Vehmanen <[email protected]>
Cc Mark Brown <[email protected]>

---

I'm going to merge this through my sound git tree as it requires ALSA core changes.

 sound/soc/intel/skylake/skl-pcm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/intel/skylake/skl-pcm.c +2 -2
index 9d72ebd812af..1015716f9336 100644
@@ -275,7 +275,7 @@ static int skl_pcm_prepare(struct snd_pcm_substream *substream,
 	 * calls prepare another time, reset the FW pipe to clean state
 	 */
 	if (mconfig &&
-		(substream->runtime->status->state == SNDRV_PCM_STATE_XRUN ||
+		(substream->runtime->state == SNDRV_PCM_STATE_XRUN ||
 		 mconfig->pipe->state == SKL_PIPE_CREATED ||
 		 mconfig->pipe->state == SKL_PIPE_PAUSED)) {
 
@@ -593,7 +593,7 @@ static int skl_link_pcm_prepare(struct snd_pcm_substream *substream,
 	/* In case of XRUN recovery, reset the FW pipe to clean state */
 	mconfig = skl_tplg_be_get_cpr_module(dai, substream->stream);
 	if (mconfig && !mconfig->pipe->passthru &&
-		(substream->runtime->status->state == SNDRV_PCM_STATE_XRUN))
+		(substream->runtime->state == SNDRV_PCM_STATE_XRUN))
 		skl_reset_pipe(skl, mconfig->pipe);
 
 	return 0;
Signature · 1 line
2.35.3
maintainer Acked-by on v1 9/11
#10 lore raw

Re: [PATCH 09/11] ASoC: intel: Replace runtime->status->state reference to runtime->state

Quoted 2 lines · Takashi Iwai

The recent change in ALSA core allows drivers to get the current PCM state directly from runtime object. Replace the calls accordingly.

#11 lore raw

PATCH 10/11 ASoC: sh: Replace runtime->status->state reference to runtime->state

In reply to Takashi Iwai

The recent change in ALSA core allows drivers to get the current PCM state directly from runtime object. Replace the calls accordingly.

---

I'm going to merge this through my sound git tree as it requires ALSA core changes.

 sound/soc/sh/rz-ssi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/sh/rz-ssi.c +1 -1
index 7ace0c0db5b1..5d6bae33ae34 100644
@@ -598,7 +598,7 @@ static int rz_ssi_dma_transfer(struct rz_ssi_priv *ssi,
 		return -EINVAL;
 
 	runtime = substream->runtime;
-	if (runtime->status->state == SNDRV_PCM_STATE_DRAINING)
+	if (runtime->state == SNDRV_PCM_STATE_DRAINING)
 		/*
 		 * Stream is ending, so do not queue up any more DMA
 		 * transfers otherwise we play partial sound clips
Signature · 1 line
2.35.3
maintainer Acked-by on v1 10/11
#12 lore raw

Re: [PATCH 10/11] ASoC: sh: Replace runtime->status->state reference to runtime->state

Quoted 2 lines · Takashi Iwai

The recent change in ALSA core allows drivers to get the current PCM state directly from runtime object. Replace the calls accordingly.

#13 lore raw

PATCH 11/11 usb: gadget: Replace runtime->status->state reference to runtime->state

In reply to Takashi Iwai

The recent change in ALSA core allows drivers to get the current PCM state directly from runtime object. Replace the calls accordingly.

Cc Felipe Balbi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>

---

I'm going to merge this through sound git tree as it requires ALSA core changes.

 drivers/usb/gadget/function/u_uac1_legacy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/gadget/function/u_uac1_legacy.c +2 -2
index 60ae8b2d3f6a..dd21c251542c 100644
@@ -158,8 +158,8 @@ size_t u_audio_playback(struct gaudio *card, void *buf, size_t count)
 	snd_pcm_sframes_t frames;
 
 try_again:
-	if (runtime->status->state == SNDRV_PCM_STATE_XRUN ||
-		runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) {
+	if (runtime->state == SNDRV_PCM_STATE_XRUN ||
+		runtime->state == SNDRV_PCM_STATE_SUSPENDED) {
 		result = snd_pcm_kernel_ioctl(substream,
 				SNDRV_PCM_IOCTL_PREPARE, NULL);
 		if (result < 0) {
Signature · 1 line
2.35.3
maintainer Reviewed-by on v1 11/11
#14 lore raw

Re: [PATCH 11/11] usb: gadget: Replace runtime->status->state reference to runtime->state

Quoted 10 lines · Takashi Iwai

The recent change in ALSA core allows drivers to get the current PCM state directly from runtime object. Replace the calls accordingly.

Cc Felipe Balbi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>

---

I'm going to merge this through sound git tree as it requires ALSA core changes.

Looks good to me:

maintainer Reviewed-by on the v1 series
#15 lore raw
In reply to Takashi Iwai
Quoted 24 lines · Takashi Iwai

Hi,

this is a patch set for simplifying the reference to the current PCM state by having the local copy in runtime instead of relying on runtime->status indirection. This also hardens against the attack by modifying the mmapped status record.

The first patch does the basic job in the core PCM side, and the second patch flips the PCM status mmap to read-only for hardening, while the remaining patches are for drivers to follow the core change.

The conversions are straightforward. In most places, it's just replacing runtime->status->state with runtime->state.

Takashi

===

Takashi Iwai (11):
ALSA: pcm: Avoid reference to status->state
ALSA: pcm: Make mmap status read-only
ALSA: aloop: Replace runtime->status->state reference to

Quoted 15 lines
     runtime->state
   ALSA: firewire: Replace runtime->status->state reference to
     runtime->state
   ALSA: hda: Replace runtime->status->state reference to runtime->state
   ALSA: asihpi: Replace runtime->status->state reference to
     runtime->state
   ALSA: usb-audio: Replace runtime->status->state reference to
     runtime->state
   ALSA: usx2y: Replace runtime->status->state reference to
     runtime->state
   ASoC: intel: Replace runtime->status->state reference to
     runtime->state
   ASoC: sh: Replace runtime->status->state reference to runtime->state
   usb: gadget: Replace runtime->status->state reference to
     runtime->state

Nice cleanup. Perhaps, you may add a note to the second patch that the status is already mmaped as read-only in alsa-lib for ages. So no regressions are expected.

Signature · 2 lines
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
#16 lore raw
Quoted 42 lines · Jaroslav Kysela
Quoted 24 lines · Takashi Iwai

Hi,

this is a patch set for simplifying the reference to the current PCM state by having the local copy in runtime instead of relying on runtime->status indirection. This also hardens against the attack by modifying the mmapped status record.

The first patch does the basic job in the core PCM side, and the second patch flips the PCM status mmap to read-only for hardening, while the remaining patches are for drivers to follow the core change.

The conversions are straightforward. In most places, it's just replacing runtime->status->state with runtime->state.

Takashi

===

Takashi Iwai (11):
ALSA: pcm: Avoid reference to status->state
ALSA: pcm: Make mmap status read-only
ALSA: aloop: Replace runtime->status->state reference to

Quoted 15 lines
     runtime->state
   ALSA: firewire: Replace runtime->status->state reference to
     runtime->state
   ALSA: hda: Replace runtime->status->state reference to runtime->state
   ALSA: asihpi: Replace runtime->status->state reference to
     runtime->state
   ALSA: usb-audio: Replace runtime->status->state reference to
     runtime->state
   ALSA: usx2y: Replace runtime->status->state reference to
     runtime->state
   ASoC: intel: Replace runtime->status->state reference to
     runtime->state
   ASoC: sh: Replace runtime->status->state reference to runtime->state
   usb: gadget: Replace runtime->status->state reference to
     runtime->state
Quoted 3 lines

Nice cleanup. Perhaps, you may add a note to the second patch that the status is already mmaped as read-only in alsa-lib for ages. So no regressions are expected.

Makes sense. Will add some text.

thanks,

Takashi

maintainer
#17 lore raw
In reply to Takashi Iwai

Hi,

Quoted 6 lines · Takashi Iwai

Hi,

this is a patch set for simplifying the reference to the current PCM state by having the local copy in runtime instead of relying on runtime->status indirection. This also hardens against the attack by modifying the mmapped status record.

The overall patches looks good to me and I have no objections, while I have some slight opinions to them in a place of sound driver developer.

Quoted 1 line

The first patch does the basic job in the core PCM side,

The main concern is indirect accessing to state field via some pointer hops. I think addition of helper macro at first step eases centre of your work, like:

```
diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index 8c48a5bce88c..f6a160cb8135 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -669,6 +669,20 @@ void snd_pcm_stream_unlock_irqrestore(struct snd_pcm_substream *substream,
             stream <= SNDRV_PCM_STREAM_LAST;           \
             stream++)
 
+/**
+ * snd_pcm_stream_state - Return state in runtime of the PCM substream.
+ * @substream: substream to check. runtime should be attached.
+ *
+ * Return state in runtime of the PCM substream. The substream should exists and
+ * runtime should be attached to it.
+ */
+static inline snd_pcm_state_t snd_pcm_stream_state(const snd_pcm_substream *substream)
+{
+       snd_BUG_ON(!(sub) || !(sub)->runtime);
+
+       return substream->runtime->status->state;
+}
```

As we can see, sound driver programmer sometimes checks state of runtime in their code, thus the macro could helps them as well as centre of your change.

Quoted 2 lines

and the
second patch flips the PCM status mmap to read-only for hardening,

The patch looks good to me as well as the patch for asihpi driver, and should be in your tree independent from the others.

Quoted 5 lines

while the remaining patches are for drivers to follow the core change.

The conversions are straightforward. In most places, it's just replacing runtime->status->state with runtime->state.

The usage of mentioned macro can control the concerned access. Now addition of new field, state to runtime structure can be done easily.

Quoted 51 lines

Takashi

===

Takashi Iwai (11):
ALSA: pcm: Avoid reference to status->state
ALSA: pcm: Make mmap status read-only
ALSA: aloop: Replace runtime->status->state reference to

    runtime->state
  ALSA: firewire: Replace runtime->status->state reference to
    runtime->state
  ALSA: hda: Replace runtime->status->state reference to runtime->state
  ALSA: asihpi: Replace runtime->status->state reference to
    runtime->state
  ALSA: usb-audio: Replace runtime->status->state reference to
    runtime->state
  ALSA: usx2y: Replace runtime->status->state reference to
    runtime->state
  ASoC: intel: Replace runtime->status->state reference to
    runtime->state
  ASoC: sh: Replace runtime->status->state reference to runtime->state
  usb: gadget: Replace runtime->status->state reference to
    runtime->state
 drivers/usb/gadget/function/u_uac1_legacy.c |   4 +-
 include/sound/pcm.h                         |  20 ++-
 sound/core/oss/pcm_oss.c                    |  42 +++----
 sound/core/pcm.c                            |   9 +-
 sound/core/pcm_compat.c                     |   4 +-
 sound/core/pcm_lib.c                        |  16 +--
 sound/core/pcm_native.c                     | 128 ++++++++++----------
 sound/drivers/aloop.c                       |   4 +-
 sound/firewire/bebob/bebob_pcm.c            |   4 +-
 sound/firewire/dice/dice-pcm.c              |   4 +-
 sound/firewire/digi00x/digi00x-pcm.c        |   4 +-
 sound/firewire/fireface/ff-pcm.c            |   4 +-
 sound/firewire/fireworks/fireworks_pcm.c    |   4 +-
 sound/firewire/motu/motu-pcm.c              |   4 +-
 sound/firewire/oxfw/oxfw-pcm.c              |   8 +-
 sound/firewire/tascam/tascam-pcm.c          |   4 +-
 sound/hda/hdmi_chmap.c                      |   2 +-
 sound/pci/asihpi/asihpi.c                   |   2 +-
 sound/soc/intel/skylake/skl-pcm.c           |   4 +-
 sound/soc/sh/rz-ssi.c                       |   2 +-
 sound/usb/pcm.c                             |   4 +-
 sound/usb/usx2y/usbusx2yaudio.c             |   3 +-
 sound/usb/usx2y/usx2yhwdeppcm.c             |   3 +-
 23 files changed, 150 insertions(+), 133 deletions(-)

===

Quoted 14 lines
Cc Bard Liao <[email protected]>
Cc Cezary Rojewski <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Kai Vehmanen <[email protected]>
Cc Liam Girdwood <[email protected]>
Cc Mark Brown <[email protected]>
Cc Peter Ujfalusi <[email protected]>
Cc Pierre-Louis Bossart <[email protected]>
Cc Ranjani Sridharan <[email protected]>
Cc Takashi Sakamoto <[email protected]>
Signature · 1 line
2.35.3

Regards

Takashi Sakamoto

#18 lore raw
Quoted 44 lines · Takashi Sakamoto

Hi,

Quoted 6 lines · Takashi Iwai

Hi,

this is a patch set for simplifying the reference to the current PCM state by having the local copy in runtime instead of relying on runtime->status indirection. This also hardens against the attack by modifying the mmapped status record.

The overall patches looks good to me and I have no objections, while I have some slight opinions to them in a place of sound driver developer.

Quoted 1 line

The first patch does the basic job in the core PCM side,

The main concern is indirect accessing to state field via some pointer hops. I think addition of helper macro at first step eases centre of your work, like:

```

include/sound/pcm.h +13 -0
index 8c48a5bce88c..f6a160cb8135 100644
@@ -669,6 +669,20 @@ void snd_pcm_stream_unlock_irqrestore(struct snd_pcm_substream *substream,
             stream <= SNDRV_PCM_STREAM_LAST;           \
             stream++)
 
+/**
+ * snd_pcm_stream_state - Return state in runtime of the PCM substream.
+ * @substream: substream to check. runtime should be attached.
+ *
+ * Return state in runtime of the PCM substream. The substream should exists and
+ * runtime should be attached to it.
+ */
+static inline snd_pcm_state_t snd_pcm_stream_state(const snd_pcm_substream *substream)
+{
+       snd_BUG_ON(!(sub) || !(sub)->runtime);
+
+       return substream->runtime->status->state;
+}

```

Quoted 3 lines

As we can see, sound driver programmer sometimes checks state of runtime in their code, thus the macro could helps them as well as centre of your change.

This might help if we may need any change in future again.

But the NULL check is superfluous in most places, and the state check is done often in a hot path, it's better to rip off. So it's only about the read of runtime->state, and then it's doubtful whether it brings much value at this moment; that's the reason I didn't introduce such a macro for now.

Takashi

maintainer
#19 lore raw
Quoted 52 lines · Takashi Iwai
Quoted 44 lines · Takashi Sakamoto

Hi,

Quoted 6 lines · Takashi Iwai

Hi,

this is a patch set for simplifying the reference to the current PCM state by having the local copy in runtime instead of relying on runtime->status indirection. This also hardens against the attack by modifying the mmapped status record.

The overall patches looks good to me and I have no objections, while I have some slight opinions to them in a place of sound driver developer.

Quoted 1 line

The first patch does the basic job in the core PCM side,

The main concern is indirect accessing to state field via some pointer hops. I think addition of helper macro at first step eases centre of your work, like:

```

include/sound/pcm.h +13 -0
index 8c48a5bce88c..f6a160cb8135 100644
@@ -669,6 +669,20 @@ void snd_pcm_stream_unlock_irqrestore(struct snd_pcm_substream *substream,
             stream <= SNDRV_PCM_STREAM_LAST;           \
             stream++)
 
+/**
+ * snd_pcm_stream_state - Return state in runtime of the PCM substream.
+ * @substream: substream to check. runtime should be attached.
+ *
+ * Return state in runtime of the PCM substream. The substream should exists and
+ * runtime should be attached to it.
+ */
+static inline snd_pcm_state_t snd_pcm_stream_state(const snd_pcm_substream *substream)
+{
+       snd_BUG_ON(!(sub) || !(sub)->runtime);
+
+       return substream->runtime->status->state;
+}

```

Quoted 3 lines

As we can see, sound driver programmer sometimes checks state of runtime in their code, thus the macro could helps them as well as centre of your change.

This might help if we may need any change in future again.

Quoted 5 lines

But the NULL check is superfluous in most places, and the state check is done often in a hot path, it's better to rip off. So it's only about the read of runtime->state, and then it's doubtful whether it brings much value at this moment; that's the reason I didn't introduce such a macro for now.

Yes, so I have no strong suggestion to introduce the macro and no objections to apply the patches as is.

I'm too conservative developer and consider about usage of memory barrier always when seeing such state check since we should pay enough attension to instruction reordering and concurrent accesses across processors for such case. Fortunately we have no reports for such issue yet. When posting the last message, it was on my mind and it's still.

Regards

Takashi Sakamoto