* [PATCH] ALSA: vmaster: Retry follower initialization on failure
@ 2026-11-26 7:22 Sreeraj S Kurup
2026-11-26 7:39 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Sreeraj S Kurup @ 2026-11-26 7:22 UTC (permalink / raw)
To: perex, tiwai; +Cc: linux-kernel, linux-sound, Sreeraj S Kurup
Reset the follower count when the initial follower update
fails.
This allows follower initialization to be retried on the
next access.
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
sound/core/vmaster.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/sound/core/vmaster.c b/sound/core/vmaster.c
index f43144ba2797..d97d7bb33e16 100644
--- a/sound/core/vmaster.c
+++ b/sound/core/vmaster.c
@@ -102,7 +102,14 @@ static int follower_init(struct link_follower *follower)
follower->info.min_val = uinfo->value.integer.min;
follower->info.max_val = uinfo->value.integer.max;
- return follower_update(follower);
+ err = follower_update(follower);
+ if (err < 0) {
+ /* allow initialization to be retried */
+ follower->info.count = 0;
+ return err;
+ }
+
+ return 0;
}
/* initialize master volume */
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ALSA: vmaster: Retry follower initialization on failure
2026-11-26 7:22 [PATCH] ALSA: vmaster: Retry follower initialization on failure Sreeraj S Kurup
@ 2026-11-26 7:39 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-26 7:39 UTC (permalink / raw)
To: Sreeraj S Kurup; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] ALSA: vmaster: uninitialized uval passed in sync_followers()
on init failure
- [Medium] ALSA: vmaster: race on follower->info.count in
follower_init() under read lock
- [Low] ALSA: vmaster: missing Fixes trailer in commit message
--
commit 66386ac7ea387abe74516a97a7585d68c50638a0
Author: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
> ALSA: vmaster: Retry follower initialization on failure
>
> Reset the follower count when the initial follower update
> fails.
>
> This allows follower initialization to be retried on the
> next access.
>
> Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
[Severity: Low]
This is a bug fix for follower initialization failure handling. Should
the commit message include a Fixes tag, such as:
Fixes: 3b0a5f22d464 ("[ALSA] Add virtual master control helpers")
or:
Fixes: 2e2c177ca84a ("ALSA: vmaster: Propagate slave error")
> diff --git a/sound/core/vmaster.c b/sound/core/vmaster.c
> index f43144ba27978..d97d7bb33e166 100644
> --- a/sound/core/vmaster.c
> +++ b/sound/core/vmaster.c
> @@ -102,7 +102,14 @@ static int follower_init(struct link_follower *follower)
> follower->info.min_val = uinfo->value.integer.min;
> follower->info.max_val = uinfo->value.integer.max;
>
> - return follower_update(follower);
> + err = follower_update(follower);
> + if (err < 0) {
> + /* allow initialization to be retried */
> + follower->info.count = 0;
> + return err;
> + }
> +
> + return 0;
> }
[Severity: Medium]
Can resetting follower->info.count to 0 here cause sync_followers() to
pass uninitialized or stale uval contents to follower->follower.put()?
master_init() only initializes the first follower in master->followers.
When sync_followers() iterates over a subsequent follower whose
follower_update() fails, follower_get_val() returns an error without
populating uval->value.integer.value[]:
sound/core/vmaster.c:sync_followers() {
struct snd_ctl_elem_value *uval __free(kfree) =
kmalloc_obj(*uval);
...
list_for_each_entry(follower, &master->followers, list) {
master->val = old_val;
uval->id = follower->follower.id;
follower_get_val(follower, uval);
master->val = new_val;
follower_put_val(follower, uval);
}
sync_followers() ignores the error from follower_get_val() and calls
follower_put_val(follower, uval). Because follower->info.count is now 0,
follower_put_val() skips its per-channel attenuation and clamping loop
and passes uval directly to follower->follower.put(), writing unclamped
stale values (from the previous follower) or uninitialized heap memory
(if the first follower has SND_CTL_FOLLOWER_NEED_UPDATE) into the
underlying control.
[Severity: Medium]
Can a concurrent control read or info call observe follower->info.count
as non-zero before follower_update() finishes, bypassing initialization
when follower_update() fails?
snd_ctl_elem_read() and snd_ctl_elem_info() hold only a shared read lock
on card->controls_rwsem when calling master_get(), master_info(), or
follower_get():
CPU0 CPU1
follower_get_val()
follower_init()
follower->info.count =
uinfo->count;
follower_update()
kzalloc_obj(*uctl)
master_get()
master_init()
follower_init()
if (follower->info.count)
return 0;
master->info.count = 1; <-- skips retry
follower.get() -> fails
follower->info.count = 0;
If CPU1 enters follower_init() through master_init(), it marks the master
initialized from a follower that failed to initialize; if CPU1 enters
through follower_get_val(), it copies unpopulated follower->vals[] to
userspace. Setting follower->info.count only after follower_update()
succeeds (passing the count to follower_update() or using a local info
struct) would avoid publishing an incompletely initialized follower.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126072220.4496-1-sreekuttan2156239@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-26 7:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 7:22 [PATCH] ALSA: vmaster: Retry follower initialization on failure Sreeraj S Kurup
2026-11-26 7:39 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox