Commit 36173112 authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman

greybus: connection: unbind protocol at exit

Unbind protocol at connection exit rather than when the connection is
destroyed.

Now a protocol is only bound while a connection is enabled.
Signed-off-by: default avatarJohan Hovold <johan@hovoldconsulting.com>
Reviewed-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent 30c2de77
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
static int gb_connection_bind_protocol(struct gb_connection *connection); static int gb_connection_bind_protocol(struct gb_connection *connection);
static void gb_connection_unbind_protocol(struct gb_connection *connection);
static int gb_connection_init(struct gb_connection *connection); static int gb_connection_init(struct gb_connection *connection);
...@@ -405,7 +406,7 @@ static int gb_connection_init(struct gb_connection *connection) ...@@ -405,7 +406,7 @@ static int gb_connection_init(struct gb_connection *connection)
ret = gb_connection_hd_cport_enable(connection); ret = gb_connection_hd_cport_enable(connection);
if (ret) if (ret)
return ret; goto err_unbind_protocol;
ret = gb_connection_svc_connection_create(connection); ret = gb_connection_svc_connection_create(connection);
if (ret) if (ret)
...@@ -440,15 +441,14 @@ static int gb_connection_init(struct gb_connection *connection) ...@@ -440,15 +441,14 @@ static int gb_connection_init(struct gb_connection *connection)
gb_connection_svc_connection_destroy(connection); gb_connection_svc_connection_destroy(connection);
err_hd_cport_disable: err_hd_cport_disable:
gb_connection_hd_cport_disable(connection); gb_connection_hd_cport_disable(connection);
err_unbind_protocol:
gb_connection_unbind_protocol(connection);
return ret; return ret;
} }
static void gb_connection_exit(struct gb_connection *connection) static void gb_connection_exit(struct gb_connection *connection)
{ {
if (!connection->protocol)
return;
spin_lock_irq(&connection->lock); spin_lock_irq(&connection->lock);
if (connection->state != GB_CONNECTION_STATE_ENABLED) { if (connection->state != GB_CONNECTION_STATE_ENABLED) {
spin_unlock_irq(&connection->lock); spin_unlock_irq(&connection->lock);
...@@ -463,6 +463,7 @@ static void gb_connection_exit(struct gb_connection *connection) ...@@ -463,6 +463,7 @@ static void gb_connection_exit(struct gb_connection *connection)
gb_connection_control_disconnected(connection); gb_connection_control_disconnected(connection);
gb_connection_svc_connection_destroy(connection); gb_connection_svc_connection_destroy(connection);
gb_connection_hd_cport_disable(connection); gb_connection_hd_cport_disable(connection);
gb_connection_unbind_protocol(connection);
} }
/* /*
...@@ -482,10 +483,6 @@ void gb_connection_destroy(struct gb_connection *connection) ...@@ -482,10 +483,6 @@ void gb_connection_destroy(struct gb_connection *connection)
list_del(&connection->hd_links); list_del(&connection->hd_links);
spin_unlock_irq(&gb_connections_lock); spin_unlock_irq(&gb_connections_lock);
if (connection->protocol)
gb_protocol_put(connection->protocol);
connection->protocol = NULL;
id_map = &connection->hd->cport_id_map; id_map = &connection->hd->cport_id_map;
ida_simple_remove(id_map, connection->hd_cport_id); ida_simple_remove(id_map, connection->hd_cport_id);
connection->hd_cport_id = CPORT_ID_BAD; connection->hd_cport_id = CPORT_ID_BAD;
...@@ -532,10 +529,6 @@ static int gb_connection_bind_protocol(struct gb_connection *connection) ...@@ -532,10 +529,6 @@ static int gb_connection_bind_protocol(struct gb_connection *connection)
{ {
struct gb_protocol *protocol; struct gb_protocol *protocol;
/* If we already have a protocol bound here, just return */
if (connection->protocol)
return 0;
protocol = gb_protocol_get(connection->protocol_id, protocol = gb_protocol_get(connection->protocol_id,
connection->major, connection->major,
connection->minor); connection->minor);
...@@ -550,3 +543,12 @@ static int gb_connection_bind_protocol(struct gb_connection *connection) ...@@ -550,3 +543,12 @@ static int gb_connection_bind_protocol(struct gb_connection *connection)
return 0; return 0;
} }
static void gb_connection_unbind_protocol(struct gb_connection *connection)
{
struct gb_protocol *protocol = connection->protocol;
gb_protocol_put(protocol);
connection->protocol = NULL;
}
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