staging: dgnc: return -ENOMEM when kzalloc failed
authorDaeseok Youn <daeseok.youn@gmail.com>
Tue, 5 Apr 2016 09:29:43 +0000 (18:29 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 30 Apr 2016 00:46:00 +0000 (17:46 -0700)
The kzalloc can be failed when memory is not enough
to allocate. When kzalloc failed, it need to return
error code with ENOMEM

Signed-off-by: Daeseok Youn <daeseok.youn@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/dgnc/dgnc_tty.c

index 5832190..7f73a41 100644 (file)
@@ -1106,6 +1106,14 @@ static int dgnc_tty_open(struct tty_struct *tty, struct file *file)
        if (!ch->ch_wqueue)
                ch->ch_wqueue = kzalloc(WQUEUESIZE, GFP_KERNEL);
 
+       if (!ch->ch_rqueue || !ch->ch_equeue || !ch->ch_wqueue) {
+               kfree(ch->ch_rqueue);
+               kfree(ch->ch_equeue);
+               kfree(ch->ch_wqueue);
+
+               return -ENOMEM;
+       }
+
        spin_lock_irqsave(&ch->ch_lock, flags);
 
        ch->ch_flags &= ~(CH_OPENING);