ucm: fix uc_mgr_scan_master_configs() - skip correctly component directories

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2019-11-02 08:36:46 +01:00
parent 63ffd41d5f
commit e61913f94c

View file

@ -1528,7 +1528,7 @@ int uc_mgr_scan_master_configs(const char **_list[])
char *env = getenv(ALSA_CONFIG_UCM_VAR); char *env = getenv(ALSA_CONFIG_UCM_VAR);
const char **list; const char **list;
snd_config_t *cfg, *c; snd_config_t *cfg, *c;
int i, cnt, err; int i, j, cnt, err;
ssize_t ss; ssize_t ss;
struct dirent **namelist; struct dirent **namelist;
@ -1573,7 +1573,7 @@ int uc_mgr_scan_master_configs(const char **_list[])
goto __err; goto __err;
} }
for (i = 0; i < cnt; i++) { for (i = j = 0; i < cnt; i++) {
/* Skip the directories for component devices */ /* Skip the directories for component devices */
if (is_component_directory(namelist[i]->d_name)) if (is_component_directory(namelist[i]->d_name))
@ -1584,28 +1584,29 @@ int uc_mgr_scan_master_configs(const char **_list[])
goto __err; goto __err;
err = snd_config_search(cfg, "Comment", &c); err = snd_config_search(cfg, "Comment", &c);
if (err >= 0) { if (err >= 0) {
err = parse_string(c, (char **)&list[i*2+1]); err = parse_string(c, (char **)&list[j+1]);
if (err < 0) { if (err < 0) {
snd_config_delete(cfg); snd_config_delete(cfg);
goto __err; goto __err;
} }
} }
snd_config_delete(cfg); snd_config_delete(cfg);
list[i * 2] = strdup(namelist[i]->d_name); list[j] = strdup(namelist[i]->d_name);
if (list[i * 2] == NULL) { if (list[j] == NULL) {
err = -ENOMEM; err = -ENOMEM;
goto __err; goto __err;
} }
if (strcmp(dfl, list[i * 2]) == 0) { if (strcmp(dfl, list[j]) == 0) {
/* default to top */ /* default to top */
const char *save1 = list[i * 2]; const char *save1 = list[j];
const char *save2 = list[i * 2 + 1]; const char *save2 = list[j + 1];
memmove(list + 2, list, i * 2 * sizeof(char *)); memmove(list + 2, list, j * sizeof(char *));
list[0] = save1; list[0] = save1;
list[1] = save2; list[1] = save2;
} }
j += 2;
} }
err = cnt * 2; err = j;
__err: __err:
for (i = 0; i < cnt; i++) { for (i = 0; i < cnt; i++) {