]> git.alsa-project.org Git - alsa-lib.git/commitdiff
ucm: do not register hw: aliases for non-hw control devices
authorJaroslav Kysela <perex@perex.cz>
Tue, 24 Nov 2026 15:35:12 +0000 (16:35 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 24 Nov 2026 15:39:13 +0000 (16:39 +0100)
uc_mgr_ctl_add() unconditionally registered the synthetic hw:<card> and
hw:<id> aliases into the dev_list of every opened control device. These
aliases identify the hw control interface of a card, so adding them to a
different interface (e.g. default:X) makes that handle wrongly claim the
hw name. Two cached entries then reference the same hw:<id> string and a
later hw:X request may be served by (or merged into) the default handle.

Register the hw:<card> / hw:<id> aliases only when the opened device is
actually a hw device, keeping each cache entry tied to a single control
interface.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
src/ucm/utils.c

index c386593bc17e8a7d60faf7b4e319325710953ba3..f56d7f7406cdd8689430be3fa57c8dcbbe5cb061 100644 (file)
@@ -194,6 +194,15 @@ static int uc_mgr_ctl_add_dev(struct ctl_list *ctl_list, const char *device)
        return 0;
 }
 
+/* compare the device name (the part before ':'), ignoring the arguments */
+static int uc_mgr_ctl_dev_name_eq(const char *a, const char *b)
+{
+       size_t la = strcspn(a, ":");
+       size_t lb = strcspn(b, ":");
+
+       return la == lb && strncmp(a, b, la) == 0;
+}
+
 static int uc_mgr_ctl_add(snd_use_case_mgr_t *uc_mgr,
                          struct ctl_list **ctl_list,
                          snd_ctl_t *ctl, int card,
@@ -225,18 +234,20 @@ static int uc_mgr_ctl_add(snd_use_case_mgr_t *uc_mgr,
                if (!slave)
                        (*ctl_list)->slave = slave;
        }
-       if (card >= 0) {
-               snprintf(dev, sizeof(dev), "hw:%d", card);
+       if (!device || uc_mgr_ctl_dev_name_eq(device, "hw")) {
+               if (card >= 0) {
+                       snprintf(dev, sizeof(dev), "hw:%d", card);
+                       hit |= !!(device && (strcmp(dev, device) == 0));
+                       err = uc_mgr_ctl_add_dev(*ctl_list, dev);
+                       if (err < 0)
+                               goto __nomem;
+               }
+               snprintf(dev, sizeof(dev), "hw:%s", id);
                hit |= !!(device && (strcmp(dev, device) == 0));
                err = uc_mgr_ctl_add_dev(*ctl_list, dev);
                if (err < 0)
                        goto __nomem;
        }
-       snprintf(dev, sizeof(dev), "hw:%s", id);
-       hit |= !!(device && (strcmp(dev, device) == 0));
-       err = uc_mgr_ctl_add_dev(*ctl_list, dev);
-       if (err < 0)
-               goto __nomem;
        /* the UCM name not based on the card name / id */
        if (!hit && device) {
                err = uc_mgr_ctl_add_dev(*ctl_list, device);