Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755830AbbDGQMZ (ORCPT ); Tue, 7 Apr 2015 12:12:25 -0400 Received: from mail-wg0-f52.google.com ([74.125.82.52]:33174 "EHLO mail-wg0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754833AbbDGQMR (ORCPT ); Tue, 7 Apr 2015 12:12:17 -0400 From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= To: lidza.louina@gmail.com, markh@compro.net Cc: gregkh@linuxfoundation.org, driverdev-devel@linuxdriverproject.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, dan.carpenter@oracle.com, sudipm.mukherjee@gmail.com, =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Subject: [PATCH v4 2/3] staging: dgnc: don't forget to check if ->channels[i] is NULL in dgnc_tty_uninit() Date: Tue, 7 Apr 2015 19:11:41 +0300 Message-Id: <1428423102-29138-2-git-send-email-giedrius.statkevicius@gmail.com> X-Mailer: git-send-email 2.3.5 In-Reply-To: <1428423102-29138-1-git-send-email-giedrius.statkevicius@gmail.com> References: <1428423102-29138-1-git-send-email-giedrius.statkevicius@gmail.com> In-Reply-To: <1428415875-23797-1-git-send-email-giedrius.statkevicius@gmail.com> References: <1428415875-23797-1-git-send-email-giedrius.statkevicius@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1763 Lines: 45 Add a check if ->channels[i] is NULL because a NULL pointer may be dereferenced in case one of the allocations failed Reported-by: Dan Carpenter Signed-off-by: Giedrius Statkevičius --- v4: new patch that fixes a bug reported by Dan Carpenter drivers/staging/dgnc/dgnc_tty.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c index 0e48f95..785eb6c 100644 --- a/drivers/staging/dgnc/dgnc_tty.c +++ b/drivers/staging/dgnc/dgnc_tty.c @@ -403,7 +403,9 @@ void dgnc_tty_uninit(struct dgnc_board *brd) dgnc_BoardsByMajor[brd->SerialDriver.major] = NULL; brd->dgnc_Serial_Major = 0; for (i = 0; i < brd->nasync; i++) { - dgnc_remove_tty_sysfs(brd->channels[i]->ch_tun.un_sysfs); + if (brd->channels[i]) + dgnc_remove_tty_sysfs(brd->channels[i]-> + ch_tun.un_sysfs); tty_unregister_device(&brd->SerialDriver, i); } tty_unregister_driver(&brd->SerialDriver); @@ -414,7 +416,9 @@ void dgnc_tty_uninit(struct dgnc_board *brd) dgnc_BoardsByMajor[brd->PrintDriver.major] = NULL; brd->dgnc_TransparentPrint_Major = 0; for (i = 0; i < brd->nasync; i++) { - dgnc_remove_tty_sysfs(brd->channels[i]->ch_pun.un_sysfs); + if (brd->channels[i]) + dgnc_remove_tty_sysfs(brd->channels[i]-> + ch_pun.un_sysfs); tty_unregister_device(&brd->PrintDriver, i); } tty_unregister_driver(&brd->PrintDriver); -- 2.3.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/