greybus: core: add defensive connection disable post disconnect
authorJohan Hovold <johan@hovoldconsulting.com>
Tue, 19 Jan 2016 11:51:10 +0000 (12:51 +0100)
committerGreg Kroah-Hartman <gregkh@google.com>
Tue, 19 Jan 2016 20:17:13 +0000 (12:17 -0800)
Bundle drivers *must* disable their connections in the disconnect
callback, but add a defensive test and warn about buggy drivers
nonetheless.

Note that bundle drivers would generally release their state containers
in disconnect so a failure stop I/O could potentially lead to
use-after-free bugs in any late operation completion callbacks.

Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/core.c

index cf06c9f..493f392 100644 (file)
@@ -165,6 +165,13 @@ static int greybus_remove(struct device *dev)
                gb_connection_disable_rx(connection);
 
        driver->disconnect(bundle);
+
+       /* Catch buggy drivers that fail to disable their connections. */
+       list_for_each_entry(connection, &bundle->connections, bundle_links) {
+               if (WARN_ON(connection->state != GB_CONNECTION_STATE_DISABLED))
+                       gb_connection_disable(connection);
+       }
+
        return 0;
 }