Commit b758d686 authored by Viresh Kumar's avatar Viresh Kumar Committed by Greg Kroah-Hartman

greybus: connection: bind protocol after the connection is operational

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: default avatarViresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent 463e8736
......@@ -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;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment