From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Date: Wed, 27 Jan 2016 12:17:52 +0000 (+0100)
Subject: greybus: legacy: fix a null pointer dereference
X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=6e304f5963ce2136cf8fda2acfb87cfe942d2e71;p=linux.git

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 <bgolaszewski@baylibre.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---

diff --git a/drivers/staging/greybus/legacy.c b/drivers/staging/greybus/legacy.c
index 4a45a943470d9..838c70fe74c0a 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);