greybus: connection: separate connection creation and enabling
authorJohan Hovold <johan@hovoldconsulting.com>
Mon, 7 Dec 2015 14:05:34 +0000 (15:05 +0100)
committerGreg Kroah-Hartman <gregkh@google.com>
Tue, 8 Dec 2015 20:31:14 +0000 (15:31 -0500)
Separate connection creation from enabling.

This will ultimately allow connection structures to be created while
parsing manifests, but the connections to not be enabled until a driver
is bound.

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/connection.c
drivers/staging/greybus/connection.h
drivers/staging/greybus/hd.c
drivers/staging/greybus/interface.c
drivers/staging/greybus/manifest.c

index 980244a..c936502 100644 (file)
@@ -14,7 +14,6 @@
 
 static int gb_connection_bind_protocol(struct gb_connection *connection);
 static void gb_connection_unbind_protocol(struct gb_connection *connection);
-static int gb_connection_init(struct gb_connection *connection);
 
 
 static DEFINE_SPINLOCK(gb_connections_lock);
@@ -125,7 +124,6 @@ gb_connection_create(struct gb_host_device *hd, int hd_cport_id,
        struct gb_connection *connection;
        struct ida *id_map = &hd->cport_id_map;
        int ida_start, ida_end;
-       int retval;
        u8 major = 0;
        u8 minor = 1;
 
@@ -194,14 +192,6 @@ gb_connection_create(struct gb_host_device *hd, int hd_cport_id,
 
        spin_unlock_irq(&gb_connections_lock);
 
-       retval = gb_connection_init(connection);
-       if (retval) {
-               dev_err(&hd->dev, "%s: failed to initialize connection: %d\n",
-                       connection->name, retval);
-               gb_connection_destroy(connection);
-               return NULL;
-       }
-
        return connection;
 
 err_free_connection:
@@ -396,7 +386,7 @@ static int gb_connection_protocol_get_version(struct gb_connection *connection)
        return 0;
 }
 
-static int gb_connection_init(struct gb_connection *connection)
+int gb_connection_init(struct gb_connection *connection)
 {
        int ret;
 
index 77f77bf..329b705 100644 (file)
@@ -63,6 +63,8 @@ static inline bool gb_connection_is_static(struct gb_connection *connection)
        return !connection->intf;
 }
 
+int gb_connection_init(struct gb_connection *connection);
+
 void greybus_data_rcvd(struct gb_host_device *hd, u16 cport_id,
                        u8 *data, size_t length);
 
index b280925..74569a3 100644 (file)
@@ -124,6 +124,13 @@ int gb_hd_add(struct gb_host_device *hd)
                return ret;
        }
 
+       ret = gb_connection_init(hd->svc_connection);
+       if (ret) {
+               gb_connection_destroy(hd->svc_connection);
+               device_del(&hd->dev);
+               return ret;
+       }
+
        return 0;
 }
 EXPORT_SYMBOL_GPL(gb_hd_add);
index 9ff7464..e8eed85 100644 (file)
@@ -180,6 +180,12 @@ int gb_interface_init(struct gb_interface *intf, u8 device_id)
                return -ENOMEM;
        }
 
+       ret = gb_connection_init(connection);
+       if (ret) {
+               gb_connection_destroy(connection);
+               return ret;
+       }
+
        /* Get manifest size using control protocol on CPort */
        size = gb_control_get_manifest_size_operation(intf);
        if (size <= 0) {
index 72400e3..2d47050 100644 (file)
@@ -228,6 +228,7 @@ static char *gb_string_get(struct gb_interface *intf, u8 string_id)
  */
 static u32 gb_manifest_parse_cports(struct gb_bundle *bundle)
 {
+       struct gb_connection *connection;
        struct gb_interface *intf = bundle->intf;
        struct manifest_desc *desc;
        struct manifest_desc *next;
@@ -235,6 +236,7 @@ static u32 gb_manifest_parse_cports(struct gb_bundle *bundle)
        u8 protocol_id;
        u16 cport_id;
        u32 count = 0;
+       int ret;
 
        /* Set up all cport descriptors associated with this bundle */
        list_for_each_entry_safe(desc, next, &intf->manifest_descs, links) {
@@ -254,10 +256,18 @@ static u32 gb_manifest_parse_cports(struct gb_bundle *bundle)
                /* Found one.  Set up its function structure */
                protocol_id = desc_cport->protocol_id;
 
-               if (!gb_connection_create_dynamic(intf, bundle, cport_id,
-                                                               protocol_id))
+               connection = gb_connection_create_dynamic(intf, bundle,
+                                                               cport_id,
+                                                               protocol_id);
+               if (!connection)
                        goto exit;
 
+               ret = gb_connection_init(connection);
+               if (ret) {
+                       gb_connection_destroy(connection);
+                       goto exit;
+               }
+
                count++;
 
                /* Release the cport descriptor */