[PATCH 4/4] tty: n_gsm: Fix the test for if DLCI0 is open

From: Dan Carpenter
Date: Thu Apr 26 2018 - 01:55:02 EST

Logically, if gsm->dlci[0] is NULL then it's not open. Also if it's
NULL then we would Oops when we do dlci_get(gsm->dlci[0]); at the end
of the function.

Reported-by: Sun Peng <sun_peng@xxxxxxxxxxxxx>
Signed-off-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 44e9c5e3dbc1..660153538ca7 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -2919,7 +2919,7 @@ static int gsmtty_install(struct tty_driver *driver, struct tty_struct *tty)
perspective as we don't have to worry about this
if DLCI0 is lost */
- if (gsm->dlci[0] && gsm->dlci[0]->state != DLCI_OPEN) {
+ if (!gsm->dlci[0] || gsm->dlci[0]->state != DLCI_OPEN) {
return -EL2NSYNC;