From e99f305bb7cc3e22c508440d2a52e8c84c9b507a Mon Sep 17 00:00:00 2001 From: Viresh Kumar Date: Thu, 9 Jul 2015 10:56:30 +0530 Subject: [PATCH] greybus: Cleanup connection leftovers This wouldn't happen normally, but in a buggy corner case it is possible that all the connections aren't removed properly and they are still present after the interfaces and endo are removed. Warn in such a case and cleanup connections, so that /sys/bus/greybus/ can be removed while removing greybus modules. Signed-off-by: Viresh Kumar Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/connection.c | 10 ++++++++++ drivers/staging/greybus/connection.h | 1 + drivers/staging/greybus/core.c | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c index 6994a84439f8..65a2bd5891d9 100644 --- a/drivers/staging/greybus/connection.c +++ b/drivers/staging/greybus/connection.c @@ -313,3 +313,13 @@ void gb_connection_exit(struct gb_connection *connection) cport_id, ret); } } + +void gb_hd_connections_exit(struct greybus_host_device *hd) +{ + struct gb_connection *connection; + + list_for_each_entry(connection, &hd->connections, hd_links) { + gb_connection_exit(connection); + gb_connection_destroy(connection); + } +} diff --git a/drivers/staging/greybus/connection.h b/drivers/staging/greybus/connection.h index acf91835486d..ad699db0dfd8 100644 --- a/drivers/staging/greybus/connection.h +++ b/drivers/staging/greybus/connection.h @@ -50,6 +50,7 @@ void gb_connection_destroy(struct gb_connection *connection); int gb_connection_init(struct gb_connection *connection); void gb_connection_exit(struct gb_connection *connection); +void gb_hd_connections_exit(struct greybus_host_device *hd); void greybus_data_rcvd(struct greybus_host_device *hd, u16 cport_id, u8 *data, size_t length); diff --git a/drivers/staging/greybus/core.c b/drivers/staging/greybus/core.c index 925e1dc00eff..3b1be2dd2359 100644 --- a/drivers/staging/greybus/core.c +++ b/drivers/staging/greybus/core.c @@ -235,6 +235,13 @@ void greybus_remove_hd(struct greybus_host_device *hd) */ gb_interfaces_remove(hd); gb_endo_remove(hd->endo); + + /* + * Make sure there are no leftovers that can potentially corrupt sysfs. + */ + if (WARN_ON(!list_empty(&hd->connections))) + gb_hd_connections_exit(hd); + kref_put_mutex(&hd->kref, free_hd, &hd_mutex); } EXPORT_SYMBOL_GPL(greybus_remove_hd); -- 2.39.2