]> git.alsa-project.org Git - alsa-lib.git/commitdiff
ucm: do not share the ctl cache handle for different device names
authorJaroslav Kysela <perex@perex.cz>
Tue, 24 Nov 2026 15:35:33 +0000 (16:35 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 24 Nov 2026 15:42:29 +0000 (16:42 +0100)
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 <perex@perex.cz>
src/ucm/utils.c

index f56d7f7406cdd8689430be3fa57c8dcbbe5cb061..d3e7c139b05f08ca679df39027e24136fa5486a1 100644 (file)
@@ -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;