From patchwork Thu Apr 13 14:11:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 1768496 X-Patchwork-Delegate: ykai007@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=EEYI9He9; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Py1hx1Gwrz1yZk for ; Fri, 14 Apr 2023 00:11:27 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 93FF385A42; Thu, 13 Apr 2023 16:11:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="EEYI9He9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 88CD985A42; Thu, 13 Apr 2023 16:11:11 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5622785C66 for ; Thu, 13 Apr 2023 16:11:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=eugen.hristev@collabora.com Received: from eugen-station.. (unknown [82.76.24.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ehristev) by madras.collabora.co.uk (Postfix) with ESMTPSA id 5AE8B660321A; Thu, 13 Apr 2023 15:11:07 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1681395067; bh=tLFNnRiDUs68bkqSZP+EZWdgcdzHGPlosUUcyGuU7X8=; h=From:To:Cc:Subject:Date:From; b=EEYI9He9hi4wz1u4iYcPX0X8Q9+laXY3AKVr4PMFuKvzpIca6DoWxqu2Kml/j4AO0 DF85eFTUEkS+7b3nUfJTef2aWlOhasj0zxVxH5PyanjpSI0J2NwtTovPb62bzJhbMp F1GhPEm6GAwSCbYuwvPeejDLazUzzrtP2wjs2fxH1piG0QxRXr28lYzd5GObYkHnue N6A5dw1xNU5L7MhIGhqNwMNgrDPC3u1NNUPkcX1CjtF+NEVhlUsJTud/sszQSsFNb5 YdgYuXV8BIFdwtKZyPIH7AP6bIeZimp8yQZLrHPghsofPh/temJk/Tr7M17SlD4SUX 2Irz3Dxw1uOgA== From: Eugen Hristev To: u-boot@lists.denx.de, kever.yang@rock-chips.com, jonas@kwiboo.se Cc: jagan@edgeble.ai, Eugen Hristev Subject: [PATCH] pci: pcie_dw_rockchip: release resources on failing probe Date: Thu, 13 Apr 2023 17:11:03 +0300 Message-Id: <20230413141103.268571-1-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Implement a resource release mechanism on failing probe. Without this, a strange situation can happen e.g. when init port fails, or attempting to get the PHY fails, because the gpios have been requested first, and if the user tries to do 'pci enum' again, the driver will fail with 'can't find reset gpios' even if the gpios are there, just because they were blocked by a previous probe attempt. It is only natural to release the acquired resources if the probe fails, just for consistency if nothing else. This way on subsequent probe attempts, the user will get the same error message, and not something different that doesn't make sense. Signed-off-by: Eugen Hristev Reviewed-by: Kever Yang --- drivers/pci/pcie_dw_rockchip.c | 41 +++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/drivers/pci/pcie_dw_rockchip.c b/drivers/pci/pcie_dw_rockchip.c index 9322e735b9c3..6155710a9f5f 100644 --- a/drivers/pci/pcie_dw_rockchip.c +++ b/drivers/pci/pcie_dw_rockchip.c @@ -375,29 +375,39 @@ static int rockchip_pcie_parse_dt(struct udevice *dev) ret = reset_get_bulk(dev, &priv->rsts); if (ret) { dev_err(dev, "Can't get reset: %d\n", ret); - return ret; + goto rockchip_pcie_parse_dt_err_reset_get_bulk; } ret = clk_get_bulk(dev, &priv->clks); if (ret) { dev_err(dev, "Can't get clock: %d\n", ret); - return ret; + goto rockchip_pcie_parse_dt_err_clk_get_bulk; } ret = device_get_supply_regulator(dev, "vpcie3v3-supply", &priv->vpcie3v3); if (ret && ret != -ENOENT) { dev_err(dev, "failed to get vpcie3v3 supply (ret=%d)\n", ret); - return ret; + goto rockchip_pcie_parse_dt_err_supply_regulator; } ret = generic_phy_get_by_index(dev, 0, &priv->phy); if (ret) { dev_err(dev, "failed to get pcie phy (ret=%d)\n", ret); - return ret; + goto rockchip_pcie_parse_dt_err_phy_get_by_index; } return 0; + +rockchip_pcie_parse_dt_err_phy_get_by_index: + /* regulators don't need release */ +rockchip_pcie_parse_dt_err_supply_regulator: + clk_release_bulk(&priv->clks); +rockchip_pcie_parse_dt_err_clk_get_bulk: + reset_release_bulk(&priv->rsts); +rockchip_pcie_parse_dt_err_reset_get_bulk: + dm_gpio_free(dev, &priv->rst_gpio); + return ret; } /** @@ -426,7 +436,7 @@ static int rockchip_pcie_probe(struct udevice *dev) ret = rockchip_pcie_init_port(dev); if (ret) - return ret; + goto rockchip_pcie_probe_err_init_port; dev_info(dev, "PCIE-%d: Link up (Gen%d-x%d, Bus%d)\n", dev_seq(dev), pcie_dw_get_link_speed(&priv->dw), @@ -434,12 +444,21 @@ static int rockchip_pcie_probe(struct udevice *dev) hose->first_busno); - return pcie_dw_prog_outbound_atu_unroll(&priv->dw, - PCIE_ATU_REGION_INDEX0, - PCIE_ATU_TYPE_MEM, - priv->dw.mem.phys_start, - priv->dw.mem.bus_start, - priv->dw.mem.size); + ret = pcie_dw_prog_outbound_atu_unroll(&priv->dw, + PCIE_ATU_REGION_INDEX0, + PCIE_ATU_TYPE_MEM, + priv->dw.mem.phys_start, + priv->dw.mem.bus_start, + priv->dw.mem.size); + if (!ret) + return ret; + +rockchip_pcie_probe_err_init_port: + clk_release_bulk(&priv->clks); + reset_release_bulk(&priv->rsts); + dm_gpio_free(dev, &priv->rst_gpio); + + return ret; } static const struct dm_pci_ops rockchip_pcie_ops = {