Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1637675
| From | Joe Perches <joe@perches.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH] net: dsa: loop: Check for memory allocation failure |
| Date | 2017-05-08 21:50 +0200 |
| Message-ID | <tEWPo-8b6-5@gated-at.bofh.it> (permalink) |
| References | <tE0BH-3Xk-5@gated-at.bofh.it> <tEPEe-3LB-9@gated-at.bofh.it> <tEQ7g-3UW-27@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Mon, 2017-05-08 at 20:32 +0800, Julia Lawall wrote:
>
> On Mon, 8 May 2017, David Laight wrote:
>
> > From: Christophe JAILLET
> > > Sent: 06 May 2017 06:30
> > > If 'devm_kzalloc' fails, a NULL pointer will be dereferenced.
> > > Return -ENOMEM instead, as done for some other memory allocation just a
> > > few lines above.
> >
> > ...
> > > --- a/drivers/net/dsa/dsa_loop.c
> > > +++ b/drivers/net/dsa/dsa_loop.c
> > > @@ -256,6 +256,9 @@ static int dsa_loop_drv_probe(struct mdio_device *mdiodev)
> > > return -ENOMEM;
> > >
> > > ps = devm_kzalloc(&mdiodev->dev, sizeof(*ps), GFP_KERNEL);
> > > + if (!ps)
> > > + return -ENOMEM;
> > > +
> > > ps->netdev = dev_get_by_name(&init_net, pdata->netdev);
> > > if (!ps->netdev)
> > > return -EPROBE_DEFER;
> >
> > On the face if it this code leaks like a sieve.
>
> I don't think so. The allocations (dsa_switch_alloc and devm_kzalloc) use
> devm functions.
It's at least wasteful.
Each time -EPROBE_DEFER occurs, another set of calls to
dsa_switch_alloc and dev_kzalloc also occurs.
Perhaps it'd be better to do:
if (ps->netdev) {
devm_kfree(&devmdev->dev, ps);
devm_kfree(&mdiodev->dev, ds);
return -EPROBE_DEFER;
}
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH] net: dsa: loop: Check for memory allocation failure Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2017-05-06 07:40 +0200
Re: [PATCH] net: dsa: loop: Check for memory allocation failure Andrew Lunn <andrew@lunn.ch> - 2017-05-06 16:50 +0200
Re: [PATCH] net: dsa: loop: Check for memory allocation failure Florian Fainelli <f.fainelli@gmail.com> - 2017-05-08 01:30 +0200
RE: [PATCH] net: dsa: loop: Check for memory allocation failure David Laight <David.Laight@ACULAB.COM> - 2017-05-08 14:10 +0200
RE: [PATCH] net: dsa: loop: Check for memory allocation failure Julia Lawall <julia.lawall@lip6.fr> - 2017-05-08 14:40 +0200
Re: [PATCH] net: dsa: loop: Check for memory allocation failure Joe Perches <joe@perches.com> - 2017-05-08 21:50 +0200
Re: [PATCH] net: dsa: loop: Check for memory allocation failure Julia Lawall <julia.lawall@lip6.fr> - 2017-05-09 01:50 +0200
Re: [PATCH] net: dsa: loop: Check for memory allocation failure Florian Fainelli <f.fainelli@gmail.com> - 2017-05-09 02:40 +0200
Re: [PATCH] net: dsa: loop: Check for memory allocation failure Julia Lawall <julia.lawall@lip6.fr> - 2017-05-09 02:50 +0200
Re: [PATCH] net: dsa: loop: Check for memory allocation failure Joe Perches <joe@perches.com> - 2017-05-09 17:20 +0200
Re: [PATCH] net: dsa: loop: Check for memory allocation failure Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2017-05-10 06:40 +0200
Re: [PATCH] net: dsa: loop: Check for memory allocation failure Julia Lawall <julia.lawall@lip6.fr> - 2017-05-10 06:50 +0200
Re: [PATCH] net: dsa: loop: Check for memory allocation failure Marion & Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2017-05-10 07:00 +0200
Re: [PATCH] net: dsa: loop: Check for memory allocation failure David Miller <davem@davemloft.net> - 2017-05-08 21:10 +0200
csiph-web