greybus: svc: connection is created only once now
authorViresh Kumar <viresh.kumar@linaro.org>
Fri, 24 Jul 2015 10:02:20 +0000 (15:32 +0530)
committerGreg Kroah-Hartman <gregkh@google.com>
Fri, 24 Jul 2015 23:33:20 +0000 (16:33 -0700)
We no longer create a fresh connection on receiving svc-hello message,
but rather update the initial one.

Update 'initial_svc_connection' after the connection is fully
initialized. Look for the partially initialized connection while
removing hd, as hd might be removed before getting svc-hello requests
from svc.

Also update gb_svc_connection_init() to initialize id_map on the first
(and the only) call to connection-init function.

We also can't update connection->bundle->intf->svc, as its a bundle-less
connection. Lets stop updating intf->svc as its not really used.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Perry Hung <perry@leaflabs.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/core.c
drivers/staging/greybus/svc.c

index 3b1be2d..bbfae4a 100644 (file)
@@ -236,6 +236,12 @@ void greybus_remove_hd(struct greybus_host_device *hd)
        gb_interfaces_remove(hd);
        gb_endo_remove(hd->endo);
 
+       /* Is the SVC still using the partially uninitialized connection ? */
+       if (hd->initial_svc_connection) {
+               gb_connection_exit(hd->initial_svc_connection);
+               gb_connection_destroy(hd->initial_svc_connection);
+       }
+
        /*
         * Make sure there are no leftovers that can potentially corrupt sysfs.
         */
index 28a4ca9..969c389 100644 (file)
@@ -54,6 +54,9 @@ gb_ap_interface_create(struct greybus_host_device *hd,
        intf->device_id = GB_DEVICE_ID_AP;
        svc_update_connection(intf, connection);
 
+       /* Its no longer a partially initialized connection */
+       hd->initial_svc_connection = NULL;
+
        return intf;
 }
 
@@ -384,24 +387,11 @@ static int gb_svc_connection_init(struct gb_connection *connection)
        svc->connection = connection;
        connection->private = svc;
 
-       /*
-        * SVC connection is created twice:
-        * - before the interface-id of the AP and the endo type is known.
-        * - after receiving endo type and interface-id of the AP from the SVC.
-        *
-        * We should do light-weight initialization for the first case.
-        */
-       if (!connection->bundle) {
-               WARN_ON(connection->hd->initial_svc_connection);
-               connection->hd->initial_svc_connection = connection;
-               return 0;
-       }
+       WARN_ON(connection->hd->initial_svc_connection);
+       connection->hd->initial_svc_connection = connection;
 
        ida_init(&greybus_svc_device_id_map);
 
-       /* Set interface's svc connection */
-       connection->bundle->intf->svc = svc;
-
        return 0;
 }
 
@@ -409,14 +399,6 @@ static void gb_svc_connection_exit(struct gb_connection *connection)
 {
        struct gb_svc *svc = connection->private;
 
-       if (connection->hd->initial_svc_connection == connection) {
-               connection->hd->initial_svc_connection = NULL;
-       } else {
-               if (WARN_ON(connection->bundle->intf->svc != svc))
-                       return;
-               connection->bundle->intf->svc = NULL;
-       }
-
        connection->private = NULL;
        kfree(svc);
 }