mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] ALSA: linear: Check frame count for all channels
@ 2026-11-05 14:22 Sreeraj S Kurup
  2026-11-05 15:08 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Sreeraj S Kurup @ 2026-11-05 14:22 UTC (permalink / raw)
  To: perex, tiwai, tiwai; +Cc: linux-kernel, linux-sound, Sreeraj S Kurup

linear_transfer() checks the available frame count only for
the first destination channel.

Check the available frame count of all source and destination
channels before converting samples.

Use the smallest available frame count to make sure that
conversion does not read or write beyond the channel buffers.

Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
v2:
  Add missing mailing-list recipients

 sound/core/oss/linear.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/sound/core/oss/linear.c b/sound/core/oss/linear.c
index 6e51cfdca238..7765ac0ec400 100644
--- a/sound/core/oss/linear.c
+++ b/sound/core/oss/linear.c
@@ -6,6 +6,7 @@
  */
 
 #include <linux/time.h>
+#include <linux/minmax.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include "pcm_plugin.h"
@@ -75,6 +76,8 @@ static snd_pcm_sframes_t linear_transfer(struct snd_pcm_plugin *plugin,
 			       struct snd_pcm_plugin_channel *dst_channels,
 			       snd_pcm_uframes_t frames)
 {
+	unsigned int channel;
+
 	if (snd_BUG_ON(!plugin || !src_channels || !dst_channels))
 		return -ENXIO;
 	if (frames == 0)
@@ -92,8 +95,12 @@ static snd_pcm_sframes_t linear_transfer(struct snd_pcm_plugin *plugin,
 		}
 	}
 #endif
-	if (frames > dst_channels[0].frames)
-		frames = dst_channels[0].frames;
+	for (channel = 0; channel < plugin->src_format.channels; channel++) {
+		frames = min(frames, src_channels[channel].frames);
+
+		frames = min(frames, dst_channels[channel].frames);
+	}
+
 	convert(plugin, src_channels, dst_channels, frames);
 	return frames;
 }
-- 
2.55.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] ALSA: linear: Check frame count for all channels
  2026-11-05 14:22 [PATCH v2] ALSA: linear: Check frame count for all channels Sreeraj S Kurup
@ 2026-11-05 15:08 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2026-11-05 15:08 UTC (permalink / raw)
  To: Sreeraj S Kurup; +Cc: perex, tiwai, tiwai, linux-kernel, linux-sound

On Thu, 05 Nov 2026 15:22:26 +0100,
Sreeraj S Kurup wrote:
> 
> linear_transfer() checks the available frame count only for
> the first destination channel.
> 
> Check the available frame count of all source and destination
> channels before converting samples.
> 
> Use the smallest available frame count to make sure that
> conversion does not read or write beyond the channel buffers.
> 
> Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>

Well, the number of the processed frames must be identical for all
channels.  So this is superfluous.

Or, do you see any real case hitting this?


thanks,

Takashi

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-05 15:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-05 14:22 [PATCH v2] ALSA: linear: Check frame count for all channels Sreeraj S Kurup
2026-11-05 15:08 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®