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 22C49C3DA4A for ; Sat, 27 Jul 2024 06:41:06 +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=KruoNU1ECeduc4ttqiLP75/tZo5xqSr0uZUmxvRMw4Y=; b=oWL8Z35YlTgIRL2YnXes/YA7df hAsO6uMYHHM1SA4GcGcURXFTFbiHNNrsQXprKGoI5R3c8colJmi45byc1sfJuI0Ckgs11MhSPtcf4 RfnerdhSP0o40URjxdoCu0Wr2IjSyATnQwJnkWpLMJ7BUeeyLt30IC15zRvcncb7r41Cx7YFDnnGw rOzFzLtXmfT0bjH9o2nvbT5d1ajH/HyKdpAtQKCueSmiCUI6Ry5cPqZBa8GX8mIsCCjS25j+nxzAV zpxNbQP68+JEDbl9K2vB8PeGYMyj9JmuuOqPZ4pO/0isMTmHAKlxJ8jOBrKD+cDZY3MRmXZl/XuLA 25BkkjAQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXb6o-00000006Cly-2MqH; Sat, 27 Jul 2024 06:40:50 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXb6O-00000006ChL-0QJ8 for linux-arm-kernel@lists.infradead.org; Sat, 27 Jul 2024 06:40:25 +0000 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1fd6ed7688cso11952255ad.3 for ; Fri, 26 Jul 2024 23:40:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1722062423; x=1722667223; 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=KruoNU1ECeduc4ttqiLP75/tZo5xqSr0uZUmxvRMw4Y=; b=P1RnUWqDt/s4w0tSsh0XOcLYYBoUQWOowiW+uPteXIH3RlYq5/YauoQYxP93o0rO3/ O1aUgeRRNLARjm49AVh0XgbciP6YDw4MHoOopYWjue2k3dgQo1yz2BzDylzyON5fOG5J jyNAAB1OJ8BGhjj1oFOsTgr8MQllXHWgdIesw7iM+uAAe61tUd6HlxtzHLSc2RjJa0Pe NCmxNUTPVwAF8AV+WSZU+goFkZsnYenMh44W/uzq2iJVzeUovtdKaPPSQPw8ELZIpLQQ BYx2lGXBCr4NLUk2u5u6qbm/KYoss2bDcxhZhf1/M/lRpuzItfj/4klMjPN37VNUd3oI p+HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722062423; x=1722667223; 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=KruoNU1ECeduc4ttqiLP75/tZo5xqSr0uZUmxvRMw4Y=; b=Fravx8+wuq4qhXgFBy3njCKH+LU0+PAPhR3f2sQ2WYKMyzESv8wZOqYamb+Ie322Mo I4s5oH5awcvw9eJMDRg6NtQ7y8roUHv07wZj30M0mfURHTKvTyF4kpyA80UGIa9mNPq+ oB1F61zQJJ0QUDEwjNg4+qIhTEjFrbbYyhaacSozNhvvv6gHQNA8+0EtvY1VFgC//YsJ uoyAU3Roq4FPzBDVtXiqfiLamRoeH18pCgZ4Qn7m5vSjdgL8DxjD/TC4Hfz3165x/aja f00UQqXxKpFgNpMewavDzRr9wODkO4R9fUKLv9daz2VU0Ir1VwxEX7rsWLdVzfxG53x2 bffg== X-Forwarded-Encrypted: i=1; AJvYcCVQttmOGJRcT8TxjAIhjaKKb5/AHZTad1+196xRrrnY3EpyuX9x98gl1Wmuql44NNQnHFt+Z+asVcFEclyH2x4L20l/dpjMtJXTDcweYhd8qy0ebNo= X-Gm-Message-State: AOJu0YwO2QCOmNIxUVM8HD0ZGHyuKX/YV6ugUIJyw5d/4Nm/hEAA0VWC vgjmWxwyTmVR0JJPyZePHgSMJDqMu2bnOiQObhCtC4LSU2avd7IaPVN6lLNgtg== X-Google-Smtp-Source: AGHT+IENJIkVYk0rpCVthW0PQEkqM+SCa3WgfxY8ADZSjTocFT+s7pDZP7ZlTCOhfSzDNDgG2/7LNA== X-Received: by 2002:a17:903:186:b0:1fd:5fa0:e996 with SMTP id d9443c01a7336-1ff048e4f43mr21262975ad.43.1722062422683; Fri, 26 Jul 2024 23:40:22 -0700 (PDT) Received: from thinkpad ([120.56.198.67]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7f1b6c3sm43588715ad.192.2024.07.26.23.40.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jul 2024 23:40:22 -0700 (PDT) Date: Sat, 27 Jul 2024 12:10:13 +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 , "moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE" , "moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE" , open list Subject: Re: [PATCH v4 03/12] PCI: brcmstb: Use common error handling code in brcm_pcie_probe() Message-ID: <20240727064013.GA2974@thinkpad> References: <20240716213131.6036-1-james.quinlan@broadcom.com> <20240716213131.6036-4-james.quinlan@broadcom.com> <20240725043111.GD2317@thinkpad> <20240726050423.GB2628@thinkpad> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240726_234024_347524_8CFEC5AB X-CRM114-Status: GOOD ( 31.98 ) 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 Fri, Jul 26, 2024 at 02:34:54PM -0400, Jim Quinlan wrote: > On Fri, Jul 26, 2024 at 1:04 AM Manivannan Sadhasivam > wrote: > > > > On Thu, Jul 25, 2024 at 03:45:59PM -0400, Jim Quinlan wrote: > > > On Thu, Jul 25, 2024 at 12:31 AM Manivannan Sadhasivam > > > wrote: > > > > > > > > On Tue, Jul 16, 2024 at 05:31:18PM -0400, Jim Quinlan wrote: > > > > > o Move the clk_prepare_enable() below the resource allocations. > > > > > o Add a jump target (clk_out) so that a bit of exception handling can be > > > > > better reused at the end of this function implementation. > > > > > > > > > > Signed-off-by: Jim Quinlan > > > > > Reviewed-by: Stanimir Varbanov > > > > > Reviewed-by: Florian Fainelli > > > > > --- > > > > > drivers/pci/controller/pcie-brcmstb.c | 29 +++++++++++++++------------ > > > > > 1 file changed, 16 insertions(+), 13 deletions(-) > > > > > > > > > > diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c > > > > > index c08683febdd4..c257434edc08 100644 > > > > > --- a/drivers/pci/controller/pcie-brcmstb.c > > > > > +++ b/drivers/pci/controller/pcie-brcmstb.c > > > > > @@ -1613,31 +1613,30 @@ 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 = clk_prepare_enable(pcie->clk); > > > > > + if (ret) { > > > > > + dev_err(&pdev->dev, "could not enable clock\n"); > > > > > + return ret; > > > > > } > > > > > > > > > > ret = reset_control_reset(pcie->rescal); > > > > > - if (ret) > > > > > + if (ret) { > > > > > dev_err(&pdev->dev, "failed to deassert 'rescal'\n"); > > > > > + goto clk_out; > > > > > > > > Please use a descriptive name for the err labels. Here this err path disables > > > > and unprepares the clk, so use 'clk_disable_unprepare'. > > > ack > > > > > > > > > + } > > > > > > > > > > ret = brcm_phy_start(pcie); > > > > > if (ret) { > > > > > reset_control_rearm(pcie->rescal); > > > > > - clk_disable_unprepare(pcie->clk); > > > > > - return ret; > > > > > + goto clk_out; > > > > > } > > > > > > > > > > ret = brcm_pcie_setup(pcie); > > > > > @@ -1676,6 +1675,10 @@ static int brcm_pcie_probe(struct platform_device *pdev) > > > > > > > > > > return 0; > > > > > > > > > > +clk_out: > > > > > + clk_disable_unprepare(pcie->clk); > > > > > + return ret; > > > > > + > > > > > > > > This is leaking the resources. Move this new label below 'fail'. > > > What resources is it leaking? At "clk_out" the return value will be negative > > > and only managed resources have been allocated at that juncture. > > > > > > > Right, but what about the err path below this one? If that path is taken, then > > clks won't be released, right? > No, that is the same situation. The clock is originally allocated > with "devm_clk_get_optional()", i.e. it is a managed resource. > If the probe fails, and it does in both of these error paths, > Linux deallocates the newly formed device structure and all of its resources. > Perhaps I am missing something? > No, I missed the fact that __brcm_pcie_remove() is freeing all resources. But grouping all release functions in a single helper and using it in multiple err paths even when the err path need not release everything the helper is releasing, warrants trouble. - Mani -- மணிவண்ணன் சதாசிவம்