* [patch] mdio_bus: NULL dereference on allocation error
@ 2016-01-12 9:34 ` Dan Carpenter
0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2016-01-12 9:34 UTC (permalink / raw)
To: Florian Fainelli, Andrew Lunn; +Cc: netdev, linux-kernel, kernel-janitors
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>
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++)
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [patch] mdio_bus: NULL dereference on allocation error
@ 2016-01-12 9:34 ` Dan Carpenter
0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2016-01-12 9:34 UTC (permalink / raw)
To: Florian Fainelli, Andrew Lunn; +Cc: netdev, linux-kernel, kernel-janitors
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>
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++)
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [patch] mdio_bus: NULL dereference on allocation error
2016-01-12 9:34 ` Dan Carpenter
@ 2016-01-12 14:06 ` Andrew Lunn
-1 siblings, 0 replies; 6+ messages in thread
From: Andrew Lunn @ 2016-01-12 14:06 UTC (permalink / raw)
To: Dan Carpenter; +Cc: Florian Fainelli, netdev, linux-kernel, kernel-janitors
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++)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch] mdio_bus: NULL dereference on allocation error
@ 2016-01-12 14:06 ` Andrew Lunn
0 siblings, 0 replies; 6+ messages in thread
From: Andrew Lunn @ 2016-01-12 14:06 UTC (permalink / raw)
To: Dan Carpenter; +Cc: Florian Fainelli, netdev, linux-kernel, kernel-janitors
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++)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch] mdio_bus: NULL dereference on allocation error
2016-01-12 9:34 ` Dan Carpenter
@ 2016-01-12 19:31 ` David Miller
-1 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2016-01-12 19:31 UTC (permalink / raw)
To: dan.carpenter; +Cc: f.fainelli, andrew, netdev, linux-kernel, kernel-janitors
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Tue, 12 Jan 2016 12:34:36 +0300
> 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>
Applied.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch] mdio_bus: NULL dereference on allocation error
@ 2016-01-12 19:31 ` David Miller
0 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2016-01-12 19:31 UTC (permalink / raw)
To: dan.carpenter; +Cc: f.fainelli, andrew, netdev, linux-kernel, kernel-janitors
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Tue, 12 Jan 2016 12:34:36 +0300
> 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>
Applied.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-01-12 19:31 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2016-01-12 14:06 ` Andrew Lunn
2016-01-12 19:31 ` David Miller
2016-01-12 19:31 ` David Miller
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.