Re: [PATCH v4 2/7] ALSA: usb-audio: us144mkii: Add PCM core infrastructure
From: Takashi Iwai
Date: Thu Aug 14 2025 - 03:59:06 EST
On Wed, 13 Aug 2025 15:15:13 +0200,
Šerif Rami wrote:
>
> +static snd_pcm_uframes_t
> +tascam_capture_pointer(struct snd_pcm_substream *substream)
> +{
> + struct tascam_card *tascam = snd_pcm_substream_chip(substream);
> + struct snd_pcm_runtime *runtime = substream->runtime;
> + u64 pos;
> +
> + if (!atomic_read(&tascam->capture_active))
> + return 0;
> +
> + guard(spinlock_irqsave)(&tascam->lock);
> + pos = tascam->capture_frames_processed;
> +
> + if (runtime->buffer_size == 0)
> + return 0;
> +
> + u64 remainder = do_div(pos, runtime->buffer_size);
> +
> + return runtime ? remainder : 0;
If runtime is NULL, it already hits Oops, so this NULL check makes
little sense.
Also, the "u64 remainder" declaration should be put at the beginning
of the function (although nowadays allowed in the middle).
But, judging the code, you don't have to assign but just return
do_div().
> +static snd_pcm_uframes_t
> +tascam_playback_pointer(struct snd_pcm_substream *substream)
> +{
> + struct tascam_card *tascam = snd_pcm_substream_chip(substream);
> + struct snd_pcm_runtime *runtime = substream->runtime;
> + u64 pos;
> +
> + if (!atomic_read(&tascam->playback_active))
> + return 0;
> +
> + guard(spinlock_irqsave)(&tascam->lock);
> + pos = tascam->playback_frames_consumed;
> +
> + if (runtime->buffer_size == 0)
> + return 0;
> +
> + u64 remainder = do_div(pos, runtime->buffer_size);
> +
> + return runtime ? remainder : 0;
Ditto.
thanks,
Takashi