greybus: connection: bind protocol after the connection is operational
authorViresh Kumar <viresh.kumar@linaro.org>
Wed, 1 Jul 2015 06:43:54 +0000 (12:13 +0530)
committerGreg Kroah-Hartman <gregkh@google.com>
Wed, 1 Jul 2015 23:34:55 +0000 (16:34 -0700)
We may bind protocol with a connection from gb_connection_create(), if
bundle's device_id is already set. That's not the case until now.

But if the protocol is initialized with a call to
protocol->connection_init() from this place, kernel will crash.

This will happen because the connection isn't fully initialized yet, for
example its operation list isn't initialized yet. And as soon as the
protocol driver tries to send a request to the module from its
connection_init() callback, we will add an operation to this
uninitialized list. And it will crash while doing:

        prev->next = new;

Try to bind the connection with a protocol only after the connection is
ready for operations.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/connection.c

index 564011ac78948e7ab9b3b45a3ce8aa9f98ac2080..6cd9fe2df034fee45bb53c2e7f5293cc8438fc2c 100644 (file)
@@ -196,12 +196,6 @@ struct gb_connection *gb_connection_create(struct gb_bundle *bundle,
                return NULL;
        }
 
-       /* XXX Will have to establish connections to get version */
-       gb_connection_bind_protocol(connection);
-       if (!connection->protocol)
-               dev_warn(&bundle->dev,
-                        "protocol 0x%02hhx handler not found\n", protocol_id);
-
        spin_lock_irq(&gb_connections_lock);
        list_add(&connection->hd_links, &hd->connections);
        list_add(&connection->bundle_links, &bundle->connections);
@@ -210,6 +204,12 @@ struct gb_connection *gb_connection_create(struct gb_bundle *bundle,
        atomic_set(&connection->op_cycle, 0);
        INIT_LIST_HEAD(&connection->operations);
 
+       /* XXX Will have to establish connections to get version */
+       gb_connection_bind_protocol(connection);
+       if (!connection->protocol)
+               dev_warn(&bundle->dev,
+                        "protocol 0x%02hhx handler not found\n", protocol_id);
+
        return connection;
 }