Commit dd3b8a32 authored by Timur Tabi's avatar Timur Tabi Committed by David S. Miller

net/fsl-pq-mdio: coalesce multiple memory allocations into one

Take advantage of the new mdiobus_alloc_size() function to combine three
different memory allocations into one.  This also simplies the error
handling.
Signed-off-by: default avatarTimur Tabi <timur@freescale.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent afae5ad7
...@@ -68,6 +68,7 @@ struct fsl_pq_mdio { ...@@ -68,6 +68,7 @@ struct fsl_pq_mdio {
struct fsl_pq_mdio_priv { struct fsl_pq_mdio_priv {
void __iomem *map; void __iomem *map;
struct fsl_pq_mii __iomem *regs; struct fsl_pq_mii __iomem *regs;
int irqs[PHY_MAX_ADDR];
}; };
/* /*
...@@ -359,26 +360,21 @@ static int fsl_pq_mdio_probe(struct platform_device *pdev) ...@@ -359,26 +360,21 @@ static int fsl_pq_mdio_probe(struct platform_device *pdev)
dev_dbg(&pdev->dev, "found %s compatible node\n", id->compatible); dev_dbg(&pdev->dev, "found %s compatible node\n", id->compatible);
priv = kzalloc(sizeof(*priv), GFP_KERNEL); new_bus = mdiobus_alloc_size(sizeof(*priv));
if (!priv) if (!new_bus)
return -ENOMEM; return -ENOMEM;
new_bus = mdiobus_alloc(); priv = new_bus->priv;
if (!new_bus) {
err = -ENOMEM;
goto err_free_priv;
}
new_bus->name = "Freescale PowerQUICC MII Bus", new_bus->name = "Freescale PowerQUICC MII Bus",
new_bus->read = &fsl_pq_mdio_read; new_bus->read = &fsl_pq_mdio_read;
new_bus->write = &fsl_pq_mdio_write; new_bus->write = &fsl_pq_mdio_write;
new_bus->reset = &fsl_pq_mdio_reset; new_bus->reset = &fsl_pq_mdio_reset;
new_bus->priv = priv; new_bus->irq = priv->irqs;
err = of_address_to_resource(np, 0, &res); err = of_address_to_resource(np, 0, &res);
if (err < 0) { if (err < 0) {
dev_err(&pdev->dev, "could not obtain address information\n"); dev_err(&pdev->dev, "could not obtain address information\n");
goto err_free_bus; goto error;
} }
snprintf(new_bus->id, MII_BUS_ID_SIZE, "%s@%llx", np->name, snprintf(new_bus->id, MII_BUS_ID_SIZE, "%s@%llx", np->name,
...@@ -387,7 +383,7 @@ static int fsl_pq_mdio_probe(struct platform_device *pdev) ...@@ -387,7 +383,7 @@ static int fsl_pq_mdio_probe(struct platform_device *pdev)
priv->map = of_iomap(np, 0); priv->map = of_iomap(np, 0);
if (!priv->map) { if (!priv->map) {
err = -ENOMEM; err = -ENOMEM;
goto err_free_bus; goto error;
} }
/* /*
...@@ -399,16 +395,10 @@ static int fsl_pq_mdio_probe(struct platform_device *pdev) ...@@ -399,16 +395,10 @@ static int fsl_pq_mdio_probe(struct platform_device *pdev)
if (data->mii_offset > resource_size(&res)) { if (data->mii_offset > resource_size(&res)) {
dev_err(&pdev->dev, "invalid register map\n"); dev_err(&pdev->dev, "invalid register map\n");
err = -EINVAL; err = -EINVAL;
goto err_unmap_regs; goto error;
} }
priv->regs = priv->map + data->mii_offset; priv->regs = priv->map + data->mii_offset;
new_bus->irq = kcalloc(PHY_MAX_ADDR, sizeof(int), GFP_KERNEL);
if (NULL == new_bus->irq) {
err = -ENOMEM;
goto err_unmap_regs;
}
new_bus->parent = &pdev->dev; new_bus->parent = &pdev->dev;
dev_set_drvdata(&pdev->dev, new_bus); dev_set_drvdata(&pdev->dev, new_bus);
...@@ -446,19 +436,17 @@ static int fsl_pq_mdio_probe(struct platform_device *pdev) ...@@ -446,19 +436,17 @@ static int fsl_pq_mdio_probe(struct platform_device *pdev)
if (err) { if (err) {
dev_err(&pdev->dev, "cannot register %s as MDIO bus\n", dev_err(&pdev->dev, "cannot register %s as MDIO bus\n",
new_bus->name); new_bus->name);
goto err_free_irqs; goto error;
} }
return 0; return 0;
err_free_irqs: error:
kfree(new_bus->irq); if (priv->map)
err_unmap_regs: iounmap(priv->map);
iounmap(priv->map);
err_free_bus:
kfree(new_bus); kfree(new_bus);
err_free_priv:
kfree(priv);
return err; return err;
} }
...@@ -474,9 +462,7 @@ static int fsl_pq_mdio_remove(struct platform_device *pdev) ...@@ -474,9 +462,7 @@ static int fsl_pq_mdio_remove(struct platform_device *pdev)
dev_set_drvdata(device, NULL); dev_set_drvdata(device, NULL);
iounmap(priv->map); iounmap(priv->map);
bus->priv = NULL;
mdiobus_free(bus); mdiobus_free(bus);
kfree(priv);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment