[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.LNX.2.03.1504071453250.17915@localhost.localdomain>
Date: Tue, 7 Apr 2015 14:53:39 +0300 (EEST)
From: Giedrius Statkevičius
<giedrius.statkevicius@...il.com>
To: Sudip Mukherjee <sudipm.mukherjee@...il.com>
cc: Giedrius Statkevičius
<giedrius.statkevicius@...il.com>, lidza.louina@...il.com,
markh@...pro.net, gregkh@...uxfoundation.org,
driverdev-devel@...uxdriverproject.org, devel@...verdev.osuosl.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] staging: dgnc: check if kzalloc fails in
dgnc_tty_init()
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@...il.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
Powered by blists - more mailing lists