greybus: connection: call gb_connection_exit() from gb_connection_destroy()
authorViresh Kumar <viresh.kumar@linaro.org>
Mon, 31 Aug 2015 11:51:13 +0000 (17:21 +0530)
committerJohan Hovold <johan@hovoldconsulting.com>
Thu, 3 Sep 2015 12:45:09 +0000 (14:45 +0200)
Both the routines are always called together and in the same sequence.
Rather than duplicating this at different places, make
gb_connection_destroy() call gb_connection_exit().

This also makes it more sensible, as gb_connection_init() is never
called directly by the users and so its its counterpart shouldn't be
called directly as well.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
drivers/staging/greybus/bundle.c
drivers/staging/greybus/connection.c
drivers/staging/greybus/connection.h
drivers/staging/greybus/core.c

index 459c62a3efb9a27831ae969c4a107dfd7fb8b2ee..5c09bccf55b8b2c92be6560ef8ff26d1d5445102 100644 (file)
@@ -201,10 +201,8 @@ static void gb_bundle_connections_exit(struct gb_bundle *bundle)
        struct gb_connection *next;
 
        list_for_each_entry_safe(connection, next, &bundle->connections,
-                                bundle_links) {
-               gb_connection_exit(connection);
+                                bundle_links)
                gb_connection_destroy(connection);
-       }
 }
 
 /*
index 8fe056d57493ec9e486cc27040bac6dc35bbe926..29870536aa2fbdd2387799d799625787831457ed 100644 (file)
@@ -318,32 +318,6 @@ static void gb_connection_cancel_operations(struct gb_connection *connection,
        spin_unlock_irq(&connection->lock);
 }
 
-/*
- * Tear down a previously set up connection.
- */
-void gb_connection_destroy(struct gb_connection *connection)
-{
-       struct ida *id_map;
-
-       if (WARN_ON(!connection))
-               return;
-
-       spin_lock_irq(&gb_connections_lock);
-       list_del(&connection->bundle_links);
-       list_del(&connection->hd_links);
-       spin_unlock_irq(&gb_connections_lock);
-
-       if (connection->protocol)
-               gb_protocol_put(connection->protocol);
-       connection->protocol = NULL;
-
-       id_map = &connection->hd->cport_id_map;
-       ida_simple_remove(id_map, connection->hd_cport_id);
-       connection->hd_cport_id = CPORT_ID_BAD;
-
-       device_unregister(&connection->dev);
-}
-
 static void gb_connection_disconnected(struct gb_connection *connection)
 {
        struct gb_control *control;
@@ -420,7 +394,7 @@ disconnect:
        return ret;
 }
 
-void gb_connection_exit(struct gb_connection *connection)
+static void gb_connection_exit(struct gb_connection *connection)
 {
        if (!connection->protocol) {
                dev_warn(&connection->dev, "exit without protocol.\n");
@@ -441,14 +415,40 @@ void gb_connection_exit(struct gb_connection *connection)
        gb_connection_disconnected(connection);
 }
 
+/*
+ * Tear down a previously set up connection.
+ */
+void gb_connection_destroy(struct gb_connection *connection)
+{
+       struct ida *id_map;
+
+       if (WARN_ON(!connection))
+               return;
+
+       gb_connection_exit(connection);
+
+       spin_lock_irq(&gb_connections_lock);
+       list_del(&connection->bundle_links);
+       list_del(&connection->hd_links);
+       spin_unlock_irq(&gb_connections_lock);
+
+       if (connection->protocol)
+               gb_protocol_put(connection->protocol);
+       connection->protocol = NULL;
+
+       id_map = &connection->hd->cport_id_map;
+       ida_simple_remove(id_map, connection->hd_cport_id);
+       connection->hd_cport_id = CPORT_ID_BAD;
+
+       device_unregister(&connection->dev);
+}
+
 void gb_hd_connections_exit(struct greybus_host_device *hd)
 {
        struct gb_connection *connection;
 
-       list_for_each_entry(connection, &hd->connections, hd_links) {
-               gb_connection_exit(connection);
+       list_for_each_entry(connection, &hd->connections, hd_links)
                gb_connection_destroy(connection);
-       }
 }
 
 void gb_connection_bind_protocol(struct gb_connection *connection)
index f1b5863820c5911fce65ee247dfe3805a4541aa5..0b442fe61b87116a2db5aea0cbda25c23a65203e 100644 (file)
@@ -60,8 +60,6 @@ struct gb_connection *gb_connection_create_range(struct greybus_host_device *hd,
                           u16 cport_id, u8 protocol_id, u32 ida_start,
                           u32 ida_end);
 void gb_connection_destroy(struct gb_connection *connection);
-
-void gb_connection_exit(struct gb_connection *connection);
 void gb_hd_connections_exit(struct greybus_host_device *hd);
 
 void greybus_data_rcvd(struct greybus_host_device *hd, u16 cport_id,
index 605a0887dc61f1d929433fb7ffcf3abeac72091d..3c89cb368f6d23be72c17c7c824fc085ad598103 100644 (file)
@@ -259,10 +259,8 @@ void greybus_remove_hd(struct greybus_host_device *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);
+       if (hd->initial_svc_connection)
                gb_connection_destroy(hd->initial_svc_connection);
-       }
 
        /*
         * Make sure there are no leftovers that can potentially corrupt sysfs.