Skip to content

Commit 4285de0

Browse files
committed
ALSA: pcm: oss: Place the plugin buffer overflow checks correctly
The checks of the plugin buffer overflow in the previous fix by commit f2ecf90 ("ALSA: pcm: oss: Avoid plugin buffer overflow") are put in the wrong places mistakenly, which leads to the expected (repeated) sound when the rate plugin is involved. Fix in the right places. Also, at those right places, the zero check is needed for the termination node, so added there as well, and let's get it done, finally. Fixes: f2ecf90 ("ALSA: pcm: oss: Avoid plugin buffer overflow") Cc: <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent ae769d3 commit 4285de0

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

sound/core/oss/pcm_plugin.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,21 +211,23 @@ static snd_pcm_sframes_t plug_client_size(struct snd_pcm_substream *plug,
211211
if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
212212
plugin = snd_pcm_plug_last(plug);
213213
while (plugin && drv_frames > 0) {
214-
if (check_size && drv_frames > plugin->buf_frames)
215-
drv_frames = plugin->buf_frames;
216214
plugin_prev = plugin->prev;
217215
if (plugin->src_frames)
218216
drv_frames = plugin->src_frames(plugin, drv_frames);
217+
if (check_size && plugin->buf_frames &&
218+
drv_frames > plugin->buf_frames)
219+
drv_frames = plugin->buf_frames;
219220
plugin = plugin_prev;
220221
}
221222
} else if (stream == SNDRV_PCM_STREAM_CAPTURE) {
222223
plugin = snd_pcm_plug_first(plug);
223224
while (plugin && drv_frames > 0) {
224225
plugin_next = plugin->next;
226+
if (check_size && plugin->buf_frames &&
227+
drv_frames > plugin->buf_frames)
228+
drv_frames = plugin->buf_frames;
225229
if (plugin->dst_frames)
226230
drv_frames = plugin->dst_frames(plugin, drv_frames);
227-
if (check_size && drv_frames > plugin->buf_frames)
228-
drv_frames = plugin->buf_frames;
229231
plugin = plugin_next;
230232
}
231233
} else
@@ -251,26 +253,28 @@ static snd_pcm_sframes_t plug_slave_size(struct snd_pcm_substream *plug,
251253
plugin = snd_pcm_plug_first(plug);
252254
while (plugin && frames > 0) {
253255
plugin_next = plugin->next;
256+
if (check_size && plugin->buf_frames &&
257+
frames > plugin->buf_frames)
258+
frames = plugin->buf_frames;
254259
if (plugin->dst_frames) {
255260
frames = plugin->dst_frames(plugin, frames);
256261
if (frames < 0)
257262
return frames;
258263
}
259-
if (check_size && frames > plugin->buf_frames)
260-
frames = plugin->buf_frames;
261264
plugin = plugin_next;
262265
}
263266
} else if (stream == SNDRV_PCM_STREAM_CAPTURE) {
264267
plugin = snd_pcm_plug_last(plug);
265268
while (plugin) {
266-
if (check_size && frames > plugin->buf_frames)
267-
frames = plugin->buf_frames;
268269
plugin_prev = plugin->prev;
269270
if (plugin->src_frames) {
270271
frames = plugin->src_frames(plugin, frames);
271272
if (frames < 0)
272273
return frames;
273274
}
275+
if (check_size && plugin->buf_frames &&
276+
frames > plugin->buf_frames)
277+
frames = plugin->buf_frames;
274278
plugin = plugin_prev;
275279
}
276280
} else

0 commit comments

Comments
 (0)