greybus: manifest interface descriptor parsing
authorAlex Elder <elder@linaro.org>
Thu, 2 Oct 2014 02:54:17 +0000 (21:54 -0500)
committerGreg Kroah-Hartman <greg@kroah.com>
Fri, 3 Oct 2014 04:18:41 +0000 (21:18 -0700)
Add support for parsing one or more interface descriptors in a module
manifest.  There must be at least one, but we impose no limit on the
number of interfaces associated with a module.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
drivers/staging/greybus/manifest.c

index cdb7c24..2c3cf74 100644 (file)
@@ -171,6 +171,45 @@ static char *gb_string_get(u8 string_id)
        return string;
 }
 
+/*
+ * Find interface descriptors in the manifest and set up their data
+ * structures.  Returns the number of interfaces set up for the
+ * given module.
+ */
+static u32 gb_manifest_parse_interfaces(struct gb_module *gmod)
+{
+       u32 count = 0;
+
+       while (true) {
+               struct manifest_desc *descriptor;
+               struct greybus_descriptor_interface *desc_interface;
+               struct gb_interface *interface;
+               bool found = false;
+
+               /* Find an interface descriptor */
+               list_for_each_entry(descriptor, &manifest_descs, links) {
+                       if (descriptor->type == GREYBUS_TYPE_DEVICE) {
+                               found = true;
+                               break;
+                       }
+               }
+               if (!found)
+                       break;
+
+               /* Found one.  Set up its interface structure*/
+               desc_interface = descriptor->data;
+               interface = gb_interface_create(gmod, desc_interface->id);
+               if (!interface)
+                       return 0;       /* Error */
+               count++;
+
+               /* Done with this interface descriptor */
+               release_manifest_descriptor(descriptor);
+       }
+
+       return count;
+}
+
 struct gb_module *gb_manifest_parse_module(struct manifest_desc *module_desc)
 {
        struct greybus_descriptor *desc = module_desc->data;
@@ -202,6 +241,13 @@ struct gb_module *gb_manifest_parse_module(struct manifest_desc *module_desc)
        /* Release the module descriptor, now that we're done with it */
        release_manifest_descriptor(module_desc);
 
+       /* A module must have at least one interface descriptor */
+       if (!gb_manifest_parse_interfaces(gmod)) {
+               pr_err("manifest interface descriptors not valid\n");
+               gb_module_destroy(gmod);
+               return NULL;
+       }
+
        return gmod;
 }