All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Julia Lawall <julia.lawall@lip6.fr>,
	David Laight <David.Laight@ACULAB.COM>
Cc: "'Christophe JAILLET'" <christophe.jaillet@wanadoo.fr>,
	"andrew@lunn.ch" <andrew@lunn.ch>,
	"vivien.didelot@savoirfairelinux.com" 
	<vivien.didelot@savoirfairelinux.com>,
	"f.fainelli@gmail.com" <f.fainelli@gmail.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kernel-janitors@vger.kernel.org"
	<kernel-janitors@vger.kernel.org>
Subject: Re: [PATCH] net: dsa: loop: Check for memory allocation failure
Date: Mon, 08 May 2017 10:44:03 -0700	[thread overview]
Message-ID: <1494265443.31950.62.camel@perches.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1705082031280.3440@hadrien>

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;
	}

WARNING: multiple messages have this Message-ID (diff)
From: Joe Perches <joe@perches.com>
To: Julia Lawall <julia.lawall@lip6.fr>,
	David Laight <David.Laight@ACULAB.COM>
Cc: 'Christophe JAILLET' <christophe.jaillet@wanadoo.fr>,
	"andrew@lunn.ch" <andrew@lunn.ch>,
	"vivien.didelot@savoirfairelinux.com"
	<vivien.didelot@savoirfairelinux.com>,
	"f.fainelli@gmail.com" <f.fainelli@gmail.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kernel-janitors@vger.kernel.org"
	<kernel-janitors@vger.kernel.org>
Subject: Re: [PATCH] net: dsa: loop: Check for memory allocation failure
Date: Mon, 08 May 2017 17:44:03 +0000	[thread overview]
Message-ID: <1494265443.31950.62.camel@perches.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1705082031280.3440@hadrien>

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;
	}


  reply	other threads:[~2017-05-08 19:48 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-06  5:29 [PATCH] net: dsa: loop: Check for memory allocation failure Christophe JAILLET
2017-05-06  5:29 ` Christophe JAILLET
2017-05-06 14:45 ` Andrew Lunn
2017-05-06 14:45   ` Andrew Lunn
2017-05-07 23:22 ` Florian Fainelli
2017-05-07 23:22   ` Florian Fainelli
2017-05-08 12:05 ` David Laight
2017-05-08 12:05   ` David Laight
2017-05-08 12:05   ` David Laight
2017-05-08 12:32   ` Julia Lawall
2017-05-08 12:32     ` Julia Lawall
2017-05-08 12:32     ` Julia Lawall
2017-05-08 17:44     ` Joe Perches [this message]
2017-05-08 17:44       ` Joe Perches
2017-05-08 17:44       ` Joe Perches
2017-05-08 23:46       ` Julia Lawall
2017-05-08 23:46         ` Julia Lawall
2017-05-08 23:46         ` Julia Lawall
2017-05-09  0:35         ` Florian Fainelli
2017-05-09  0:35           ` Florian Fainelli
2017-05-09  0:35           ` Florian Fainelli
2017-05-09  0:39           ` Julia Lawall
2017-05-09  0:39             ` Julia Lawall
2017-05-09  0:39             ` Julia Lawall
2017-05-09 15:18           ` Joe Perches
2017-05-09 15:18             ` Joe Perches
2017-05-09 15:18             ` Joe Perches
2017-05-10  4:38             ` Christophe JAILLET
2017-05-10  4:38               ` Christophe JAILLET
2017-05-10  4:46               ` Julia Lawall
2017-05-10  4:46                 ` Julia Lawall
2017-05-10  4:54                 ` Marion & Christophe JAILLET
2017-05-10  4:54                   ` Marion & Christophe JAILLET
2017-05-08 19:01 ` David Miller
2017-05-08 19:01   ` David Miller

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=1494265443.31950.62.camel@perches.com \
    --to=joe@perches.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=andrew@lunn.ch \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=f.fainelli@gmail.com \
    --cc=julia.lawall@lip6.fr \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=vivien.didelot@savoirfairelinux.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.