From 91a0e4d05565fd51b22e1fbb0d5042b9e5f433ca Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Tue, 24 Nov 2026 16:35:12 +0100 Subject: [PATCH] ucm: do not register hw: aliases for non-hw control devices uc_mgr_ctl_add() unconditionally registered the synthetic hw: and hw: 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: string and a later hw:X request may be served by (or merged into) the default handle. Register the hw: / hw: 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 --- src/ucm/utils.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/ucm/utils.c b/src/ucm/utils.c index c386593b..f56d7f74 100644 --- a/src/ucm/utils.c +++ b/src/ucm/utils.c @@ -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); -- 2.52.0