greybus: interface: separate manifest parsing from bundle registration
authorJohan Hovold <johan@hovoldconsulting.com>
Mon, 7 Dec 2015 14:05:44 +0000 (15:05 +0100)
committerGreg Kroah-Hartman <gregkh@google.com>
Tue, 8 Dec 2015 20:56:38 +0000 (15:56 -0500)
Separate manifest parsing, including bundle and connection creation,
from bundle registration.

Note that this is also needed to allow the interface to not be
registered until the manifest has been parsed.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/interface.c
drivers/staging/greybus/manifest.c

index 27215cf30180c3abea7107138c8b64c184aea33b..98a1ba1e485ddddc3421952a4df125258dd2c5dc 100644 (file)
@@ -162,6 +162,7 @@ void gb_interfaces_remove(struct gb_host_device *hd)
  */
 int gb_interface_init(struct gb_interface *intf, u8 device_id)
 {
+       struct gb_bundle *bundle, *tmp;
        struct gb_connection *connection;
        int ret, size;
        void *manifest;
@@ -215,14 +216,25 @@ int gb_interface_init(struct gb_interface *intf, u8 device_id)
                goto free_manifest;
        }
 
-       /*
-        * XXX
-        * We've successfully parsed the manifest.  Now we need to
-        * allocate CPort Id's for connecting to the CPorts found on
-        * other modules.  For each of these, establish a connection
-        * between the local and remote CPorts (including
-        * configuring the switch to allow them to communicate).
-        */
+       /* Register the interface bundles. */
+       list_for_each_entry_safe_reverse(bundle, tmp, &intf->bundles, links) {
+               ret = gb_bundle_add(bundle);
+               if (ret) {
+                       gb_bundle_destroy(bundle);
+                       continue;
+               }
+
+               list_for_each_entry(connection, &bundle->connections,
+                                                       bundle_links) {
+                       ret = gb_connection_init(connection);
+                       if (ret)
+                               break;
+               }
+               if (ret)
+                       gb_bundle_destroy(bundle);
+       }
+
+       ret = 0;
 
 free_manifest:
        kfree(manifest);
index 51201128498d59f5ec05a4f2e6ce6329a254e0ff..357f9c64821b44876c5cf1d96820415ec72191c6 100644 (file)
@@ -286,14 +286,12 @@ exit:
  */
 static u32 gb_manifest_parse_bundles(struct gb_interface *intf)
 {
-       struct gb_connection *connection;
        struct manifest_desc *desc;
        struct gb_bundle *bundle;
        struct gb_bundle *bundle_next;
        u32 count = 0;
        u8 bundle_id;
        u8 class;
-       int ret;
 
        while ((desc = get_next_bundle_desc(intf))) {
                struct greybus_descriptor_bundle *desc_bundle;
@@ -349,23 +347,6 @@ static u32 gb_manifest_parse_bundles(struct gb_interface *intf)
                        continue;
                }
 
-               ret = gb_bundle_add(bundle);
-               if (ret) {
-                       gb_bundle_destroy(bundle);
-                       continue;
-               }
-
-               list_for_each_entry(connection, &bundle->connections,
-                                                       bundle_links) {
-                       ret = gb_connection_init(connection);
-                       if (ret)
-                               break;
-               }
-               if (ret) {
-                       gb_bundle_destroy(bundle);
-                       continue;
-               }
-
                count++;
        }