From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752883AbbDGLyI (ORCPT ); Tue, 7 Apr 2015 07:54:08 -0400 Received: from mail-wi0-f173.google.com ([209.85.212.173]:33987 "EHLO mail-wi0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752605AbbDGLyF (ORCPT ); Tue, 7 Apr 2015 07:54:05 -0400 Date: Tue, 7 Apr 2015 14:53:39 +0300 (EEST) From: =?ISO-8859-2?Q?Giedrius_Statkevi=E8ius?= X-X-Sender: giedrius@localhost.localdomain To: Sudip Mukherjee cc: =?ISO-8859-2?Q?Giedrius_Statkevi=E8ius?= , lidza.louina@gmail.com, markh@compro.net, gregkh@linuxfoundation.org, driverdev-devel@linuxdriverproject.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] staging: dgnc: check if kzalloc fails in dgnc_tty_init() In-Reply-To: <20150407104110.GB28119@sudip-PC> Message-ID: References: <1428402392-15817-1-git-send-email-giedrius.statkevicius@gmail.com> <20150407104110.GB28119@sudip-PC> User-Agent: Alpine 2.03 (LNX 1266 2009-07-14) MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="8323328-1320879748-1428407623=:17915" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323328-1320879748-1428407623=:17915 Content-Type: TEXT/PLAIN; charset=utf-8 Content-Transfer-Encoding: 8BIT On Tue, 7 Apr 2015, Sudip Mukherjee wrote: > On Tue, Apr 07, 2015 at 01:26:32PM +0300, Giedrius Statkevičius wrote: > > kzalloc() could fail so add a check and return -ENOMEM if it does that gets > > propogated to the pci layer > > > > Signed-off-by: Giedrius Statkevičius > > --- > > drivers/staging/dgnc/dgnc_tty.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c > > index 61d5a8e..23337da 100644 > > --- a/drivers/staging/dgnc/dgnc_tty.c > > +++ b/drivers/staging/dgnc/dgnc_tty.c > > @@ -311,6 +311,8 @@ int dgnc_tty_init(struct dgnc_board *brd) > > * interrupt context, and there are no locks held. > > */ > > brd->channels[i] = kzalloc(sizeof(*brd->channels[i]), GFP_KERNEL); > > + if (!brd->channels[i]) > > + return -ENOMEM; > won't this create memory leak ? > suppose you have brd->nasync = 3 > and kzalloc fails when i=2, and you return -ENOMEM, > then what happens to the memory already allocated to brd->channels[0] > and brd->channels[1] ? > > regards > sudip > Didn't think about that, sorry. It will cause a memory leak indeed. I'll send a v2 that creates a label that frees all successful kzalloc() before returning -ENOMEM. Su pagarba / Regards, Giedrius --8323328-1320879748-1428407623=:17915--