All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Giedrius Statkevičius" <giedrius.statkevicius@gmail.com>
To: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Cc: "Giedrius Statkevičius" <giedrius.statkevicius@gmail.com>,
	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()
Date: Tue, 7 Apr 2015 14:53:39 +0300 (EEST)	[thread overview]
Message-ID: <alpine.LNX.2.03.1504071453250.17915@localhost.localdomain> (raw)
In-Reply-To: <20150407104110.GB28119@sudip-PC>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1316 bytes --]

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 <giedrius.statkevicius@gmail.com>
> > ---
> >  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

  reply	other threads:[~2015-04-07 11:54 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-07 10:26 [PATCH] staging: dgnc: check if kzalloc fails in dgnc_tty_init() Giedrius Statkevičius
2015-04-07 10:41 ` Sudip Mukherjee
2015-04-07 11:53   ` Giedrius Statkevičius [this message]
2015-04-07 12:40 ` [PATCH v2] " Giedrius Statkevičius
2015-04-07 13:01   ` Dan Carpenter
2015-04-07 13:25     ` Giedrius Statkevičius
2015-04-07 14:11   ` [PATCH v3] " Giedrius Statkevičius
2015-04-07 14:24     ` Sudip Mukherjee
2015-04-07 14:37       ` Giedrius Statkevičius
2015-04-07 14:54         ` Dan Carpenter
2015-04-07 14:48     ` Dan Carpenter
2015-04-07 15:35       ` Giedrius Statkevičius
2015-04-07 15:46         ` Dan Carpenter
2015-04-07 15:46           ` Dan Carpenter
2015-04-07 16:11     ` [PATCH v4 1/3] staging: dgnc: clean up allocation of ->channels[i] Giedrius Statkevičius
2015-04-07 16:11       ` Giedrius Statkevičius
2015-04-09 23:42       ` [PATCH v5 " Giedrius Statkevičius
2015-04-09 23:42         ` Giedrius Statkevičius
2015-04-09 23:42       ` [PATCH v5 2/3] staging: dgnc: don't forget to check if ->channels[i] is NULL in dgnc_tty_uninit() Giedrius Statkevičius
2015-04-09 23:42         ` Giedrius Statkevičius
2015-04-09 23:42       ` [PATCH v5 3/3] staging: dgnc: remove redundant !ch checks Giedrius Statkevičius
2015-04-09 23:42         ` Giedrius Statkevičius
2015-04-07 16:11     ` [PATCH v4 2/3] staging: dgnc: don't forget to check if ->channels[i] is NULL in dgnc_tty_uninit() Giedrius Statkevičius
2015-04-07 16:11       ` Giedrius Statkevičius
2015-04-07 16:11     ` [PATCH v4 3/3] staging: dgnc: remove redundant !ch checks Giedrius Statkevičius
2015-04-07 16:11       ` Giedrius Statkevičius
2015-04-10  0:37       ` Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LNX.2.03.1504071453250.17915@localhost.localdomain \
    --to=giedrius.statkevicius@gmail.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=driverdev-devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=lidza.louina@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markh@compro.net \
    --cc=sudipm.mukherjee@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.