From patchwork Fri Sep 23 14:27:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timur Tabi X-Patchwork-Id: 9348219 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 59CCE6077A for ; Fri, 23 Sep 2016 14:29:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B24A2ABED for ; Fri, 23 Sep 2016 14:29:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3FE682ABF1; Fri, 23 Sep 2016 14:29:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3E3C82ABED for ; Fri, 23 Sep 2016 14:29:45 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bnRSh-0002wF-GG; Fri, 23 Sep 2016 14:28:23 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bnRSJ-0002dD-H7 for linux-arm-kernel@lists.infradead.org; Fri, 23 Sep 2016 14:28:00 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 1A45661220; Fri, 23 Sep 2016 14:27:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1474640858; bh=CuuGXGlgAih3EFt7wa7D84SvTsZ8bXIRgDFvItJjoCo=; h=From:To:Subject:Date:From; b=RPjaEsrrEZS/J0adZfEcp25rN03T1ScZL8KVoJyb3TzK87v/4gbEYol8P0T+8SNpG k34KEp5MTBr/L3LYrB2ePEr3Jd5ZUQPw5bzEf7tHxOLBqgooHmSOyEwX4IvUMBmPLF txpFcGiwIyWfIwY88fb40w2LlDl4eA7P1fLY29nQ= Received: from timur-ubuntu.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: timur@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 1EA23611DD; Fri, 23 Sep 2016 14:27:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1474640857; bh=CuuGXGlgAih3EFt7wa7D84SvTsZ8bXIRgDFvItJjoCo=; h=From:To:Subject:Date:From; b=PbEZN0j0rhz8f8ziSxTxHczQEtd/jlt/wSsCR02F4rRW82fNAqj/p5YdRV92j0yiq KincXKlZhsCqxYwy0KgLTSU1hXP/4H4KE9GbMx8aN7f1dg8x7Dz14gRgHKgysGKiC7 5DPtCRI5hrTbgMIkw4RiHRWRk0agpctSA1Z503Hc= DMARC-Filter: OpenDMARC Filter v1.3.1 smtp.codeaurora.org 1EA23611DD Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=pass smtp.mailfrom=timur@codeaurora.org From: Timur Tabi To: netdev@vger.kernel.org, linaro-acpi@lists.linaro.org, linux-arm-kernel@lists.infradead.org, shankerd@codeaurora.org, vikrams@codeaurora.org Subject: [PATCH 1/2] net: qcom/emac: do not use devm on internal phy pdev Date: Fri, 23 Sep 2016 09:27:33 -0500 Message-Id: <1474640854-1698-1-git-send-email-timur@codeaurora.org> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160923_072759_778636_33BC5C72 X-CRM114-Status: GOOD ( 16.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The platform_device returned by of_find_device_by_node() is not automatically released when the driver unprobes. Therefore, managed calls like devm_ioremap_resource() should not be used. Instead, we manually allocate the resources and then free them on driver release. Signed-off-by: Timur Tabi --- drivers/net/ethernet/qualcomm/emac/emac-sgmii.c | 42 +++++++++++++++++++------ drivers/net/ethernet/qualcomm/emac/emac.c | 4 +++ 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/emac/emac-sgmii.c b/drivers/net/ethernet/qualcomm/emac/emac-sgmii.c index 9a9a963..2a095fb 100644 --- a/drivers/net/ethernet/qualcomm/emac/emac-sgmii.c +++ b/drivers/net/ethernet/qualcomm/emac/emac-sgmii.c @@ -681,6 +681,7 @@ int emac_sgmii_config(struct platform_device *pdev, struct emac_adapter *adpt) struct resource *res; const struct of_device_id *match; struct device_node *np; + int ret; np = of_parse_phandle(pdev->dev.of_node, "internal-phy", 0); if (!np) { @@ -697,26 +698,49 @@ int emac_sgmii_config(struct platform_device *pdev, struct emac_adapter *adpt) match = of_match_device(emac_sgmii_dt_match, &sgmii_pdev->dev); if (!match) { dev_err(&pdev->dev, "unrecognized internal phy node\n"); - return -ENODEV; + ret = -ENODEV; + goto error_put_device; } phy->initialize = (emac_sgmii_initialize)match->data; /* Base address is the first address */ res = platform_get_resource(sgmii_pdev, IORESOURCE_MEM, 0); - phy->base = devm_ioremap_resource(&sgmii_pdev->dev, res); - if (IS_ERR(phy->base)) - return PTR_ERR(phy->base); + phy->base = ioremap(res->start, resource_size(res)); + if (IS_ERR(phy->base)) { + ret = PTR_ERR(phy->base); + goto error_put_device; + } /* v2 SGMII has a per-lane digital digital, so parse it if it exists */ res = platform_get_resource(sgmii_pdev, IORESOURCE_MEM, 1); if (res) { - phy->digital = devm_ioremap_resource(&sgmii_pdev->dev, res); - if (IS_ERR(phy->base)) - return PTR_ERR(phy->base); - + phy->digital = ioremap(res->start, resource_size(res)); + if (IS_ERR(phy->digital)) { + ret = PTR_ERR(phy->digital); + goto error_unmap_base; + } } - return phy->initialize(adpt); + ret = phy->initialize(adpt); + if (ret) + goto error; + + /* We've remapped the addresses, so we don't need the device any + * more. of_find_device_by_node() says we should release it. + */ + put_device(&sgmii_pdev->dev); + + return 0; + +error: + if (phy->digital) + iounmap(phy->digital); +error_unmap_base: + iounmap(phy->base); +error_put_device: + put_device(&sgmii_pdev->dev); + + return ret; } diff --git a/drivers/net/ethernet/qualcomm/emac/emac.c b/drivers/net/ethernet/qualcomm/emac/emac.c index e47d387..429b4cb 100644 --- a/drivers/net/ethernet/qualcomm/emac/emac.c +++ b/drivers/net/ethernet/qualcomm/emac/emac.c @@ -723,6 +723,10 @@ static int emac_remove(struct platform_device *pdev) mdiobus_unregister(adpt->mii_bus); free_netdev(netdev); + if (adpt->phy.digital) + iounmap(adpt->phy.digital); + iounmap(adpt->phy.base); + return 0; }