From: Andrew Lunn <andrew@lunn.ch> To: Dan Carpenter <dan.carpenter@oracle.com> Cc: Florian Fainelli <f.fainelli@gmail.com>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [patch] mdio_bus: NULL dereference on allocation error Date: Tue, 12 Jan 2016 15:06:47 +0100 [thread overview] Message-ID: <20160112140647.GA5527@lunn.ch> (raw) In-Reply-To: <20160112093435.GD29804@mwanda> On Tue, Jan 12, 2016 at 12:34:36PM +0300, Dan Carpenter wrote: > If bus = kzalloc() fails then we end up dereferencing bus when we do > "bus->irq[i] = PHY_POLL;". The code is a little simpler if we reverse > the NULL check and return directly on failure. > > Fixes: e7f4dc3536a4 ('mdio: Move allocation of interrupts into core') > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Thanks Andrew > > diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c > index 0be7b3d..0cba64f 100644 > --- a/drivers/net/phy/mdio_bus.c > +++ b/drivers/net/phy/mdio_bus.c > @@ -102,11 +102,12 @@ struct mii_bus *mdiobus_alloc_size(size_t size) > alloc_size = sizeof(*bus); > > bus = kzalloc(alloc_size, GFP_KERNEL); > - if (bus) { > - bus->state = MDIOBUS_ALLOCATED; > - if (size) > - bus->priv = (void *)bus + aligned_size; > - } > + if (!bus) > + return NULL; > + > + bus->state = MDIOBUS_ALLOCATED; > + if (size) > + bus->priv = (void *)bus + aligned_size; > > /* Initialise the interrupts to polling */ > for (i = 0; i < PHY_MAX_ADDR; i++)
WARNING: multiple messages have this Message-ID (diff)
From: Andrew Lunn <andrew@lunn.ch> To: Dan Carpenter <dan.carpenter@oracle.com> Cc: Florian Fainelli <f.fainelli@gmail.com>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [patch] mdio_bus: NULL dereference on allocation error Date: Tue, 12 Jan 2016 14:06:47 +0000 [thread overview] Message-ID: <20160112140647.GA5527@lunn.ch> (raw) In-Reply-To: <20160112093435.GD29804@mwanda> On Tue, Jan 12, 2016 at 12:34:36PM +0300, Dan Carpenter wrote: > If bus = kzalloc() fails then we end up dereferencing bus when we do > "bus->irq[i] = PHY_POLL;". The code is a little simpler if we reverse > the NULL check and return directly on failure. > > Fixes: e7f4dc3536a4 ('mdio: Move allocation of interrupts into core') > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Thanks Andrew > > diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c > index 0be7b3d..0cba64f 100644 > --- a/drivers/net/phy/mdio_bus.c > +++ b/drivers/net/phy/mdio_bus.c > @@ -102,11 +102,12 @@ struct mii_bus *mdiobus_alloc_size(size_t size) > alloc_size = sizeof(*bus); > > bus = kzalloc(alloc_size, GFP_KERNEL); > - if (bus) { > - bus->state = MDIOBUS_ALLOCATED; > - if (size) > - bus->priv = (void *)bus + aligned_size; > - } > + if (!bus) > + return NULL; > + > + bus->state = MDIOBUS_ALLOCATED; > + if (size) > + bus->priv = (void *)bus + aligned_size; > > /* Initialise the interrupts to polling */ > for (i = 0; i < PHY_MAX_ADDR; i++)
next prev parent reply other threads:[~2016-01-12 14:06 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2016-01-12 9:34 [patch] mdio_bus: NULL dereference on allocation error Dan Carpenter 2016-01-12 9:34 ` Dan Carpenter 2016-01-12 14:06 ` Andrew Lunn [this message] 2016-01-12 14:06 ` Andrew Lunn 2016-01-12 19:31 ` David Miller 2016-01-12 19:31 ` 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=20160112140647.GA5527@lunn.ch \ --to=andrew@lunn.ch \ --cc=dan.carpenter@oracle.com \ --cc=f.fainelli@gmail.com \ --cc=kernel-janitors@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=netdev@vger.kernel.org \ /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: linkBe 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.