Commit 96295812 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: pcm: Fix negative appl_ptr handling in pcm-indirect helpers

The indirect-PCM helper codes have an implicit assumption that the
appl_ptr always increases.  But the PCM core may deal with the
decrement of appl_ptr via rewind ioctls, and it may screw up the
buffer pointer management.

This patch adds the negative appl_ptr diff in transfer functions and
let returning an error instead of always accepting the appl_ptr
updates.  The callers are usually PCM ack callbacks, and they pass the
error to the upper layer accordingly.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 6dbaf8b9
...@@ -43,7 +43,7 @@ typedef void (*snd_pcm_indirect_copy_t)(struct snd_pcm_substream *substream, ...@@ -43,7 +43,7 @@ typedef void (*snd_pcm_indirect_copy_t)(struct snd_pcm_substream *substream,
/* /*
* helper function for playback ack callback * helper function for playback ack callback
*/ */
static inline void static inline int
snd_pcm_indirect_playback_transfer(struct snd_pcm_substream *substream, snd_pcm_indirect_playback_transfer(struct snd_pcm_substream *substream,
struct snd_pcm_indirect *rec, struct snd_pcm_indirect *rec,
snd_pcm_indirect_copy_t copy) snd_pcm_indirect_copy_t copy)
...@@ -56,6 +56,8 @@ snd_pcm_indirect_playback_transfer(struct snd_pcm_substream *substream, ...@@ -56,6 +56,8 @@ snd_pcm_indirect_playback_transfer(struct snd_pcm_substream *substream,
if (diff) { if (diff) {
if (diff < -(snd_pcm_sframes_t) (runtime->boundary / 2)) if (diff < -(snd_pcm_sframes_t) (runtime->boundary / 2))
diff += runtime->boundary; diff += runtime->boundary;
if (diff < 0)
return -EINVAL;
rec->sw_ready += (int)frames_to_bytes(runtime, diff); rec->sw_ready += (int)frames_to_bytes(runtime, diff);
rec->appl_ptr = appl_ptr; rec->appl_ptr = appl_ptr;
} }
...@@ -82,6 +84,7 @@ snd_pcm_indirect_playback_transfer(struct snd_pcm_substream *substream, ...@@ -82,6 +84,7 @@ snd_pcm_indirect_playback_transfer(struct snd_pcm_substream *substream,
rec->hw_ready += bytes; rec->hw_ready += bytes;
rec->sw_ready -= bytes; rec->sw_ready -= bytes;
} }
return 0;
} }
/* /*
...@@ -109,7 +112,7 @@ snd_pcm_indirect_playback_pointer(struct snd_pcm_substream *substream, ...@@ -109,7 +112,7 @@ snd_pcm_indirect_playback_pointer(struct snd_pcm_substream *substream,
/* /*
* helper function for capture ack callback * helper function for capture ack callback
*/ */
static inline void static inline int
snd_pcm_indirect_capture_transfer(struct snd_pcm_substream *substream, snd_pcm_indirect_capture_transfer(struct snd_pcm_substream *substream,
struct snd_pcm_indirect *rec, struct snd_pcm_indirect *rec,
snd_pcm_indirect_copy_t copy) snd_pcm_indirect_copy_t copy)
...@@ -121,6 +124,8 @@ snd_pcm_indirect_capture_transfer(struct snd_pcm_substream *substream, ...@@ -121,6 +124,8 @@ snd_pcm_indirect_capture_transfer(struct snd_pcm_substream *substream,
if (diff) { if (diff) {
if (diff < -(snd_pcm_sframes_t) (runtime->boundary / 2)) if (diff < -(snd_pcm_sframes_t) (runtime->boundary / 2))
diff += runtime->boundary; diff += runtime->boundary;
if (diff < 0)
return -EINVAL;
rec->sw_ready -= frames_to_bytes(runtime, diff); rec->sw_ready -= frames_to_bytes(runtime, diff);
rec->appl_ptr = appl_ptr; rec->appl_ptr = appl_ptr;
} }
...@@ -147,6 +152,7 @@ snd_pcm_indirect_capture_transfer(struct snd_pcm_substream *substream, ...@@ -147,6 +152,7 @@ snd_pcm_indirect_capture_transfer(struct snd_pcm_substream *substream,
rec->hw_ready -= bytes; rec->hw_ready -= bytes;
rec->sw_ready += bytes; rec->sw_ready += bytes;
} }
return 0;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment