From b61bd1d972f4ebc41f4d8f2d0e5b42d9baca13b6 Mon Sep 17 00:00:00 2001 From: Eduardo Date: Wed, 25 Nov 2026 12:06:53 +0000 Subject: [PATCH] drm/apple: audio: start the format sieve with no rates dcpaud_fill_fmt_sieve() assigns the sieve's formats and channel counts but only or's bits into its rates, and both callers leave the sieve on the stack uninitialised. Any rate the stack holds then passes as one the stream asked for: the hw rules count elements that do not have the stream's rate, dcpaud_select_cookie() takes the first element that has any of those rates, and on firmware whose link data is the stream's format, dcpaud_link_format() sends the lowest. Measured on an older tree on a J713: a 48 kHz stereo 24-bit stream that went on after a deep sleep was linked as (1, 2, 24, 192000) and played about four times too fast. A stream opened after it was linked as 48000. Start from no rates. Fixes: 4a8d0257cd1a ("gpu: drm: apple: Add DCP audio driver") Signed-off-by: Eduardo --- drivers/gpu/drm/apple/audio-link-test.c | 25 +++++++++++++++++++++++++ drivers/gpu/drm/apple/audio.c | 1 + 2 files changed, 26 insertions(+) diff --git a/drivers/gpu/drm/apple/audio-link-test.c b/drivers/gpu/drm/apple/audio-link-test.c index 908b0e73bc3f2..044e740ed847c 100644 --- a/drivers/gpu/drm/apple/audio-link-test.c +++ b/drivers/gpu/drm/apple/audio-link-test.c @@ -767,6 +767,30 @@ static void dcpaud_eld_refresh_keeps_name_without_edid(struct kunit *test) KUNIT_EXPECT_MEMEQ(test, dcpaud->eld + DRM_ELD_MONITOR_NAME_STRING, "QG270 S3", 8); } +/* The sieve holds what the parameters allow only, whatever it held before. */ +static void dcpaud_sieve_takes_params_only(struct kunit *test) +{ + struct snd_pcm_hw_params *params = kunit_kzalloc(test, sizeof(*params), GFP_KERNEL); + struct dcp_sound_format_mask sieve; + struct snd_interval *i; + + KUNIT_ASSERT_NOT_NULL(test, params); + snd_mask_set_format(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), + SNDRV_PCM_FORMAT_S24_LE); + i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); + i->min = 2; + i->max = 2; + i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); + i->min = 48000; + i->max = 48000; + + memset(&sieve, 0xff, sizeof(sieve)); + dcpaud_fill_fmt_sieve(params, &sieve); + KUNIT_EXPECT_EQ(test, sieve.rates, snd_pcm_rate_to_rate_bit(48000)); + KUNIT_EXPECT_EQ(test, sieve.nchans, BIT(2)); + KUNIT_EXPECT_EQ(test, sieve.formats, SNDRV_PCM_FMTBIT_S24_LE); +} + static struct kunit_case dcpaud_link_cases[] = { KUNIT_CASE(dcpaud_link_release_instance), KUNIT_CASE(dcpaud_disconnect_sync_completes_live_owner), @@ -790,6 +814,7 @@ static struct kunit_case dcpaud_link_cases[] = { KUNIT_CASE(dcpaud_eld_refresh_takes_monitor_name), KUNIT_CASE(dcpaud_eld_refresh_needs_connection), KUNIT_CASE(dcpaud_eld_refresh_keeps_name_without_edid), + KUNIT_CASE(dcpaud_sieve_takes_params_only), {} }; diff --git a/drivers/gpu/drm/apple/audio.c b/drivers/gpu/drm/apple/audio.c index f4db111e67585..44be303d11744 100644 --- a/drivers/gpu/drm/apple/audio.c +++ b/drivers/gpu/drm/apple/audio.c @@ -239,6 +239,7 @@ static void dcpaud_fill_fmt_sieve(struct snd_pcm_hw_params *params, sieve->nchans = GENMASK(c->max, c->min); sieve->formats = f->bits[0] | ((u64) f->bits[1]) << 32; /* TODO: don't open-code */ + sieve->rates = 0; for (i = 0; i < snd_pcm_known_rates.count; i++) { unsigned int rate = snd_pcm_known_rates.list[i];