Message ID | e2b83334ab204ee905fe36ac01cfc297a5a2a7be.1698654061.git.christophe.jaillet@wanadoo.fr |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp2055074vqb; Mon, 30 Oct 2023 01:21:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF66v+vq8BD4snd1x9W39fEPaA0LbDOwPPJiHWEOpTNfl5kYvnWomxaCmGfdkLQ1lwc+Ksj X-Received: by 2002:a17:902:7fcf:b0:1cc:1efb:1bab with SMTP id t15-20020a1709027fcf00b001cc1efb1babmr5710083plb.38.1698654119361; Mon, 30 Oct 2023 01:21:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698654119; cv=none; d=google.com; s=arc-20160816; b=cBzLl8tDFIspuV227JKHE+35IqzCgESt4YqfEzajoHRLQS3DlNZ8D2BsRZMFzy/tgl l0juVHeDfvtnA+Va3dhNLXGvSvJNihj/Io5eX2IA7CNaZLXApw+zVuDJq3JpmLsGbEIg et10epxosau4hoLaIl5W0O1VwTlCCrlE28642exFWPxbLk/p26i5RHi49YJn0nVS4olK fLpsR7OIk6QILIgh/q1Iooddw1Sn/OpS9WiYwrDPNx+t7XVMzpfnpOkeO9Tt51C6A4Fh u3jcT/lzmQLTP9P2NNEdjFzoIndMVA06u6bQbDF0Zl5TtViVmDWQAPmzQWqRsVUy4WRf o3rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=3VXcFUM59+a6yTHwvN11t3YSHRRSpkC7ssA2S+DiK0A=; fh=+P/RXkrEsz+aau1A+coJFqwXvz0rvLPAPQ8TEg7cdCM=; b=Jd7AegXbGFoENplHRsI4dp3tUp5aORePNvDE/iRxEYC03fzNhKwL6RUiX2GA/Lynf7 yvt+tpEkQdzEUFC9Hy/HN2lcSYhlKpZ/6sbEDdxzsge5k4kBFkKKYDA0rOW3yS/GbYFv brWgVKSw8QuWo94rubVXC1BtqxYN6VSDK46Hap72ZwACJKTC1kqtcSH8kC85q7bw/28d 7Ct9cMOqm6w1UJ13jMfnLjFSRm2l1EnPV6325uljYuU1mlB0rgYLAs6RcpHtTRNWeOFL fzTv2f5UYEtk4VbvTCzM8FyCl7rIOeJ2oXpREMRhMurTGZiRGv3ZzRUD8t6w4cjtvoM/ kDVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=ciL54POF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id kk3-20020a170903070300b001cc467a339esi1537859plb.389.2023.10.30.01.21.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 01:21:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=ciL54POF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 56F8E8065018; Mon, 30 Oct 2023 01:21:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231467AbjJ3IV1 (ORCPT <rfc822;zxc52fgh@gmail.com> + 31 others); Mon, 30 Oct 2023 04:21:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232022AbjJ3IV0 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 30 Oct 2023 04:21:26 -0400 Received: from smtp.smtpout.orange.fr (smtp-19.smtpout.orange.fr [80.12.242.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34CD5AB for <linux-kernel@vger.kernel.org>; Mon, 30 Oct 2023 01:21:24 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id xNWPqRZ1MjwlwxNWPqO2Tz; Mon, 30 Oct 2023 09:21:22 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1698654082; bh=3VXcFUM59+a6yTHwvN11t3YSHRRSpkC7ssA2S+DiK0A=; h=From:To:Cc:Subject:Date; b=ciL54POF1xrD14QUPwx63HiBkJ+cEP0l2VpgVDg3lFrzxGHyfqFCb0gB2cWTngbYn adEOjMR4CO+GetQgS2K7cEDJ5z6owMmJQfCiVW7UPEXE3kmCR66jnscVIhNmyXE7W1 afgzgw4TZIYIsUbEAl2qSZAleAvmcyYcj/dbEX7nLaOcp/pmpQnby+UIoE8IAg2Rwa KqqVYhRcN27pRTluiVb5OLQ9yxw52kvvKtXwk+rsTJlEg0Jvyjy4z7m2tIZtv2CFbQ vo9CHWbhgQMT6GbDk7llatDHmUE38ivu79aqtkdjDff+648jJLi69Gvcg53Ts6IXD1 R+H0U1u1U9LsQ== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 30 Oct 2023 09:21:22 +0100 X-ME-IP: 86.243.2.178 From: Christophe JAILLET <christophe.jaillet@wanadoo.fr> To: Xiaowei Song <songxiaowei@hisilicon.com>, Binghui Wang <wangbinghui@hisilicon.com>, Lorenzo Pieralisi <lpieralisi@kernel.org>, =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= <kw@linux.com>, Rob Herring <robh@kernel.org>, Bjorn Helgaas <bhelgaas@google.com>, Jingoo Han <jingoohan1@gmail.com> Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET <christophe.jaillet@wanadoo.fr>, linux-pci@vger.kernel.org Subject: [PATCH] PCI: kirin: Fix an error path in kirin_pcie_probe() Date: Mon, 30 Oct 2023 09:21:16 +0100 Message-Id: <e2b83334ab204ee905fe36ac01cfc297a5a2a7be.1698654061.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 30 Oct 2023 01:21:34 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781167941528537093 X-GMAIL-MSGID: 1781167941528537093 |
Series |
PCI: kirin: Fix an error path in kirin_pcie_probe()
|
|
Commit Message
Christophe JAILLET
Oct. 30, 2023, 8:21 a.m. UTC
If an error occurs after a successful kirin_pcie_power_on(),
kirin_pcie_power_off() should be called, as already done in the remove
function.
Fixes: fc5165db245a ("PCI: kirin: Add HiSilicon Kirin SoC PCIe controller driver")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Not sure of the Fixes tag.
---
drivers/pci/controller/dwc/pcie-kirin.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
Comments
On Mon, Oct 30, 2023 at 09:21:16AM +0100, Christophe JAILLET wrote: > If an error occurs after a successful kirin_pcie_power_on(), > kirin_pcie_power_off() should be called, as already done in the remove > function. > > Fixes: fc5165db245a ("PCI: kirin: Add HiSilicon Kirin SoC PCIe controller driver") > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> > --- > Not sure of the Fixes tag. > --- > drivers/pci/controller/dwc/pcie-kirin.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c > index 2ee146767971..0b93de9d2d06 100644 > --- a/drivers/pci/controller/dwc/pcie-kirin.c > +++ b/drivers/pci/controller/dwc/pcie-kirin.c > @@ -813,7 +813,15 @@ static int kirin_pcie_probe(struct platform_device *pdev) > if (ret) > return ret; > > - return dw_pcie_host_init(&pci->pp); > + ret = dw_pcie_host_init(&pci->pp); > + if (ret) > + goto err_power_off; > + > + return 0; > + > +err_power_off: > + kirin_pcie_power_off(kirin_pcie); > + return ret; From the current driver implementation point of view this looks correct. So Reviewed-by: Serge Semin <fancer.lancer@gmail.com> But the design of the power on/off procedures seems very unfortunate: 1. Calling antagonist from the respective protagonist is a bad solution for maintainability, because shall you need to add something to the protagonist you'll need to somehow take into account that it is reverted in the antagonist only if it was executed, which in its turn will get to be impossible if there are several conditional steps need to be implemented. 2. There is a logical split up between the hi3660 and other controllers. Wherein the hi3660-specific code is implemented as a set of various coherent functions, meanwhile the code for the other controllers is placed directly to the kirin_pcie_power_on() and kirin_pcie_power_off() functions. It looks clumsy and hard-readable. 3. kirin_pcie->gpio_id_dwc_perst is requested and switched to output, but is never freed and got back to input or level zero. -Serge(y) > } > > static struct platform_driver kirin_pcie_driver = { > -- > 2.34.1 >
On Mon, Oct 30, 2023 at 09:21:16AM +0100, Christophe JAILLET wrote: > If an error occurs after a successful kirin_pcie_power_on(), > kirin_pcie_power_off() should be called, as already done in the remove > function. > PERST# assert (gpio_id_dwc_perst) is missing from kirin_pcie_power_off(). So first you need to add that in a separate patch and then this patch can come next. Also, this driver is using legacy GPIO APIs and needs cleanup too (Kudos if you are willing to do that). - Mani > Fixes: fc5165db245a ("PCI: kirin: Add HiSilicon Kirin SoC PCIe controller driver") > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> > --- > Not sure of the Fixes tag. > --- > drivers/pci/controller/dwc/pcie-kirin.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c > index 2ee146767971..0b93de9d2d06 100644 > --- a/drivers/pci/controller/dwc/pcie-kirin.c > +++ b/drivers/pci/controller/dwc/pcie-kirin.c > @@ -813,7 +813,15 @@ static int kirin_pcie_probe(struct platform_device *pdev) > if (ret) > return ret; > > - return dw_pcie_host_init(&pci->pp); > + ret = dw_pcie_host_init(&pci->pp); > + if (ret) > + goto err_power_off; > + > + return 0; > + > +err_power_off: > + kirin_pcie_power_off(kirin_pcie); > + return ret; > } > > static struct platform_driver kirin_pcie_driver = { > -- > 2.34.1 >
diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c index 2ee146767971..0b93de9d2d06 100644 --- a/drivers/pci/controller/dwc/pcie-kirin.c +++ b/drivers/pci/controller/dwc/pcie-kirin.c @@ -813,7 +813,15 @@ static int kirin_pcie_probe(struct platform_device *pdev) if (ret) return ret; - return dw_pcie_host_init(&pci->pp); + ret = dw_pcie_host_init(&pci->pp); + if (ret) + goto err_power_off; + + return 0; + +err_power_off: + kirin_pcie_power_off(kirin_pcie); + return ret; } static struct platform_driver kirin_pcie_driver = {