OSDN Git Service

ucm: add a check for the empty configuration
authorJaroslav Kysela <perex@perex.cz>
Tue, 6 Oct 2020 08:40:40 +0000 (10:40 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 6 Oct 2020 08:43:13 +0000 (10:43 +0200)
Return an error if the UCM configuration is empty (no verbs
or no boot sequence).

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

index 9e43ac6..00b4170 100644 (file)
@@ -569,6 +569,20 @@ static int import_master_config(snd_use_case_mgr_t *uc_mgr)
 }
 
 /**
+ * \brief Check, if the UCM configuration is empty
+ * \param uc_mgr Use case Manager
+ * \return zero on success, otherwise a negative error code
+ */
+static int check_empty_configuration(snd_use_case_mgr_t *uc_mgr)
+{
+       if (!list_empty(&uc_mgr->verb_list))
+               return 0;
+       if (!list_empty(&uc_mgr->once_list))
+               return 0;
+       return -ENXIO;
+}
+
+/**
  * \brief Universal find - string in a list
  * \param list List of structures
  * \param offset Offset of list structure
@@ -981,14 +995,20 @@ int snd_use_case_mgr_open(snd_use_case_mgr_t **uc_mgr,
        err = import_master_config(mgr);
        if (err < 0) {
                uc_error("error: failed to import %s use case configuration %d",
-                       card_name, err);
-               goto err;
+                        card_name, err);
+               goto _err;
+       }
+
+       err = check_empty_configuration(mgr);
+       if (err < 0) {
+               uc_error("error: failed to import %s (empty configuration)", card_name);
+               goto _err;
        }
 
        *uc_mgr = mgr;
        return 0;
 
-err:
+_err:
        uc_mgr_free(mgr);
        return err;
 }