From 6e304f5963ce2136cf8fda2acfb87cfe942d2e71 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Wed, 27 Jan 2016 13:17:52 +0100 Subject: [PATCH] greybus: legacy: fix a null pointer dereference When gb_protocol_get() fails in legacy_connection_create(), we end up bailing-out before assigning lc->connection and lc->protocol. Calling legacy_connection_destroy() in that case results in a null pointer dereference. Check if lc->connection is not null before freeing it. Signed-off-by: Bartosz Golaszewski Reviewed-by: Johan Hovold Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/legacy.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/staging/greybus/legacy.c b/drivers/staging/greybus/legacy.c index 4a45a943470d..838c70fe74c0 100644 --- a/drivers/staging/greybus/legacy.c +++ b/drivers/staging/greybus/legacy.c @@ -148,6 +148,9 @@ err_protocol_put: static void legacy_connection_destroy(struct legacy_connection *lc) { + if (!lc->connection) + return; + lc->connection->protocol = NULL; gb_connection_destroy(lc->connection); -- 2.20.1