greybus: connection: disconnect connection on failures during initialization

Its possible for connection_init() to fail, in such cases the
disconnected event must be sent to the module.

It is missing currently, fix it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:
Viresh Kumar 2015-08-11 07:35:56 +05:30 committed by Greg Kroah-Hartman
parent 0c32d2a5b2
commit 1869065902
1 changed files with 27 additions and 17 deletions

View File

@ -330,6 +330,27 @@ void gb_connection_destroy(struct gb_connection *connection)
device_unregister(&connection->dev); device_unregister(&connection->dev);
} }
static void gb_connection_disconnected(struct gb_connection *connection)
{
struct gb_control *control;
int cport_id = connection->intf_cport_id;
int ret;
/*
* Inform Interface about In-active CPorts. We don't need to do this
* operation for control cport.
*/
if (cport_id == GB_CONTROL_CPORT_ID)
return;
control = connection->bundle->intf->control;
ret = gb_control_disconnected_operation(control, cport_id);
if (ret)
dev_warn(&connection->dev,
"Failed to disconnect CPort-%d (%d)\n", cport_id, ret);
}
int gb_connection_init(struct gb_connection *connection) int gb_connection_init(struct gb_connection *connection)
{ {
int cport_id = connection->intf_cport_id; int cport_id = connection->intf_cport_id;
@ -366,15 +387,18 @@ int gb_connection_init(struct gb_connection *connection)
spin_lock_irq(&connection->lock); spin_lock_irq(&connection->lock);
connection->state = GB_CONNECTION_STATE_ERROR; connection->state = GB_CONNECTION_STATE_ERROR;
spin_unlock_irq(&connection->lock); spin_unlock_irq(&connection->lock);
goto disconnect;
} }
return 0;
disconnect:
gb_connection_disconnected(connection);
return ret; return ret;
} }
void gb_connection_exit(struct gb_connection *connection) void gb_connection_exit(struct gb_connection *connection)
{ {
int cport_id = connection->intf_cport_id;
if (!connection->protocol) { if (!connection->protocol) {
dev_warn(&connection->dev, "exit without protocol.\n"); dev_warn(&connection->dev, "exit without protocol.\n");
return; return;
@ -391,21 +415,7 @@ void gb_connection_exit(struct gb_connection *connection)
gb_connection_cancel_operations(connection, -ESHUTDOWN); gb_connection_cancel_operations(connection, -ESHUTDOWN);
connection->protocol->connection_exit(connection); connection->protocol->connection_exit(connection);
gb_connection_disconnected(connection);
/*
* Inform Interface about In-active CPorts. We don't need to do this
* operation for control cport.
*/
if (cport_id != GB_CONTROL_CPORT_ID) {
struct gb_control *control = connection->bundle->intf->control;
int ret;
ret = gb_control_disconnected_operation(control, cport_id);
if (ret)
dev_warn(&connection->dev,
"Failed to disconnect CPort-%d (%d)\n",
cport_id, ret);
}
} }
void gb_hd_connections_exit(struct greybus_host_device *hd) void gb_hd_connections_exit(struct greybus_host_device *hd)