alsactl: suppress no device 'errors' for UCM

This patch adds --ucm-nodev (or -X) option to get those
messages back. The code works only with library 1.2.6+.

By default, these messages are suppressed:

  alsactl[xxx]: alsa-lib parser.c:242:(error_node) UCM is not supported for this HDA model (HDA Intel PCH...)
  alsactl[xxx]: alsa-lib main.c:1405:(snd_use_case_mgr_open) error: failed to import hw:0 use case configuration -6

Fixes: https://github.com/alsa-project/alsa-utils/issues/111
Link: https://lore.kernel.org/alsa-devel/20211027144008.27002-1-tiwai@suse.de/
Link: 23198a72cd
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2021-10-28 12:07:10 +02:00
parent 5d4442b2cf
commit af62c72e2d
3 changed files with 13 additions and 2 deletions

View file

@ -102,6 +102,9 @@ static struct arg args[] = {
#ifdef HAVE_ALSA_USE_CASE_H #ifdef HAVE_ALSA_USE_CASE_H
{ 'D', "ucm-defaults", "execute also the UCM 'defaults' section" }, { 'D', "ucm-defaults", "execute also the UCM 'defaults' section" },
{ 'U', "no-ucm", "don't init with UCM" }, { 'U', "no-ucm", "don't init with UCM" },
#if SND_LIB_VER(1, 2, 5) < SND_LIB_VERSION
{ 'X', "ucm-nodev", "show UCM no device errors" },
#endif
#endif #endif
{ HEADER, NULL, "Available commands:" }, { HEADER, NULL, "Available commands:" },
{ CARDCMD, "store", "save current driver setup for one or each soundcards" }, { CARDCMD, "store", "save current driver setup for one or each soundcards" },
@ -253,6 +256,9 @@ int main(int argc, char *argv[])
struct option *long_option; struct option *long_option;
char *short_option; char *short_option;
#if SND_LIB_VER(1, 2, 5) >= SND_LIB_VERSION
initflags |= FLAG_UCM_NODEV;
#endif
long_option = calloc(ARRAY_SIZE(args), sizeof(struct option)); long_option = calloc(ARRAY_SIZE(args), sizeof(struct option));
if (long_option == NULL) if (long_option == NULL)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -328,6 +334,9 @@ int main(int argc, char *argv[])
case 'U': case 'U':
initflags |= FLAG_UCM_DISABLED; initflags |= FLAG_UCM_DISABLED;
break; break;
case 'X':
initflags |= FLAG_UCM_NODEV;
break;
case 'r': case 'r':
statefile = optarg; statefile = optarg;
break; break;

View file

@ -39,6 +39,7 @@ void error_handler(const char *file, int line, const char *function, int err, co
#define FLAG_UCM_FBOOT (1<<1) #define FLAG_UCM_FBOOT (1<<1)
#define FLAG_UCM_BOOT (1<<2) #define FLAG_UCM_BOOT (1<<2)
#define FLAG_UCM_DEFAULTS (1<<3) #define FLAG_UCM_DEFAULTS (1<<3)
#define FLAG_UCM_NODEV (1<<4)
void snd_card_iterator_init(struct snd_card_iterator *iter, int cardno); void snd_card_iterator_init(struct snd_card_iterator *iter, int cardno);
int snd_card_iterator_sinit(struct snd_card_iterator *iter, const char *cardname); int snd_card_iterator_sinit(struct snd_card_iterator *iter, const char *cardname);

View file

@ -34,13 +34,14 @@
int init_ucm(int flags, int cardno) int init_ucm(int flags, int cardno)
{ {
snd_use_case_mgr_t *uc_mgr; snd_use_case_mgr_t *uc_mgr;
char id[32]; char id[32], *nodev;
int err; int err;
if (flags & FLAG_UCM_DISABLED) if (flags & FLAG_UCM_DISABLED)
return -ENXIO; return -ENXIO;
snprintf(id, sizeof(id), "hw:%d", cardno); nodev = (flags & FLAG_UCM_NODEV) ? "" : "-";
snprintf(id, sizeof(id), "%shw:%d", nodev, cardno);
err = snd_use_case_mgr_open(&uc_mgr, id); err = snd_use_case_mgr_open(&uc_mgr, id);
if (err < 0) if (err < 0)
return err; return err;