From: Takashi Iwai <tiwai@suse.de> To: alsa-devel@alsa-project.org Cc: Stefan Wahren <stefan.wahren@i2se.com>, Lee Jones <lee@kernel.org>, Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>, Jaikrishna Nemallapudi <jaikrishnax.nemallapudi@intel.com>, Eric Anholt <eric@anholt.net>, linux-rpi-kernel@lists.infradead.org, "Subhransu S . Prusty" <subhransu.s.prusty@intel.com>, linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/7] ALSA: pcm: Fix negative appl_ptr handling in pcm-indirect helpers Date: Sun, 21 May 2017 21:02:52 +0200 [thread overview] Message-ID: <20170521190258.1178-2-tiwai@suse.de> (raw) In-Reply-To: <20170521190258.1178-1-tiwai@suse.de> 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: Takashi Iwai <tiwai@suse.de> --- include/sound/pcm-indirect.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/sound/pcm-indirect.h b/include/sound/pcm-indirect.h index 1df7acaaa535..7ade285328cf 100644 --- a/include/sound/pcm-indirect.h +++ b/include/sound/pcm-indirect.h @@ -43,7 +43,7 @@ typedef void (*snd_pcm_indirect_copy_t)(struct snd_pcm_substream *substream, /* * helper function for playback ack callback */ -static inline void +static inline int snd_pcm_indirect_playback_transfer(struct snd_pcm_substream *substream, struct snd_pcm_indirect *rec, snd_pcm_indirect_copy_t copy) @@ -56,6 +56,8 @@ snd_pcm_indirect_playback_transfer(struct snd_pcm_substream *substream, if (diff) { if (diff < -(snd_pcm_sframes_t) (runtime->boundary / 2)) diff += runtime->boundary; + if (diff < 0) + return -EINVAL; rec->sw_ready += (int)frames_to_bytes(runtime, diff); rec->appl_ptr = appl_ptr; } @@ -82,6 +84,7 @@ snd_pcm_indirect_playback_transfer(struct snd_pcm_substream *substream, rec->hw_ready += bytes; rec->sw_ready -= bytes; } + return 0; } /* @@ -109,7 +112,7 @@ snd_pcm_indirect_playback_pointer(struct snd_pcm_substream *substream, /* * helper function for capture ack callback */ -static inline void +static inline int snd_pcm_indirect_capture_transfer(struct snd_pcm_substream *substream, struct snd_pcm_indirect *rec, snd_pcm_indirect_copy_t copy) @@ -121,6 +124,8 @@ snd_pcm_indirect_capture_transfer(struct snd_pcm_substream *substream, if (diff) { if (diff < -(snd_pcm_sframes_t) (runtime->boundary / 2)) diff += runtime->boundary; + if (diff < 0) + return -EINVAL; rec->sw_ready -= frames_to_bytes(runtime, diff); rec->appl_ptr = appl_ptr; } @@ -147,6 +152,7 @@ snd_pcm_indirect_capture_transfer(struct snd_pcm_substream *substream, rec->hw_ready -= bytes; rec->sw_ready += bytes; } + return 0; } /* -- 2.13.0
WARNING: multiple messages have this Message-ID (diff)
From: tiwai@suse.de (Takashi Iwai) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/7] ALSA: pcm: Fix negative appl_ptr handling in pcm-indirect helpers Date: Sun, 21 May 2017 21:02:52 +0200 [thread overview] Message-ID: <20170521190258.1178-2-tiwai@suse.de> (raw) In-Reply-To: <20170521190258.1178-1-tiwai@suse.de> 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: Takashi Iwai <tiwai@suse.de> --- include/sound/pcm-indirect.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/sound/pcm-indirect.h b/include/sound/pcm-indirect.h index 1df7acaaa535..7ade285328cf 100644 --- a/include/sound/pcm-indirect.h +++ b/include/sound/pcm-indirect.h @@ -43,7 +43,7 @@ typedef void (*snd_pcm_indirect_copy_t)(struct snd_pcm_substream *substream, /* * helper function for playback ack callback */ -static inline void +static inline int snd_pcm_indirect_playback_transfer(struct snd_pcm_substream *substream, struct snd_pcm_indirect *rec, snd_pcm_indirect_copy_t copy) @@ -56,6 +56,8 @@ snd_pcm_indirect_playback_transfer(struct snd_pcm_substream *substream, if (diff) { if (diff < -(snd_pcm_sframes_t) (runtime->boundary / 2)) diff += runtime->boundary; + if (diff < 0) + return -EINVAL; rec->sw_ready += (int)frames_to_bytes(runtime, diff); rec->appl_ptr = appl_ptr; } @@ -82,6 +84,7 @@ snd_pcm_indirect_playback_transfer(struct snd_pcm_substream *substream, rec->hw_ready += bytes; rec->sw_ready -= bytes; } + return 0; } /* @@ -109,7 +112,7 @@ snd_pcm_indirect_playback_pointer(struct snd_pcm_substream *substream, /* * helper function for capture ack callback */ -static inline void +static inline int snd_pcm_indirect_capture_transfer(struct snd_pcm_substream *substream, struct snd_pcm_indirect *rec, snd_pcm_indirect_copy_t copy) @@ -121,6 +124,8 @@ snd_pcm_indirect_capture_transfer(struct snd_pcm_substream *substream, if (diff) { if (diff < -(snd_pcm_sframes_t) (runtime->boundary / 2)) diff += runtime->boundary; + if (diff < 0) + return -EINVAL; rec->sw_ready -= frames_to_bytes(runtime, diff); rec->appl_ptr = appl_ptr; } @@ -147,6 +152,7 @@ snd_pcm_indirect_capture_transfer(struct snd_pcm_substream *substream, rec->hw_ready -= bytes; rec->sw_ready += bytes; } + return 0; } /* -- 2.13.0
next prev parent reply other threads:[~2017-05-21 19:03 UTC|newest] Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top 2017-05-21 19:02 [PATCH 0/7] ALSA: Fix/improve PCM ack callback Takashi Iwai 2017-05-21 19:02 ` Takashi Iwai 2017-05-21 19:02 ` Takashi Iwai [this message] 2017-05-21 19:02 ` [PATCH 1/7] ALSA: pcm: Fix negative appl_ptr handling in pcm-indirect helpers Takashi Iwai [not found] ` <20170521190258.1178-1-tiwai-l3A5Bk7waGM@public.gmane.org> 2017-05-21 19:02 ` [PATCH 2/7] ALSA: mips: Deliver indirect-PCM transfer error Takashi Iwai 2017-05-21 19:02 ` Takashi Iwai 2017-05-21 19:02 ` [PATCH 3/7] ALSA: cs46xx: " Takashi Iwai 2017-05-21 19:02 ` Takashi Iwai 2017-05-21 19:02 ` [PATCH 4/7] ALSA: emu10k1: " Takashi Iwai 2017-05-21 19:02 ` Takashi Iwai 2017-05-21 19:02 ` [PATCH 5/7] ALSA: rme32: " Takashi Iwai 2017-05-21 19:02 ` Takashi Iwai 2017-05-21 19:02 ` [PATCH 6/7] staging: bcm2835-audio: " Takashi Iwai 2017-05-21 19:02 ` Takashi Iwai 2017-05-22 16:33 ` Eric Anholt 2017-05-22 16:33 ` Eric Anholt 2017-05-21 19:02 ` [PATCH 7/7] ALSA: pcm: Call ack() whenever appl_ptr is updated Takashi Iwai 2017-05-21 19:02 ` Takashi Iwai 2017-05-22 3:49 ` [PATCH 0/7] ALSA: Fix/improve PCM ack callback Takashi Sakamoto 2017-05-22 3:49 ` Takashi Sakamoto 2017-05-22 5:27 ` Takashi Iwai 2017-05-22 5:27 ` Takashi Iwai 2017-05-22 6:31 ` Takashi Sakamoto 2017-05-22 6:31 ` Takashi Sakamoto 2017-05-22 6:46 ` Takashi Iwai 2017-05-22 6:46 ` Takashi Iwai 2017-05-22 7:07 ` Takashi Iwai 2017-05-22 7:07 ` Takashi Iwai 2017-05-25 21:39 ` Takashi Iwai
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=20170521190258.1178-2-tiwai@suse.de \ --to=tiwai@suse.de \ --cc=alsa-devel@alsa-project.org \ --cc=eric@anholt.net \ --cc=jaikrishnax.nemallapudi@intel.com \ --cc=lee@kernel.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-rpi-kernel@lists.infradead.org \ --cc=pierre-louis.bossart@linux.intel.com \ --cc=stefan.wahren@i2se.com \ --cc=subhransu.s.prusty@intel.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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.