From patchwork Tue Dec 14 22:14:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 523849 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25D7CC433EF for ; Tue, 14 Dec 2021 22:15:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232684AbhLNWPM (ORCPT ); Tue, 14 Dec 2021 17:15:12 -0500 Received: from hostingweb31-40.netsons.net ([89.40.174.40]:50789 "EHLO hostingweb31-40.netsons.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232252AbhLNWPL (ORCPT ); Tue, 14 Dec 2021 17:15:11 -0500 Received: from [77.244.183.192] (port=63782 helo=melee.fritz.box) by hostingweb31.netsons.net with esmtpa (Exim 4.94.2) (envelope-from ) id 1mxG4j-000AP5-UT; Tue, 14 Dec 2021 23:15:10 +0100 From: Luca Ceresoli To: linux-pci@vger.kernel.org Cc: Luca Ceresoli , Dan Carpenter , linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Kishon Vijay Abraham I , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , Sekhar Nori Subject: [PATCH 1/2] PCI: dra7xx: Fix link removal on probe error Date: Tue, 14 Dec 2021 23:14:49 +0100 Message-Id: <20211214221450.589884-1-luca@lucaceresoli.net> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - hostingweb31.netsons.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lucaceresoli.net X-Get-Message-Sender-Via: hostingweb31.netsons.net: authenticated_id: luca+lucaceresoli.net/only user confirmed/virtual account not confirmed X-Authenticated-Sender: hostingweb31.netsons.net: luca@lucaceresoli.net X-Source: X-Source-Args: X-Source-Dir: Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org If a devm_phy_get() calls fails with phy_count==N (N > 0), then N links have already been added by device_link_add() and won't be deleted by device_link_del() because the code calls 'return' and not 'goto err_link'. Fix in a very simple way by doing all the devm_phy_get() calls before all the device_link_add() calls. Fixes: 7a4db656a635 ("PCI: dra7xx: Create functional dependency between PCIe and PHY") Signed-off-by: Luca Ceresoli --- drivers/pci/controller/dwc/pci-dra7xx.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/pci/controller/dwc/pci-dra7xx.c b/drivers/pci/controller/dwc/pci-dra7xx.c index f7f1490e7beb..2ccc53869e13 100644 --- a/drivers/pci/controller/dwc/pci-dra7xx.c +++ b/drivers/pci/controller/dwc/pci-dra7xx.c @@ -757,7 +757,9 @@ static int dra7xx_pcie_probe(struct platform_device *pdev) phy[i] = devm_phy_get(dev, name); if (IS_ERR(phy[i])) return PTR_ERR(phy[i]); + } + for (i = 0; i < phy_count; i++) { link[i] = device_link_add(dev, &phy[i]->dev, DL_FLAG_STATELESS); if (!link[i]) { ret = -EINVAL;