msm: sdio: Check tty state before checking write bytes available

Before checking for how many bytes can be written, check the state of
terminal so as to handle the removal of the device during shutdown.

CRs-fixed: 302366
Signed-off-by: Krishna Konda <kkonda@codeaurora.org>
diff --git a/arch/arm/mach-msm/sdio_tty.c b/arch/arm/mach-msm/sdio_tty.c
index d1254e6..6dfd07a 100644
--- a/arch/arm/mach-msm/sdio_tty.c
+++ b/arch/arm/mach-msm/sdio_tty.c
@@ -170,6 +170,12 @@
 		return -ENODEV;
 	}
 
+	if (sdio_tty_drv->sdio_tty_state != TTY_OPENED) {
+		pr_err(SDIO_TTY_MODULE_NAME ": %s: sdio_tty_state = %d",
+		       __func__, sdio_tty_drv->sdio_tty_state);
+		return -EPERM;
+	}
+
 	write_avail = sdio_write_avail(sdio_tty_drv->ch);
 	DEBUG_MSG(sdio_tty_drv,
 		  SDIO_TTY_MODULE_NAME ": %s: write_avail=%d",