Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757908AbcDEJaR (ORCPT ); Tue, 5 Apr 2016 05:30:17 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:32965 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756592AbcDEJaN (ORCPT ); Tue, 5 Apr 2016 05:30:13 -0400 Date: Tue, 5 Apr 2016 18:29:43 +0900 From: Daeseok Youn To: lidza.louina@gmail.com Cc: markh@compro.net, gregkh@linuxfoundation.org, driverdev-devel@linuxdriverproject.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH 1/2] staging: dgnc: return -ENOMEM when kzalloc failed Message-ID: <20160405092943.GA25140@SEL-JYOUN-D1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 866 Lines: 30 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 --- drivers/staging/dgnc/dgnc_tty.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c index 074988d..e97faaa 100644 --- a/drivers/staging/dgnc/dgnc_tty.c +++ b/drivers/staging/dgnc/dgnc_tty.c @@ -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); -- 1.9.1