Re: [PATCH 16/28] ASoC: apple: Add macaudio machine driver

From: James Calligeros

Date: Wed Sep 30 2026 - 03:47:39 EST


On Monday, 28 September 2026 9:03:13 pm Australian Eastern Standard Time Mark
Brown wrote:
> On Sat, Sep 26, 2026 at 11:06:02AM +1000, James Calligeros wrote:
> > On Tuesday, 22 September 2026 7:38:54 pm Australian Eastern Standard Time
Mark Brown wrote:
> > > > + list_for_each_entry(kctl, &ma->card.snd_card->controls, list) {
> > > > + if (!snd_soc_control_matches(kctl,
> > > > volume_control_names[ma->cfg->amp]))
> > > > + continue;
> > >
> > > This is used from the volume limit timeout work which doesn't hold the
> > > controls_rwsem, userspace can add or remove user controls which would
> > > change the list so the work needs to lock the controls list.
> >
> > Would it be sufficient to scoped_guard the controls_rwsem wherever we
> > use this pattern?
>
> I think so, but I didn't properly check.
>

I did some testing of this and it causes deadlocks if we try to take the
semaphore from inside the workqueue. I believe it is related to the fact
that speakersafetyd has a blocking handle to the controls open at all times.
This may be fixable by simply having speakersafetyd take a nonblocking
handle instead. I will do some more testing before submitting v2.

> > > > +static int macaudio_dpcm_hw_params(struct snd_pcm_substream
> > > > *substream,
> > > > + struct snd_pcm_hw_params *params)
> > > > +{
> > > > + struct snd_soc_pcm_runtime *rtd =
> > > > snd_soc_substream_to_rtd(substream);
> > > > + struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(rtd->card);
> > > > + struct macaudio_link_props *props =
> > > > &ma->link_props[rtd->dai_link->id];
> > > > + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
> > > > + struct snd_interval *rate = hw_param_interval(params,
> > > > +
SNDRV_PCM_HW_PARAM_RATE);
> > > > + int bclk_ratio = macaudio_get_runtime_bclk_ratio(substream);
> > > > + int i;
> > > > +
> > > > + if (props->is_sense) {
> > > > + rate->min = rate->max = cpu_dai->symmetric_rate;
> > > > + return 0;
> > > > + }
> > >
> > > It feels like this DAI ought to have separate ops... Also, for the
> > > sense link will we definitely already have a rate set up?
> >
> > AIUI, the cpu rate should always be set up by the time we hit
> > this path as it is only taken when setting up the VISENSE FE (after the
> > playback stuff is already set up).
>
> Is that something we actually enforce or is that just a thing a sensible
> userspace should do? I can see something racing.

We don't really enforce it. speakersafetyd is the only thing that opens the
VISENSE PCM and does a blocking read of samples
which only starts and subsequently completes after the "real" PCM
is configured and playback begins. The sample rate is reliably
reflected to speakersafetyd via the kcontrol on the VISENSE PCM. We
have not experienced any race issues with this arrangement in ~5 years
nor has anyone reported any to us. I'm happy to take pointers on
how we should be doing this if the current approach won't fly.