From patchwork Thu Nov 17 16:40:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 696260 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 3tKTBx05xrz9vKV for ; Fri, 18 Nov 2016 04:48:57 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JbTn+apD"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754948AbcKQRsh (ORCPT ); Thu, 17 Nov 2016 12:48:37 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:32791 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751059AbcKQRsb (ORCPT ); Thu, 17 Nov 2016 12:48:31 -0500 Received: by mail-wm0-f68.google.com with SMTP id u144so23447438wmu.0; Thu, 17 Nov 2016 09:48:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=vPNdy3v0ocDRlE07+GP73wvedtFwWGPcur+f0+dLQEU=; b=JbTn+apDWGMVk3ByKJaHgr4JDsjz8r0Bl5vYsULN/1M5Ig1t6kfssoLco0WPMgeYhe vivKs/JfZBnMoAR5djdWs+cU2F7J2LPYi+ibyfdL1iePgy4bRdHyUIq62F7XTr1MQ1aD ggb3Y/gGJEreVY/fJYJCUOF38L2syIaVn6d5ekf0+QxDoremXHEvgvIjLXPjjD/h6qtH bDAJwF5eWJHsxmKUWPheVIDIkf3Ujbhg2gmflBNypDWJI29cEc7Cc8MXLbVqT4LlpXg1 tCHgLD6vzUNdiW1QgXbA4BFOt9tuzRWbC8yCI3hPmdS97YTNqMnXrzvwoRJDSRrn05mL S+XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=vPNdy3v0ocDRlE07+GP73wvedtFwWGPcur+f0+dLQEU=; b=gWn9H5UFhWV4gqN02LNAbdbQJz6OvkfY90P3tnWASiVXarX0vSz+xI/DaDACAvoJWE eBwR0057qzmX3qEWUO5D/Ss18XTbePgq7pqVgvvcS+3Bt737DMHuXwwyFBbpombqlgpp nnMWrUbo5RgNbwldSClpEb0apmll/qTCCVoVOSY2xBjdLyr2IwpQrP1AlR13mPy6lofi R7rG4qfqygoBAjajs3/AqXoRZkPQAASUMvj7agsHQ1D3KGy/AG2uJVVGhK/021Q8sVqd E575TTEzWvlpsbr7ndMKxilPBYU01v9yfYklpucp13yfmDfG3iz8xJiOgt7cFs4FEC0o Pbqw== X-Gm-Message-State: AKaTC03D6xAOm/1Z2vN2urPTJJeezdb+KYYh38gMTuBj8TS97RCe4WKjIRI/hgKIq7+5IA== X-Received: by 10.46.76.2 with SMTP id z2mr1877727lja.32.1479400817224; Thu, 17 Nov 2016 08:40:17 -0800 (PST) Received: from xi.terra (c-04aadb54.07-184-6d6c6d4.cust.bredbandsbolaget.se. [84.219.170.4]) by smtp.gmail.com with ESMTPSA id 125sm974863ljj.26.2016.11.17.08.40.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Nov 2016 08:40:15 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.87) (envelope-from ) id 1c7PjU-0002Zp-G6; Thu, 17 Nov 2016 17:40:16 +0100 From: Johan Hovold To: Mugunthan V N Cc: Grygorii Strashko , linux-omap@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH net v2 3/7] net: ethernet: ti: cpsw: fix deferred probe Date: Thu, 17 Nov 2016 17:40:00 +0100 Message-Id: <1479400804-9847-4-git-send-email-johan@kernel.org> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1479400804-9847-1-git-send-email-johan@kernel.org> References: <1479400804-9847-1-git-send-email-johan@kernel.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Make sure to deregister all child devices also on probe errors to avoid leaks and to fix probe deferral: cpsw 4a100000.ethernet: omap_device: omap_device_enable() called from invalid state 1 cpsw 4a100000.ethernet: use pm_runtime_put_sync_suspend() in driver? cpsw: probe of 4a100000.ethernet failed with error -22 Add generic helper to undo the effects of cpsw_probe_dt(), which will also be used in a follow-on patch to fix further leaks that have been introduced more recently. Note that the platform device is now runtime-resumed before registering any child devices in order to make sure that it is synchronously suspended after having deregistered the children in the error path. Fixes: 1fb19aa730e4 ("net: cpsw: Add parent<->child relation support between cpsw and mdio") Signed-off-by: Johan Hovold --- drivers/net/ethernet/ti/cpsw.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c index 84c5d214557e..5d14abb06486 100644 --- a/drivers/net/ethernet/ti/cpsw.c +++ b/drivers/net/ethernet/ti/cpsw.c @@ -2441,6 +2441,11 @@ static int cpsw_probe_dt(struct cpsw_platform_data *data, return 0; } +static void cpsw_remove_dt(struct platform_device *pdev) +{ + of_platform_depopulate(&pdev->dev); +} + static int cpsw_probe_dual_emac(struct cpsw_priv *priv) { struct cpsw_common *cpsw = priv->cpsw; @@ -2585,10 +2590,19 @@ static int cpsw_probe(struct platform_device *pdev) /* Select default pin state */ pinctrl_pm_select_default_state(&pdev->dev); + /* Need to enable clocks with runtime PM api to access module + * registers + */ + ret = pm_runtime_get_sync(&pdev->dev); + if (ret < 0) { + pm_runtime_put_noidle(&pdev->dev); + goto clean_runtime_disable_ret; + } + if (cpsw_probe_dt(&cpsw->data, pdev)) { dev_err(&pdev->dev, "cpsw: platform data missing\n"); ret = -ENODEV; - goto clean_runtime_disable_ret; + goto clean_dt_ret; } data = &cpsw->data; cpsw->rx_ch_num = 1; @@ -2609,7 +2623,7 @@ static int cpsw_probe(struct platform_device *pdev) GFP_KERNEL); if (!cpsw->slaves) { ret = -ENOMEM; - goto clean_runtime_disable_ret; + goto clean_dt_ret; } for (i = 0; i < data->slaves; i++) cpsw->slaves[i].slave_num = i; @@ -2621,7 +2635,7 @@ static int cpsw_probe(struct platform_device *pdev) if (IS_ERR(clk)) { dev_err(priv->dev, "fck is not found\n"); ret = -ENODEV; - goto clean_runtime_disable_ret; + goto clean_dt_ret; } cpsw->bus_freq_mhz = clk_get_rate(clk) / 1000000; @@ -2629,25 +2643,17 @@ static int cpsw_probe(struct platform_device *pdev) ss_regs = devm_ioremap_resource(&pdev->dev, ss_res); if (IS_ERR(ss_regs)) { ret = PTR_ERR(ss_regs); - goto clean_runtime_disable_ret; + goto clean_dt_ret; } cpsw->regs = ss_regs; - /* Need to enable clocks with runtime PM api to access module - * registers - */ - ret = pm_runtime_get_sync(&pdev->dev); - if (ret < 0) { - pm_runtime_put_noidle(&pdev->dev); - goto clean_runtime_disable_ret; - } cpsw->version = readl(&cpsw->regs->id_ver); res = platform_get_resource(pdev, IORESOURCE_MEM, 1); cpsw->wr_regs = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(cpsw->wr_regs)) { ret = PTR_ERR(cpsw->wr_regs); - goto clean_pm_runtime_put_ret; + goto clean_dt_ret; } memset(&dma_params, 0, sizeof(dma_params)); @@ -2684,7 +2690,7 @@ static int cpsw_probe(struct platform_device *pdev) default: dev_err(priv->dev, "unknown version 0x%08x\n", cpsw->version); ret = -ENODEV; - goto clean_pm_runtime_put_ret; + goto clean_dt_ret; } for (i = 0; i < cpsw->data.slaves; i++) { struct cpsw_slave *slave = &cpsw->slaves[i]; @@ -2713,7 +2719,7 @@ static int cpsw_probe(struct platform_device *pdev) if (!cpsw->dma) { dev_err(priv->dev, "error initializing dma\n"); ret = -ENOMEM; - goto clean_pm_runtime_put_ret; + goto clean_dt_ret; } cpsw->txch[0] = cpdma_chan_create(cpsw->dma, 0, cpsw_tx_handler, 0); @@ -2823,7 +2829,8 @@ static int cpsw_probe(struct platform_device *pdev) cpsw_ale_destroy(cpsw->ale); clean_dma_ret: cpdma_ctlr_destroy(cpsw->dma); -clean_pm_runtime_put_ret: +clean_dt_ret: + cpsw_remove_dt(pdev); pm_runtime_put_sync(&pdev->dev); clean_runtime_disable_ret: pm_runtime_disable(&pdev->dev); @@ -2850,7 +2857,7 @@ static int cpsw_remove(struct platform_device *pdev) cpsw_ale_destroy(cpsw->ale); cpdma_ctlr_destroy(cpsw->dma); - of_platform_depopulate(&pdev->dev); + cpsw_remove_dt(pdev); pm_runtime_put_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); if (cpsw->data.dual_emac)