From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755365AbbDGNZh (ORCPT ); Tue, 7 Apr 2015 09:25:37 -0400 Received: from mail-wi0-f177.google.com ([209.85.212.177]:36984 "EHLO mail-wi0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754026AbbDGNZd (ORCPT ); Tue, 7 Apr 2015 09:25:33 -0400 Date: Tue, 7 Apr 2015 16:25:09 +0300 (EEST) From: =?ISO-8859-2?Q?Giedrius_Statkevi=E8ius?= X-X-Sender: giedrius@localhost.localdomain To: Dan Carpenter cc: =?ISO-8859-2?Q?Giedrius_Statkevi=E8ius?= , lidza.louina@gmail.com, markh@compro.net, devel@driverdev.osuosl.org, gregkh@linuxfoundation.org, driverdev-devel@linuxdriverproject.org, linux-kernel@vger.kernel.org, sudipm.mukherjee@gmail.com Subject: Re: [PATCH v2] staging: dgnc: check if kzalloc fails in dgnc_tty_init() In-Reply-To: <20150407130111.GE10964@mwanda> Message-ID: References: <1428402392-15817-1-git-send-email-giedrius.statkevicius@gmail.com> <1428410417-18524-1-git-send-email-giedrius.statkevicius@gmail.com> <20150407130111.GE10964@mwanda> User-Agent: Alpine 2.03 (LNX 1266 2009-07-14) MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="8323328-485983370-1428413111=:19037" 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-485983370-1428413111=:19037 Content-Type: TEXT/PLAIN; charset=utf-8 Content-Transfer-Encoding: 8BIT On Tue, 7 Apr 2015, Dan Carpenter wrote: > On Tue, Apr 07, 2015 at 03:40:17PM +0300, Giedrius Statkevičius wrote: > > If one of the allocations of memory for storing a channel information struct > > fails then free all the successful allocations and return -ENOMEM that gets > > propogated to the pci layer. Also, remove a bogus skipping in the next part of > > the initiation if a previous memory allocation failed because we won't execute > > that if any of the allocations failed. > > > > Signed-off-by: Giedrius Statkevičius > > --- > > v2: Only returning -ENOMEM if an allocation failed isn't enough as it was > > spotted by Sudip so create a new label that frees all successfully allocated > > stuff and only then returns -ENOMEM. Also, remove a unnecessary check in the > > next loop. > > > > drivers/staging/dgnc/dgnc_tty.c | 11 +++++++---- > > 1 file changed, 7 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c > > index ce4187f..60d7e49 100644 > > --- a/drivers/staging/dgnc/dgnc_tty.c > > +++ b/drivers/staging/dgnc/dgnc_tty.c > > @@ -316,6 +316,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]) > > + goto err_free_channels; > > The comments here say that sometimes brd->channels[] are allocated > earlier. If that's true then the error handling is not correct. But > I don't think it is true... Could you investigate and delete the > comments and unnecessary "if (!brd->channels[i])" NULL check. > > regards, > dan carpenter > I've checked this earlier and now looked over again and I didn't find any other place where this is allocated. My thought was that deleting that comment and that check could be too much for one patch. I'll send a v3. Su pagarba / Regards, Giedrius --8323328-485983370-1428413111=:19037--