Re: [PATCH] net: dsa: loop: Check for memory allocation failure

From: Joe Perches
Date: Tue May 09 2017 - 11:18:43 EST


On Mon, 2017-05-08 at 17:35 -0700, Florian Fainelli wrote:
> On 05/08/2017 04:46 PM, Julia Lawall wrote:
> > On Mon, 8 May 2017, Joe Perches wrote:
> > > 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;
> > > }
> >
> > Is EPROBE_DEFER handled differently than other kinds of errors?
>
> In the core device driver model, yes, EPROBE_DEFER is treated
> differently than other errors because it puts the driver on a retry queue.
>
> EPROBE_DEFER is already a slow and exceptional path, and this is a
> mock-up driver, so I am not sure what value there is in trying to
> balance devm_kzalloc() with corresponding devm_kfree()...

Example code should be as correct as possible.