* [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; 5+ 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] 5+ 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
2026-11-06 12:37 ` Sreeraj S Kurup
0 siblings, 1 reply; 5+ 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] 5+ messages in thread
* Re: [PATCH v2] ALSA: linear: Check frame count for all channels
2026-11-05 15:08 ` Takashi Iwai
@ 2026-11-06 12:37 ` Sreeraj S Kurup
2026-11-06 12:53 ` Takashi Iwai
0 siblings, 1 reply; 5+ messages in thread
From: Sreeraj S Kurup @ 2026-11-06 12:37 UTC (permalink / raw)
To: tiwai; +Cc: linux-kernel, linux-sound, perex, sreekuttan2156239, tiwai
Hi Takashi,
Thanks for reviewing.
I added this check because I thought the available frame count could potentially
differ between channels, similar to how the alignment is checked separately for
each channel under CONFIG_SND_DEBUG.
I understand that the ALSA plugin framework normally keeps the processed frame count
identical across all channels.
Is there any condition or exceptional case where the available frame count could differ
between channels? Or is it guaranteed to be identical by the plugin framework?
If it is guaranteed, I agree that this additional check is unnecessary.
Thanks for your guidance.
Best regards,
Sreeraj
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] ALSA: linear: Check frame count for all channels
2026-11-06 12:37 ` Sreeraj S Kurup
@ 2026-11-06 12:53 ` Takashi Iwai
2026-11-06 13:12 ` Sreeraj S Kurup
0 siblings, 1 reply; 5+ messages in thread
From: Takashi Iwai @ 2026-11-06 12:53 UTC (permalink / raw)
To: Sreeraj S Kurup; +Cc: tiwai, linux-kernel, linux-sound, perex, tiwai
On Fri, 06 Nov 2026 13:37:50 +0100,
Sreeraj S Kurup wrote:
>
> Hi Takashi,
>
> Thanks for reviewing.
>
> I added this check because I thought the available frame count could potentially
> differ between channels, similar to how the alignment is checked separately for
> each channel under CONFIG_SND_DEBUG.
Those alignment checks are with snd_BUG_ON(), so it'll give kernel
warning with stack trace, i.e. the code shouldn't be triggered.
I believe the checks are superfluous, but it's a sanity check for
debugging, after all.
> I understand that the ALSA plugin framework normally keeps the processed frame count
> identical across all channels.
>
> Is there any condition or exceptional case where the available frame count could differ
> between channels? Or is it guaranteed to be identical by the plugin framework?
The frame count must be identical. So, if any, such a check should be
conditionally enabled and trigger a kernel WARNING. It means, if it
happens, something must be completely wrong.
thanks,
Takashi
> If it is guaranteed, I agree that this additional check is unnecessary.
>
> Thanks for your guidance.
>
> Best regards,
> Sreeraj
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] ALSA: linear: Check frame count for all channels
2026-11-06 12:53 ` Takashi Iwai
@ 2026-11-06 13:12 ` Sreeraj S Kurup
0 siblings, 0 replies; 5+ messages in thread
From: Sreeraj S Kurup @ 2026-11-06 13:12 UTC (permalink / raw)
To: tiwai; +Cc: linux-kernel, linux-sound, perex, sreekuttan2156239, tiwai
Hi Takashi,
Thanks for the clarification.
I understand now. Since the frame count must be identical across all channels, taking
the minimum is unnecessary. If they ever differ, it indicates an internal inconsistency
that should be caught with a warning rather than silently adjusting the frame count.
I'll drop this patch.
Thanks for your time and explanation.
Best regards,
Sreeraj
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-06 13:12 UTC | newest]
Thread overview: 5+ 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
2026-11-06 12:37 ` Sreeraj S Kurup
2026-11-06 12:53 ` Takashi Iwai
2026-11-06 13:12 ` Sreeraj S Kurup
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®