From: Viresh Kumar Date: Wed, 1 Jul 2015 06:43:54 +0000 (+0530) Subject: greybus: connection: bind protocol after the connection is operational X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b758d68618ffda2f6c1c1d40f90350429e9f7092;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git 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: Viresh Kumar Reviewed-by: Alex Elder Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c index 564011ac7894..6cd9fe2df034 100644 --- a/drivers/staging/greybus/connection.c +++ b/drivers/staging/greybus/connection.c @@ -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; }