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

greybus: connection: destroy workqueue at unregister

Destroy the work queue when the connection is destroyed/deregistered
instead of when the last reference is dropped.

The work queue is not needed once the connection has been deregistered,
and no operations will ever be added to it again (handled by checking
connection->state) even if the connection object may not be deallocated
until the final reference is dropped.

The work-queue name is set based on the host-device name and host-device
cport id, something which guarantees a unique name. This would no longer
be true if the work queue was not destroyed at connection deregistration
as a new connection could then be created for that very same host cport.

This is not necessarily a problem unless some work queue features are
used that require unique work-queue names, but let's try to be well
behaved.

Also update an obsolete comment and make explicit that a connection must
be disabled before being destroyed.
Reviewed-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarJohan Hovold <johan@hovoldconsulting.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent 2edbf5ff
...@@ -73,7 +73,7 @@ static void gb_connection_kref_release(struct kref *kref) ...@@ -73,7 +73,7 @@ static void gb_connection_kref_release(struct kref *kref)
struct gb_connection *connection; struct gb_connection *connection;
connection = container_of(kref, struct gb_connection, kref); connection = container_of(kref, struct gb_connection, kref);
destroy_workqueue(connection->wq);
kfree(connection); kfree(connection);
mutex_unlock(&connection_mutex); mutex_unlock(&connection_mutex);
} }
...@@ -500,9 +500,7 @@ void gb_connection_disable(struct gb_connection *connection) ...@@ -500,9 +500,7 @@ void gb_connection_disable(struct gb_connection *connection)
} }
EXPORT_SYMBOL_GPL(gb_connection_disable); EXPORT_SYMBOL_GPL(gb_connection_disable);
/* /* Caller must have disabled the connection before destroying it. */
* Tear down a previously set up connection.
*/
void gb_connection_destroy(struct gb_connection *connection) void gb_connection_destroy(struct gb_connection *connection)
{ {
struct ida *id_map; struct ida *id_map;
...@@ -515,6 +513,8 @@ void gb_connection_destroy(struct gb_connection *connection) ...@@ -515,6 +513,8 @@ 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);
destroy_workqueue(connection->wq);
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;
......
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