Re: [PATCH v3] ALSA: virtio: use ack callback

From: Matias Ezequiel Vara Larsen
Date: Tue Oct 24 2023 - 07:13:29 EST


On Mon, Oct 23, 2023 at 05:50:00PM +0200, Takashi Iwai wrote:
> On Mon, 23 Oct 2023 17:06:57 +0200,
> Matias Ezequiel Vara Larsen wrote:
> >
> > +static int virtsnd_pcm_ack(struct snd_pcm_substream *substream)
> > +{
> > + struct virtio_pcm_substream *vss = snd_pcm_substream_chip(substream);
> > + struct virtio_snd_queue *queue = virtsnd_pcm_queue(vss);
> > + unsigned long flags;
> > + struct snd_pcm_runtime *runtime = vss->substream->runtime;
> > + ssize_t appl_pos = frames_to_bytes(runtime, runtime->control->appl_ptr);
> > + ssize_t buf_size = frames_to_bytes(runtime, runtime->buffer_size);
> > + int rc;
> > +
> > + spin_lock_irqsave(&queue->lock, flags);
> > + spin_lock(&vss->lock);
> > +
> > + ssize_t bytes = (appl_pos - vss->appl_ptr) % buf_size;
>
> The variable declaration should be moved to the beginning of the
> function.
>
> Also, there can be a overlap beyond runtime->boundary (which easily
> happens for 32bit apps), so the calculation can be a bit more complex
> with conditional.
>

Should I use as an example `cs46xx_playback/capture_transfer()` which relies on
the `snd_pcm_indirect_playback/capture_transfer()`? It looks like it
does already that calculation.

Thanks, Matias.