From patchwork Mon Aug 26 13:11:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 269884 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3EAEB2C00A1 for ; Mon, 26 Aug 2013 23:25:27 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756485Ab3HZNZY (ORCPT ); Mon, 26 Aug 2013 09:25:24 -0400 Received: from na3sys009aog134.obsmtp.com ([74.125.149.83]:33398 "EHLO na3sys009aog134.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751722Ab3HZNZX (ORCPT ); Mon, 26 Aug 2013 09:25:23 -0400 Received: from sc-owa02.marvell.com ([199.233.58.137]) (using TLSv1) by na3sys009aob134.postini.com ([74.125.148.12]) with SMTP ID DSNKUhtXQpZP2yv6qRRC9MizcvNxuZASWqM2@postini.com; Mon, 26 Aug 2013 06:25:23 PDT Received: from maili.marvell.com (10.93.76.43) by sc-owa02.marvell.com (10.93.76.22) with Microsoft SMTP Server id 8.3.213.0; Mon, 26 Aug 2013 06:13:31 -0700 Received: from xhacker.marvell.com (unknown [10.37.135.179]) by maili.marvell.com (Postfix) with ESMTP id 42B131CCDBF; Mon, 26 Aug 2013 06:13:30 -0700 (PDT) From: Jisheng Zhang To: , , CC: , , Jisheng Zhang Subject: [PATCH] net: mdio-sun4i: Convert to devm_* api Date: Mon, 26 Aug 2013 21:11:57 +0800 Message-ID: <1377522717-5784-1-git-send-email-jszhang@marvell.com> X-Mailer: git-send-email 1.8.4.rc3 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 Acked-by: Maxime Ripard --- 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;