From 7f5a75fae90601fbb01c327b0c25f53b392c3b57 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Tue, 24 Nov 2026 16:35:33 +0100 Subject: [PATCH] ucm: do not share the ctl cache handle for different device names uc_mgr_open_ctl() merged any two devices resolving to the same card id into a single cached ctl_list sharing one snd_ctl_t handle. This is wrong when the device names differ: hw:1 and default:1 reference the same card but are distinct control interfaces and must not share a handle. Match the device name (the part before ':', ignoring the arguments) in addition to the card id when reusing a cached handle. Signed-off-by: Jaroslav Kysela --- src/ucm/utils.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/ucm/utils.c b/src/ucm/utils.c index f56d7f74..d3e7c139 100644 --- a/src/ucm/utils.c +++ b/src/ucm/utils.c @@ -277,7 +277,7 @@ int uc_mgr_open_ctl(snd_use_case_mgr_t *uc_mgr, struct ctl_dev *ctl_dev; snd_ctl_card_info_t *info; const char *id; - int err, card, ucm_group, ucm_offset; + int err, card, ucm_group, ucm_offset, found; snd_ctl_card_info_alloca(&info); @@ -319,16 +319,26 @@ int uc_mgr_open_ctl(snd_use_case_mgr_t *uc_mgr, ctl_list = list_entry(pos1, struct ctl_list, list); if (ctl_list->ucm_group != ucm_group) continue; - if (strcmp(id, snd_ctl_card_info_get_id(ctl_list->ctl_info)) == 0) { - card = snd_card_get_index(id); - err = uc_mgr_ctl_add(uc_mgr, &ctl_list, ctl, card, info, device + ucm_offset, slave); - if (err < 0) - goto __nomem; - snd_ctl_close(ctl); - ctl_list->ucm_group = ucm_group; - *ctll = ctl_list; - return 0; + if (strcmp(id, snd_ctl_card_info_get_id(ctl_list->ctl_info)) != 0) + continue; + found = 0; + list_for_each(pos2, &ctl_list->dev_list) { + ctl_dev = list_entry(pos2, struct ctl_dev, list); + if (uc_mgr_ctl_dev_name_eq(ctl_dev->device, device + ucm_offset)) { + found = 1; + break; + } } + if (!found) + continue; + card = snd_card_get_index(id); + err = uc_mgr_ctl_add(uc_mgr, &ctl_list, ctl, card, info, device + ucm_offset, slave); + if (err < 0) + goto __nomem; + snd_ctl_close(ctl); + ctl_list->ucm_group = ucm_group; + *ctll = ctl_list; + return 0; } ctl_list = NULL; -- 2.52.0