From f1d4416384adaedfe886591df581b289212db134 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 10:25:29 +1100 Subject: [PATCH 1/4] ASoC: apple: macaudio: lock only the driver's own speaker volumes The legacy "Speaker Volume Unlock" interface found the speaker volume controls at run time by matching the card's control list against a name pattern. User-defined elements (SNDRV_CTL_IOCTL_ELEM_ADD) are on the same list and may carry any name. They are not ASoC controls: they have no soc_mixer_control in private_value, so snd_soc_limit_volume() must not be handed one, and they must not take part in the lock's ownership check or in the volumes kept across a system sleep. Make snd_soc_control_matches() never match a user-defined element, so snd_soc_limit_volume(), snd_soc_deactivate_kctl() and snd_soc_set_enum_kctl() only see driver controls. In macaudio, have macaudio_vlimit_unlock(), macaudio_vlimit_update() and macaudio_pm_volumes_save() walk ma->spk_vols, the driver's own volume controls taken before the card registers, as the "Speaker Protection" lease already does. The same controls as before are locked, checked, kept and restored. Add a KUnit case with a user-defined element named like a speaker volume, and the define the userspace harness of macaudio-fixed-controls.py now needs. Signed-off-by: Ryan Murray --- sound/soc/apple/macaudio-pm-volumes-test.h | 74 +++++++++++++++++++ sound/soc/apple/macaudio.c | 29 +++----- sound/soc/soc-ops.c | 8 ++ .../selftests/alsa/macaudio-fixed-controls.py | 1 + 4 files changed, 95 insertions(+), 17 deletions(-) diff --git a/sound/soc/apple/macaudio-pm-volumes-test.h b/sound/soc/apple/macaudio-pm-volumes-test.h index dab9d69bb0faa..e170a97eed9c0 100644 --- a/sound/soc/apple/macaudio-pm-volumes-test.h +++ b/sound/soc/apple/macaudio-pm-volumes-test.h @@ -100,6 +100,7 @@ static void macaudio_pmt_pm_card(struct kunit *test, struct macaudio_pmt_pm *t) }; struct macaudio_snd_data *ma; struct snd_card *card; + struct device *dev; unsigned int i; int ret; @@ -107,12 +108,15 @@ static void macaudio_pmt_pm_card(struct kunit *test, struct macaudio_pmt_pm *t) card = kunit_kzalloc(test, sizeof(*card), GFP_KERNEL); KUNIT_ASSERT_NOT_NULL(test, ma); KUNIT_ASSERT_NOT_NULL(test, card); + dev = kunit_device_register(test, "macaudio-pmt-test"); + KUNIT_ASSERT_FALSE(test, IS_ERR(dev)); INIT_LIST_HEAD(&card->controls); INIT_LIST_HEAD(&card->ctl_files); init_rwsem(&card->controls_rwsem); rwlock_init(&card->controls_rwlock); ma->card.snd_card = card; + ma->card.dev = dev; snd_soc_card_set_drvdata(&ma->card, ma); ma->cfg = &macaudio_j493_cfg; ma->has_speakers = true; @@ -147,6 +151,9 @@ static void macaudio_pmt_pm_card(struct kunit *test, struct macaudio_pmt_pm *t) ret = kunit_add_action_or_reset(test, macaudio_pmt_pm_cleanup, ma); KUNIT_ASSERT_EQ(test, ret, 0); + /* As macaudio_late_probe() does, before userspace sees the card */ + KUNIT_ASSERT_EQ(test, macaudio_spk_take_volumes(ma), 0); + KUNIT_ASSERT_EQ(test, ma->spk_nr_vols, MACAUDIO_PMT_NR_VOLS - 1); } /* A daemon takes the lock and every speaker volume, as speakersafetyd does */ @@ -254,7 +261,74 @@ static void macaudio_pm_volumes_new_owner(struct kunit *test) macaudio_pmt_expect_vols(test, &t, true); } +static int macaudio_pmt_user_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *uval) +{ + uval->value.integer.value[0] = *(long *)kctl->private_data; + return 0; +} + +static int macaudio_pmt_user_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *uval) +{ + *(long *)kctl->private_data = uval->value.integer.value[0]; + return 1; +} + +/* + * A user-defined element (SNDRV_CTL_IOCTL_ELEM_ADD) named like a speaker + * volume, added after the card registered: no private_value, not the + * driver's, never locked, kept or set. + */ +static struct snd_kcontrol *macaudio_pmt_add_user_kctl(struct kunit *test, + struct macaudio_pmt_pm *t, + long *value) +{ + struct snd_kcontrol_new tmpl = { + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .name = "User Speaker Volume", + .info = macaudio_pmt_vol_info, + .get = macaudio_pmt_user_get, + .put = macaudio_pmt_user_put, + }; + struct snd_kcontrol *kctl; + + kctl = macaudio_pmt_add_kctl(test, t->ma->card.snd_card, &tmpl, value); + /* As snd_ctl_elem_add() marks it; snd_ctl_new1() filters the flag out */ + kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_USER; + return kctl; +} + +static void macaudio_pm_volumes_ignore_user_elements(struct kunit *test) +{ + struct macaudio_pmt_pm t; + struct snd_kcontrol *user; + long value = 33; + + macaudio_pmt_pm_card(test, &t); + user = macaudio_pmt_add_user_kctl(test, &t, &value); + KUNIT_EXPECT_FALSE(test, snd_soc_control_matches(user, "* Speaker Volume")); + + /* Not the lock owner's, and still not in the way of the unlock */ + macaudio_pmt_take(test, &t); + KUNIT_EXPECT_EQ(test, macaudio_pmt_ping(test, &t), 0); + KUNIT_EXPECT_TRUE(test, t.ma->speaker_volume_unlocked); + macaudio_pmt_expect_vols(test, &t, false); + + /* The lock clips the driver's volumes and keeps only those */ + macaudio_pmt_notify(&t, PM_SUSPEND_PREPARE); + KUNIT_EXPECT_FALSE(test, t.ma->speaker_volume_unlocked); + macaudio_pmt_expect_vols(test, &t, true); + KUNIT_EXPECT_EQ(test, t.ma->pm_nr_volumes, MACAUDIO_PMT_NR_VOLS - 1); + KUNIT_EXPECT_EQ(test, value, 33); + + macaudio_pmt_notify(&t, PM_POST_SUSPEND); + KUNIT_EXPECT_EQ(test, macaudio_pmt_ping(test, &t), 0); + KUNIT_EXPECT_TRUE(test, t.ma->speaker_volume_unlocked); + macaudio_pmt_expect_vols(test, &t, false); + KUNIT_EXPECT_EQ(test, value, 33); +} + static struct kunit_case macaudio_pm_volumes_cases[] = { + KUNIT_CASE(macaudio_pm_volumes_ignore_user_elements), KUNIT_CASE(macaudio_pm_volumes_restored_after_sleep), KUNIT_CASE(macaudio_pm_volumes_second_sleep_before_ping), KUNIT_CASE(macaudio_pm_volumes_new_owner), diff --git a/sound/soc/apple/macaudio.c b/sound/soc/apple/macaudio.c index b05d60bc0451a..8af9aa666ab08 100644 --- a/sound/soc/apple/macaudio.c +++ b/sound/soc/apple/macaudio.c @@ -517,6 +517,7 @@ static void macaudio_vlimit_unlock(struct macaudio_snd_data *ma, bool unlock) const char *name = volume_control_names[ma->cfg->amp]; struct snd_kcontrol *kctl; bool failed = false; + unsigned int i; if (!name) { WARN_ON_ONCE(1); @@ -558,12 +559,11 @@ static void macaudio_vlimit_unlock(struct macaudio_snd_data *ma, bool unlock) /* * One control at a time: snd_soc_limit_volume() stops at the first * control it cannot clip, which would leave the rest at their old - * limit and value. + * limit and value. Only the driver's own volume controls, taken before + * the card registered (macaudio_spk_take_volumes()). */ - list_for_each_entry(kctl, &ma->card.snd_card->controls, list) { - if (!snd_soc_control_matches(kctl, name)) - continue; - + for (i = 0; i < ma->spk_nr_vols; i++) { + kctl = ma->spk_vols[i]; hits++; ret = snd_soc_limit_volume(&ma->card, kctl->id.name, max); if (ret < 0) { @@ -680,9 +680,8 @@ static void macaudio_pm_volumes_save(struct macaudio_snd_data *ma) return; macaudio_pm_volumes_drop(ma); - list_for_each_entry(kctl, &ma->card.snd_card->controls, list) - if (snd_soc_control_matches(kctl, name)) - nr++; + /* The driver's own volume controls, which live as long as the card */ + nr = ma->spk_nr_vols; if (!nr) return; @@ -691,9 +690,8 @@ static void macaudio_pm_volumes_save(struct macaudio_snd_data *ma) if (!vols || !uval) goto out; - list_for_each_entry(kctl, &ma->card.snd_card->controls, list) { - if (!snd_soc_control_matches(kctl, name)) - continue; + for (i = 0; i < nr; i++) { + kctl = ma->spk_vols[i]; memset(uval, 0, sizeof(*uval)); uval->id = kctl->id; ret = kctl->get(kctl, uval); @@ -705,7 +703,6 @@ static void macaudio_pm_volumes_save(struct macaudio_snd_data *ma) vols[i].kctl = kctl; vols[i].value[0] = uval->value.integer.value[0]; vols[i].value[1] = uval->value.integer.value[1]; - i++; } ma->pm_volumes = vols; @@ -752,7 +749,7 @@ static void macaudio_pm_volumes_restore(struct macaudio_snd_data *ma) static void macaudio_vlimit_update(struct macaudio_snd_data *ma) { - int i; + unsigned int i, j; bool unlock = true; struct snd_kcontrol *kctl; const char *reason; @@ -793,10 +790,8 @@ static void macaudio_vlimit_update(struct macaudio_snd_data *ma) } /* Check that *every* limited control is locked by the same owner */ - list_for_each_entry(kctl, &ma->card.snd_card->controls, list) { - if(!snd_soc_control_matches(kctl, volume_control_names[ma->cfg->amp])) - continue; - + for (j = 0; j < ma->spk_nr_vols; j++) { + kctl = ma->spk_vols[j]; for (i = 0; i < kctl->count; i++) { if (kctl->vd[i].owner != ma->speaker_lock_owner) { reason = "Not all child controls locked by the same process"; diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c index 3fbfdac6eda87..4cfa5268d0941 100644 --- a/sound/soc/soc-ops.c +++ b/sound/soc/soc-ops.c @@ -408,6 +408,14 @@ bool snd_soc_control_matches(struct snd_kcontrol *kctl, { const char *name = kctl->id.name; + /* + * A user-defined element (SNDRV_CTL_IOCTL_ELEM_ADD) is not one of the + * card's controls: its name says nothing about it and it has no + * private_value, so it never matches a driver's pattern. + */ + if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_USER) + return false; + if (pattern[0] == '*') { int namelen; int patternlen; diff --git a/tools/testing/selftests/alsa/macaudio-fixed-controls.py b/tools/testing/selftests/alsa/macaudio-fixed-controls.py index 5ca87d990c11f..74f5d99f775c5 100644 --- a/tools/testing/selftests/alsa/macaudio-fixed-controls.py +++ b/tools/testing/selftests/alsa/macaudio-fixed-controls.py @@ -33,6 +33,7 @@ def function(source, name): #include #define SNDRV_CTL_ELEM_ACCESS_WRITE 2 #define SNDRV_CTL_ELEM_ACCESS_INACTIVE 256 +#define SNDRV_CTL_ELEM_ACCESS_USER (1 << 29) #define SNDRV_CTL_EVENT_MASK_INFO 2 #define SNDRV_CTL_EVENT_MASK_VALUE 1 #define SNDRV_CTL_ELEM_TYPE_ENUMERATED 3 From 0f62162c634912537e17b15ea4468b4a0277a8b5 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 11:53:55 +1100 Subject: [PATCH 2/4] ASoC: apple: macaudio: take the kept speaker controls afresh at each bind macaudio_spk_take_volumes(), macaudio_spk_take_amp_gains() and macaudio_spk_take_hpfs() allocate a new array sized for the controls they find and append to it from the kept count, which nothing resets. When the card is bound again, after a codec was unbound and bound, the count still holds the previous binding's controls: the appends run past the end of the new array, and its first entries stay unset. The old entries also keep pointing at the controls of the card that went away. Forget the kept speaker volumes, amp gains and tweeter high-pass controls when the card is removed, and have each take helper drop what it kept before it allocates again. The legacy lock leaves the volumes failed closed when none is kept; say so where it reports that. Add a KUnit case that takes the volumes again after they were dropped, as a second bind does, and checks the lock and system-sleep paths still cover exactly the speaker volumes. Also make the comment in snd_soc_control_matches() precise about a user-defined element's private_value. Signed-off-by: Ryan Murray --- sound/soc/apple/macaudio-pm-volumes-test.h | 34 ++++++++++++++ sound/soc/apple/macaudio.c | 52 ++++++++++++++++++++++ sound/soc/soc-ops.c | 5 ++- 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/sound/soc/apple/macaudio-pm-volumes-test.h b/sound/soc/apple/macaudio-pm-volumes-test.h index e170a97eed9c0..40498db631000 100644 --- a/sound/soc/apple/macaudio-pm-volumes-test.h +++ b/sound/soc/apple/macaudio-pm-volumes-test.h @@ -327,11 +327,45 @@ static void macaudio_pm_volumes_ignore_user_elements(struct kunit *test) KUNIT_EXPECT_EQ(test, value, 33); } +/* + * A card bound again (a codec unbound and bound) takes its volumes afresh: + * the kept set is the new binding's, never the old one's plus the new. + */ +static void macaudio_pm_volumes_taken_again(struct kunit *test) +{ + struct macaudio_pmt_pm t; + unsigned int i; + + macaudio_pmt_pm_card(test, &t); + KUNIT_ASSERT_EQ(test, macaudio_spk_take_volumes(t.ma), 0); + KUNIT_ASSERT_EQ(test, t.ma->spk_nr_vols, MACAUDIO_PMT_NR_VOLS - 1); + for (i = 0; i < MACAUDIO_PMT_NR_VOLS - 1; i++) + KUNIT_EXPECT_PTR_EQ(test, t.ma->spk_vols[i], t.vols[i]); + + /* As macaudio_card_remove() leaves them for the next late_probe */ + macaudio_spk_drop_controls(t.ma); + KUNIT_EXPECT_EQ(test, t.ma->spk_nr_vols, 0); + KUNIT_EXPECT_NULL(test, t.ma->spk_vols); + KUNIT_ASSERT_EQ(test, macaudio_spk_take_volumes(t.ma), 0); + KUNIT_ASSERT_EQ(test, t.ma->spk_nr_vols, MACAUDIO_PMT_NR_VOLS - 1); + + /* The lock still covers exactly the speaker volumes */ + macaudio_pmt_take(test, &t); + KUNIT_EXPECT_EQ(test, macaudio_pmt_ping(test, &t), 0); + macaudio_pmt_notify(&t, PM_SUSPEND_PREPARE); + macaudio_pmt_expect_vols(test, &t, true); + KUNIT_EXPECT_EQ(test, t.ma->pm_nr_volumes, MACAUDIO_PMT_NR_VOLS - 1); + macaudio_pmt_notify(&t, PM_POST_SUSPEND); + KUNIT_EXPECT_EQ(test, macaudio_pmt_ping(test, &t), 0); + macaudio_pmt_expect_vols(test, &t, false); +} + static struct kunit_case macaudio_pm_volumes_cases[] = { KUNIT_CASE(macaudio_pm_volumes_ignore_user_elements), KUNIT_CASE(macaudio_pm_volumes_restored_after_sleep), KUNIT_CASE(macaudio_pm_volumes_second_sleep_before_ping), KUNIT_CASE(macaudio_pm_volumes_new_owner), + KUNIT_CASE(macaudio_pm_volumes_taken_again), {} }; diff --git a/sound/soc/apple/macaudio.c b/sound/soc/apple/macaudio.c index 8af9aa666ab08..14770e19eaa93 100644 --- a/sound/soc/apple/macaudio.c +++ b/sound/soc/apple/macaudio.c @@ -572,6 +572,7 @@ static void macaudio_vlimit_unlock(struct macaudio_snd_data *ma, bool unlock) failed = true; } } + /* None kept (not taken yet, or dropped with the card): fail closed. */ if (!hits) dev_err(ma->card.dev, "Failed to %slock volume %s: %d\n", unlock ? "un" : "", name, -EINVAL); @@ -2179,6 +2180,52 @@ static int macaudio_spk_owned_write_check(struct snd_kcontrol *kctl, return macaudio_spk_leased(ma) ? -EPERM : 0; } +/* + * Forget the speaker controls the take helpers below keep. They belong to + * one binding of the card: its controls go with it, and a later late_probe + * takes the new ones afresh. + */ +static void macaudio_spk_drop_volumes(struct macaudio_snd_data *ma) +{ + struct device *dev = ma->card.dev; + + if (ma->spk_vols) + devm_kfree(dev, ma->spk_vols); + if (ma->spk_uval) + devm_kfree(dev, ma->spk_uval); + ma->spk_vols = NULL; + ma->spk_uval = NULL; + ma->spk_nr_vols = 0; +} + +static void macaudio_spk_drop_amp_gains(struct macaudio_snd_data *ma) +{ + if (ma->spk_amp_gains) + devm_kfree(ma->card.dev, ma->spk_amp_gains); + ma->spk_amp_gains = NULL; + ma->spk_nr_amp_gains = 0; +} + +static void macaudio_spk_drop_hpfs(struct macaudio_snd_data *ma) +{ + struct device *dev = ma->card.dev; + + if (ma->spk_hpfs) + devm_kfree(dev, ma->spk_hpfs); + if (ma->spk_hpf_granted) + devm_kfree(dev, ma->spk_hpf_granted); + ma->spk_hpfs = NULL; + ma->spk_hpf_granted = NULL; + ma->spk_nr_hpfs = 0; +} + +static void macaudio_spk_drop_controls(struct macaudio_snd_data *ma) +{ + macaudio_spk_drop_volumes(ma); + macaudio_spk_drop_amp_gains(ma); + macaudio_spk_drop_hpfs(ma); +} + /* * Keep the speaker volumes, which the lease sets, and refuse userspace * writes to them while leased (macaudio_spk_owned_write_check()). @@ -2201,6 +2248,7 @@ static int macaudio_spk_take_volumes(struct macaudio_snd_data *ma) if (!nr) return -ENOENT; + macaudio_spk_drop_volumes(ma); ma->spk_vols = devm_kcalloc(dev, nr, sizeof(*ma->spk_vols), GFP_KERNEL); ma->spk_uval = devm_kzalloc(dev, sizeof(*ma->spk_uval), GFP_KERNEL); if (!ma->spk_vols || !ma->spk_uval) @@ -2239,6 +2287,7 @@ static int macaudio_spk_take_amp_gains(struct macaudio_snd_data *ma) list_for_each_entry(kctl, &ma->card.snd_card->controls, list) if (macaudio_is_amp_gain(ma, kctl)) nr++; + macaudio_spk_drop_amp_gains(ma); if (!nr) return 0; @@ -2306,6 +2355,7 @@ static int macaudio_spk_take_hpfs(struct macaudio_snd_data *ma) if (!nr) return -ENOENT; + macaudio_spk_drop_hpfs(ma); ma->spk_hpfs = devm_kcalloc(dev, nr, sizeof(*ma->spk_hpfs), GFP_KERNEL); ma->spk_hpf_granted = devm_kcalloc(dev, nr, sizeof(*ma->spk_hpf_granted), GFP_KERNEL); if (!ma->spk_hpfs || !ma->spk_hpf_granted) @@ -3563,6 +3613,8 @@ static int macaudio_card_remove(struct snd_soc_card *card) cancel_delayed_work_sync(&ma->lock_timeout_work); mutex_lock(&ma->volume_lock_mutex); macaudio_pm_volumes_drop(ma); + /* The controls they point to go with this binding of the card. */ + macaudio_spk_drop_controls(ma); mutex_unlock(&ma->volume_lock_mutex); return 0; } diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c index 4cfa5268d0941..9a2a1d058e510 100644 --- a/sound/soc/soc-ops.c +++ b/sound/soc/soc-ops.c @@ -410,8 +410,9 @@ bool snd_soc_control_matches(struct snd_kcontrol *kctl, /* * A user-defined element (SNDRV_CTL_IOCTL_ELEM_ADD) is not one of the - * card's controls: its name says nothing about it and it has no - * private_value, so it never matches a driver's pattern. + * card's controls: its name says nothing about it and its + * private_value is not a struct soc_mixer_control, so it never + * matches a driver's pattern. */ if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_USER) return false; From 18e8ee0d92db2d063d3c8be38523c6e222d9a375 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 29 Nov 2026 12:18:27 +1100 Subject: [PATCH 3/4] selftests: alsa: macaudio-fixed-controls: extract macaudio_spk_drop_hpfs() macaudio_spk_take_hpfs() now calls macaudio_spk_drop_hpfs() first, but the no-device fixture only extracted the take helper, so the standalone fixture stopped compiling. Extract the drop helper too, shim devm_kfree(), and release each HPF capture through the real drop helper instead of free() so the next capture does not free the same arrays twice. Signed-off-by: Ryan Murray --- tools/testing/selftests/alsa/macaudio-fixed-controls.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/alsa/macaudio-fixed-controls.py b/tools/testing/selftests/alsa/macaudio-fixed-controls.py index 74f5d99f775c5..da9046fc6dc53 100644 --- a/tools/testing/selftests/alsa/macaudio-fixed-controls.py +++ b/tools/testing/selftests/alsa/macaudio-fixed-controls.py @@ -81,6 +81,7 @@ def function(source, name): static bool macaudio_spk_leased(const struct macaudio_snd_data *ma) { return ma->spk_iface == 1; } #define GFP_KERNEL 0 #define devm_kcalloc(d, n, s, g) calloc(n, s) +#define devm_kfree(d, p) free(p) #define kzalloc_obj(o) calloc(1, sizeof(o)) #define kfree free #define lockdep_assert_held(p) ((void)0) @@ -285,7 +286,8 @@ def function(source, name): check(regs[0].reg == 6 && regs[1].reg == 6, "safe 800 Hz", "HPF"); check(macaudio_spk_set_hpf(&ma, true) == 0, "grant", "HPF"); for (i = 0; i < 2; i++) check(regs[i].reg == (initial + i) % 7, "restore each amp DT corner", "HPF"); - free(ma.spk_hpfs); free(ma.spk_hpf_granted); + macaudio_spk_drop_hpfs(&ma); + check(!ma.spk_hpfs && !ma.spk_hpf_granted && !ma.spk_nr_hpfs, "drop clears capture", "HPF"); } } int main(void) @@ -339,6 +341,7 @@ def main(): if "static int macaudio_route_write_check(" in ma else []), function(ma, "macaudio_protect_sense"), function(ma, "macaudio_enum_item"), + function(ma, "macaudio_spk_drop_hpfs"), function(ma, "macaudio_spk_take_hpfs"), function(ma, "macaudio_spk_set_hpf")] parts += [ma[ma.index("#define CHECK(call,"):ma.index("static int macaudio_set_speaker(")], From 64b0e48784a7825df52831b59bfbfc38e6c92392 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 29 Nov 2026 15:07:30 +1100 Subject: [PATCH 4/4] ASoC: apple: macaudio: kunit: give each pm-volumes test card its own device macaudio_pmt_pm_card() now registers a KUnit device named "macaudio-pmt-test", and the vlimit cases from main build several cards in one case. The second kunit_device_register() then fails ("Driver 'macaudio-pmt-test' is already registered") and macaudio_vlimit_needs_every_volume aborts. Number the device name per card. Test-only; no driver change. Signed-off-by: Ryan Murray --- sound/soc/apple/macaudio-pm-volumes-test.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sound/soc/apple/macaudio-pm-volumes-test.h b/sound/soc/apple/macaudio-pm-volumes-test.h index baf448a4adf04..3e827fd7ae3e7 100644 --- a/sound/soc/apple/macaudio-pm-volumes-test.h +++ b/sound/soc/apple/macaudio-pm-volumes-test.h @@ -100,7 +100,9 @@ static void macaudio_pmt_pm_card(struct kunit *test, struct macaudio_pmt_pm *t) }; struct macaudio_snd_data *ma; struct snd_card *card; + static unsigned int seq; struct device *dev; + char name[32]; unsigned int i; int ret; @@ -108,7 +110,9 @@ static void macaudio_pmt_pm_card(struct kunit *test, struct macaudio_pmt_pm *t) card = kunit_kzalloc(test, sizeof(*card), GFP_KERNEL); KUNIT_ASSERT_NOT_NULL(test, ma); KUNIT_ASSERT_NOT_NULL(test, card); - dev = kunit_device_register(test, "macaudio-pmt-test"); + /* Cases may build more than one card: each needs its own driver name */ + snprintf(name, sizeof(name), "macaudio-pmt-test-%u", seq++); + dev = kunit_device_register(test, name); KUNIT_ASSERT_FALSE(test, IS_ERR(dev)); INIT_LIST_HEAD(&card->controls);