From: Johan Hovold Date: Tue, 19 Jan 2016 11:51:10 +0000 (+0100) Subject: greybus: core: add defensive connection disable post disconnect X-Git-Tag: v4.14-rc1~2366^2~378^2~21^2~802 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=02a54dd18f1eb831f4bf02ac763a4e9d805e1ba3;p=platform%2Fkernel%2Flinux-rpi.git greybus: core: add defensive connection disable post disconnect 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 Signed-off-by: Johan Hovold Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/greybus/core.c b/drivers/staging/greybus/core.c index cf06c9f..493f3920 100644 --- a/drivers/staging/greybus/core.c +++ b/drivers/staging/greybus/core.c @@ -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; }