[PATCH v28 16/17] ALSA: pcm: add an explicit application pointer to indirect playback transfer
From: Joonho Lee
Date: Wed Nov 11 2026 - 23:52:23 EST
The indirect playback transfer helper samples runtime->control->appl_ptr
internally. A driver that needs to refill already committed data from a
pointer callback cannot pass the application-pointer snapshot used for
ACK validation.
Add snd_pcm_indirect_playback_transfer_appl_ptr() so callers can supply
that snapshot. Keep snd_pcm_indirect_playback_transfer() as a wrapper
that samples the runtime pointer as before, preserving existing callers.
The explicit-pointer form lets virtio refill accepted data without
accepting new application progress while the ALSA buffer-access gate is
closed.
Assisted-by: LLM
Signed-off-by: Joonho Lee <mynameisjune111@xxxxxxxxx>
---
include/sound/pcm-indirect.h | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/include/sound/pcm-indirect.h b/include/sound/pcm-indirect.h
--- a/include/sound/pcm-indirect.h
+++ b/include/sound/pcm-indirect.h
@@ -28,15 +28,17 @@
struct snd_pcm_indirect *rec, size_t bytes);
/*
- * helper function for playback ack callback
+ * Playback transfer using a caller-supplied application pointer snapshot.
+ * Passing rec->appl_ptr refills previously accepted data without accepting
+ * additional application progress.
*/
static inline int
-snd_pcm_indirect_playback_transfer(struct snd_pcm_substream *substream,
- struct snd_pcm_indirect *rec,
- snd_pcm_indirect_copy_t copy)
+snd_pcm_indirect_playback_transfer_appl_ptr(struct snd_pcm_substream *substream,
+ struct snd_pcm_indirect *rec,
+ snd_pcm_indirect_copy_t copy,
+ snd_pcm_uframes_t appl_ptr)
{
struct snd_pcm_runtime *runtime = substream->runtime;
- snd_pcm_uframes_t appl_ptr = runtime->control->appl_ptr;
snd_pcm_sframes_t diff = appl_ptr - rec->appl_ptr;
int qsize;
@@ -72,6 +74,18 @@
rec->sw_ready -= bytes;
}
return 0;
+}
+
+/* Preserve the application pointer sampling of the ordinary ACK helper. */
+static inline int
+snd_pcm_indirect_playback_transfer(struct snd_pcm_substream *substream,
+ struct snd_pcm_indirect *rec,
+ snd_pcm_indirect_copy_t copy)
+{
+ snd_pcm_uframes_t appl_ptr = substream->runtime->control->appl_ptr;
+
+ return snd_pcm_indirect_playback_transfer_appl_ptr(substream, rec, copy,
+ appl_ptr);
}
/*