From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1E210C49EA1 for ; Wed, 7 Aug 2024 02:53:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To: Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=rxNTPURWQk7/dc/jj+R3PwdiQ6MWMSIu7JR1EjXWtLw=; b=cQdmwFHbca6U6C5cIo8ztBGhdD WUqxU2aBAdbH46wSbohrHFPe05aMnxwN7fdVt8V3JCkmrjUdxjzQrfq2BVrdYLeBilLgLNbGCcf+z wW3JHFZLy+nZT26GrFIidS8h2q7a0JnAaLMr7N5qpJIIIgRqhc6ZXXCvIe6tkhAinuS16xB+4rnCO +0LGgNUCj6ED3EdRtKiYUX0AJg8QlM6A+zBKM3rSr1TscX3vTRWeHJ9tPFQek9Ot/LPQrUsaEoMKD XhEjYH6hgyG2jiIzTcSS+ChasztMIKbbxTkM1s4sZhYsDqCt6O3gHWFV9dYKV9b+lPWPhaMFpcQ1U TRYSkQ0Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbWo1-00000003f5R-2BwX; Wed, 07 Aug 2024 02:53:41 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbWnT-00000003eyL-1V0M for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2024 02:53:08 +0000 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1fc566ac769so13779135ad.1 for ; Tue, 06 Aug 2024 19:53:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1722999186; x=1723603986; darn=lists.infradead.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=rxNTPURWQk7/dc/jj+R3PwdiQ6MWMSIu7JR1EjXWtLw=; b=fqVKaIxgHHqQkyc6ktkdgDPfhXxpeO0pAjUwD1d504ZsVSIlzG7VsHUHbUsaC0OFQY 7ouefRja3IDOfdxYYLkOxloCaYvzV3OwSKaQsUqUsFM9/AKOH5Qrr34mNxKuyJVQMKEs Rc8e7JkRPYSjtoh7RHHGmAzbQZP/phUhuJ5e16qZ+NP0wdqGq9Nk9oUH88I4YV4XKxn0 uxSV1ZRVbBK6YoVaYsbqLq0f8mFNLXo1iQ0NUERs430KLRTIIq5i5GUNKCbibSusisL1 xPoG9X6JUl3mgA3XLUlaSLVXxvuDZRI/TMrD6Su5EO0YKtWEybx4OqfyjJIj9qGn8TG5 D5sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722999186; x=1723603986; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rxNTPURWQk7/dc/jj+R3PwdiQ6MWMSIu7JR1EjXWtLw=; b=EecHlInmnsoeQN68J8HO6x9i6eAbdjYO66Fy4Y/q38qnbH/j0YhK9TghwmDv7ewjHy B1BzqC+5xmBsZhozb9TdWQfP0c9y8R0hK9y8ajZAlVssMMttERsyy6QcDTXfnqDxOYot asDK+p/eLlhuiEUybEOp4b98rXef3eG5YhcpZTNywpcOaqRcbnBXcgo5nkpMp2AsS0AM 8z4MYCsCbIhaQ/U9njECPCTZqRTVndrAy4+uwOI0qWh3XdPlopyASzu2n6zd+973teGX sbIdJHKBqMQNr8VYyJD4u+5qaicWiO42g7gXLJGtwTbGNtG+fhczwzvw/JnkU1VRNZvk ovzA== X-Forwarded-Encrypted: i=1; AJvYcCUbxnzZ32M4JQGYCEUiLScItPmQ4XJWqB+aeR7OSlUcuwwNb52eYCydy6zfe/+eYLcn/QpKk5qD6X3K86umtvzhw9H7KLxSEFVT5Sz4Em7LNm+3FMc= X-Gm-Message-State: AOJu0YyJRO1e6DyNApA40+fYpbeyZP7KfdzcClh0esm4MBQykvNkJe2d hAfEnWKrchREt8XJFR1AMPQpmkw3sPjjpvVBAgTCc3x+QanjswiKQpysgpcgqg== X-Google-Smtp-Source: AGHT+IExm1nyHNpY2Df0ueTbO0F5rX3vC1NzqDjMXBn0ObX2Q18HN9I7GSRRDFbcDAWCC26CjfW4JQ== X-Received: by 2002:a17:902:e802:b0:1fb:5c3d:b8c3 with SMTP id d9443c01a7336-1ff57262fa6mr180863515ad.4.1722999185616; Tue, 06 Aug 2024 19:53:05 -0700 (PDT) Received: from thinkpad ([120.60.72.69]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff5929abd1sm94465395ad.271.2024.08.06.19.53.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 19:53:05 -0700 (PDT) Date: Wed, 7 Aug 2024 08:22:52 +0530 From: Manivannan Sadhasivam To: Jim Quinlan Cc: linux-pci@vger.kernel.org, Nicolas Saenz Julienne , Bjorn Helgaas , Lorenzo Pieralisi , Cyril Brulebois , Stanimir Varbanov , Krzysztof Kozlowski , bcm-kernel-feedback-list@broadcom.com, jim2101024@gmail.com, Florian Fainelli , Lorenzo Pieralisi , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Rob Herring , Philipp Zabel , "moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE" , "moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE" , open list Subject: Re: [PATCH v5 03/12] PCI: brcmstb: Use common error handling code in brcm_pcie_probe() Message-ID: <20240807025252.GE3412@thinkpad> References: <20240731222831.14895-1-james.quinlan@broadcom.com> <20240731222831.14895-4-james.quinlan@broadcom.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240731222831.14895-4-james.quinlan@broadcom.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_195307_434754_9A532012 X-CRM114-Status: GOOD ( 25.84 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Jul 31, 2024 at 06:28:17PM -0400, Jim Quinlan wrote: > o Move the clk_prepare_enable() below the resource allocations. > o Move the clk_prepare_enable() out of __brcm_pcie_remove() but > add it to the end of brcm_pcie_remove(). > o Add a jump target (clk_disable_unprepare) so that a bit of exception > handling can be better reused at the end of this function implementation. > o Use dev_err_probe() where it makes sense. > > Signed-off-by: Jim Quinlan > --- > drivers/pci/controller/pcie-brcmstb.c | 34 ++++++++++++--------------- > 1 file changed, 15 insertions(+), 19 deletions(-) > > diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c > index c08683febdd4..7595e7009192 100644 > --- a/drivers/pci/controller/pcie-brcmstb.c > +++ b/drivers/pci/controller/pcie-brcmstb.c > @@ -1473,7 +1473,6 @@ static void __brcm_pcie_remove(struct brcm_pcie *pcie) > dev_err(pcie->dev, "Could not stop phy\n"); > if (reset_control_rearm(pcie->rescal)) > dev_err(pcie->dev, "Could not rearm rescal reset\n"); > - clk_disable_unprepare(pcie->clk); > } > > static void brcm_pcie_remove(struct platform_device *pdev) > @@ -1484,6 +1483,7 @@ static void brcm_pcie_remove(struct platform_device *pdev) > pci_stop_root_bus(bridge->bus); > pci_remove_root_bus(bridge->bus); > __brcm_pcie_remove(pcie); > + clk_disable_unprepare(pcie->clk); > } > > static const int pcie_offsets[] = { > @@ -1613,31 +1613,26 @@ static int brcm_pcie_probe(struct platform_device *pdev) > > pcie->ssc = of_property_read_bool(np, "brcm,enable-ssc"); > > - ret = clk_prepare_enable(pcie->clk); > - if (ret) { > - dev_err(&pdev->dev, "could not enable clock\n"); > - return ret; > - } > pcie->rescal = devm_reset_control_get_optional_shared(&pdev->dev, "rescal"); > - if (IS_ERR(pcie->rescal)) { > - clk_disable_unprepare(pcie->clk); > + if (IS_ERR(pcie->rescal)) > return PTR_ERR(pcie->rescal); > - } > + > pcie->perst_reset = devm_reset_control_get_optional_exclusive(&pdev->dev, "perst"); > - if (IS_ERR(pcie->perst_reset)) { > - clk_disable_unprepare(pcie->clk); > + if (IS_ERR(pcie->perst_reset)) > return PTR_ERR(pcie->perst_reset); > - } > > - ret = reset_control_reset(pcie->rescal); > + ret = clk_prepare_enable(pcie->clk); > if (ret) > - dev_err(&pdev->dev, "failed to deassert 'rescal'\n"); > + return dev_err_probe(&pdev->dev, ret, "could not enable clock\n"); > + > + ret = reset_control_reset(pcie->rescal); > + if (dev_err_probe(&pdev->dev, ret, "failed to deassert 'rescal'\n")) > + goto clk_disable_unprepare; > > ret = brcm_phy_start(pcie); > if (ret) { > reset_control_rearm(pcie->rescal); > - clk_disable_unprepare(pcie->clk); > - return ret; > + goto clk_disable_unprepare; > } > > ret = brcm_pcie_setup(pcie); > @@ -1654,10 +1649,8 @@ static int brcm_pcie_probe(struct platform_device *pdev) > msi_np = of_parse_phandle(pcie->np, "msi-parent", 0); > if (pci_msi_enabled() && msi_np == pcie->np) { > ret = brcm_pcie_enable_msi(pcie); > - if (ret) { > - dev_err(pcie->dev, "probe of internal MSI failed"); > + if (dev_err_probe(pcie->dev, ret, "probe of internal MSI failed")) > goto fail; > - } > } > > bridge->ops = pcie->type == BCM7425 ? &brcm7425_pcie_ops : &brcm_pcie_ops; > @@ -1678,6 +1671,9 @@ static int brcm_pcie_probe(struct platform_device *pdev) > > fail: > __brcm_pcie_remove(pcie); > +clk_disable_unprepare: > + clk_disable_unprepare(pcie->clk); > + TBH, this is not improving the code readability. __brcm_pcie_remove() used to free all the resources and now you just moved clk_disable_unprepare() out of it to save 2 lines in probe(). And you ended up calling clk_disable_unprepare() separately in brcm_pcie_remove(). So please remove the label and call clk_disable_unprepare() in the error path (just 2 instances) and continue to use __brcm_pcie_remove() to free all resources (I would've preferred to have separate error labels instead of calling __brcm_pcie_remove() though, but not this). - Mani -- மணிவண்ணன் சதாசிவம்