linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: mdio-sun4i: Convert to devm_* api
@ 2013-08-26 13:11 Jisheng Zhang
  2013-08-28  9:35 ` Maxime Ripard
  0 siblings, 1 reply; 3+ messages in thread
From: Jisheng Zhang @ 2013-08-26 13:11 UTC (permalink / raw)
  To: maxime.ripard, davem, emilio; +Cc: netdev, linux-kernel, Jisheng Zhang

Use devm_ioremap_resource instead of of_iomap() and devm_kzalloc()
instead of kmalloc() to make cleanup paths simpler. This patch also
fixes the resource leak caused by missing corresponding iounamp()
of the of_iomap().

Signed-off-by: Jisheng Zhang <jszhang@marvell.com>
---
 drivers/net/phy/mdio-sun4i.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/net/phy/mdio-sun4i.c b/drivers/net/phy/mdio-sun4i.c
index 7f25e49..18969b3 100644
--- a/drivers/net/phy/mdio-sun4i.c
+++ b/drivers/net/phy/mdio-sun4i.c
@@ -101,6 +101,7 @@ static int sun4i_mdio_probe(struct platform_device *pdev)
 	struct device_node *np = pdev->dev.of_node;
 	struct mii_bus *bus;
 	struct sun4i_mdio_data *data;
+	struct resource *res;
 	int ret, i;
 
 	bus = mdiobus_alloc_size(sizeof(*data));
@@ -114,7 +115,8 @@ static int sun4i_mdio_probe(struct platform_device *pdev)
 	snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(&pdev->dev));
 	bus->parent = &pdev->dev;
 
-	bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
+	bus->irq = devm_kzalloc(&pdev->dev, sizeof(int) * PHY_MAX_ADDR,
+			GFP_KERNEL);
 	if (!bus->irq) {
 		ret = -ENOMEM;
 		goto err_out_free_mdiobus;
@@ -124,10 +126,11 @@ static int sun4i_mdio_probe(struct platform_device *pdev)
 		bus->irq[i] = PHY_POLL;
 
 	data = bus->priv;
-	data->membase = of_iomap(np, 0);
-	if (!data->membase) {
-		ret = -ENOMEM;
-		goto err_out_free_mdio_irq;
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	data->membase = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(data->membase)) {
+		ret = PTR_ERR(data->membase);
+		goto err_out_free_mdiobus;
 	}
 
 	data->regulator = devm_regulator_get(&pdev->dev, "phy");
@@ -139,7 +142,7 @@ static int sun4i_mdio_probe(struct platform_device *pdev)
 	} else {
 		ret = regulator_enable(data->regulator);
 		if (ret)
-			goto err_out_free_mdio_irq;
+			goto err_out_free_mdiobus;
 	}
 
 	ret = of_mdiobus_register(bus, np);
@@ -152,8 +155,6 @@ static int sun4i_mdio_probe(struct platform_device *pdev)
 
 err_out_disable_regulator:
 	regulator_disable(data->regulator);
-err_out_free_mdio_irq:
-	kfree(bus->irq);
 err_out_free_mdiobus:
 	mdiobus_free(bus);
 	return ret;
@@ -164,7 +165,6 @@ static int sun4i_mdio_remove(struct platform_device *pdev)
 	struct mii_bus *bus = platform_get_drvdata(pdev);
 
 	mdiobus_unregister(bus);
-	kfree(bus->irq);
 	mdiobus_free(bus);
 
 	return 0;
-- 
1.8.4.rc3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: mdio-sun4i: Convert to devm_* api
  2013-08-26 13:11 [PATCH] net: mdio-sun4i: Convert to devm_* api Jisheng Zhang
@ 2013-08-28  9:35 ` Maxime Ripard
  2013-08-29 18:55   ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Maxime Ripard @ 2013-08-28  9:35 UTC (permalink / raw)
  To: Jisheng Zhang; +Cc: davem, emilio, netdev, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 586 bytes --]

Hi Jisheng,

On Mon, Aug 26, 2013 at 09:11:57PM +0800, Jisheng Zhang wrote:
> Use devm_ioremap_resource instead of of_iomap() and devm_kzalloc()
> instead of kmalloc() to make cleanup paths simpler. This patch also
> fixes the resource leak caused by missing corresponding iounamp()
> of the of_iomap().
> 
> Signed-off-by: Jisheng Zhang <jszhang@marvell.com>

It looks fine for me.
Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Thanks!
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: mdio-sun4i: Convert to devm_* api
  2013-08-28  9:35 ` Maxime Ripard
@ 2013-08-29 18:55   ` David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2013-08-29 18:55 UTC (permalink / raw)
  To: maxime.ripard; +Cc: jszhang, emilio, netdev, linux-kernel

From: Maxime Ripard <maxime.ripard@free-electrons.com>
Date: Wed, 28 Aug 2013 11:35:08 +0200

> Hi Jisheng,
> 
> On Mon, Aug 26, 2013 at 09:11:57PM +0800, Jisheng Zhang wrote:
>> Use devm_ioremap_resource instead of of_iomap() and devm_kzalloc()
>> instead of kmalloc() to make cleanup paths simpler. This patch also
>> fixes the resource leak caused by missing corresponding iounamp()
>> of the of_iomap().
>> 
>> Signed-off-by: Jisheng Zhang <jszhang@marvell.com>
> 
> It looks fine for me.
> Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Applied to net-next, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-08-29 18:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-26 13:11 [PATCH] net: mdio-sun4i: Convert to devm_* api Jisheng Zhang
2013-08-28  9:35 ` Maxime Ripard
2013-08-29 18:55   ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).