Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / Atom feed
From: Alex Dewar <alex.dewar90@gmail.com>
Cc: linux-arm-kernel@lists.infradead.org,
	Rob Herring <robh@kernel.org>,
	Florian Fainelli <f.fainelli@gmail.com>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	bcm-kernel-feedback-list@broadcom.com,
	linux-rpi-kernel@lists.infradead.org,
	Bjorn Helgaas <bhelgaas@google.com>,
	Jim Quinlan <jquinlan@broadcom.com>,
	Alex Dewar <alex.dewar90@gmail.com>,
	Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Subject: [PATCH v2] PCI: brcmstb: Add missing if statement and error path
Date: Mon, 21 Sep 2020 22:16:24 +0100
Message-ID: <20200921211623.33908-1-alex.dewar90@gmail.com> (raw)
In-Reply-To: <CA+-6iNwJt4zq1fZv5ujsUJqTs_kcvF9iAcLRp6rtQudwm5CfHA@mail.gmail.com>

brcm_pcie_resume() contains a return statement that was presumably
intended to have an "if (ret)" in front of it, otherwise the function
returns prematurely. Fix this.

Additionally, redisable the clock on the error path.

I don't know if this code was tested or not, but I assume that this bug
means that this driver will not resume properly.

Fixes: ad3d29c77e1e ("PCI: brcmstb: Add control of rescal reset")
Addresses-Coverity: CID 1497099: Control flow issues (UNREACHABLE)
Signed-off-by: Alex Dewar <alex.dewar90@gmail.com>
---
Hi Jim,

Here's a new version of the patch.

I added the missing clk_disable_unprepare() and assumed that it would
also be required in the case that the call to brcm_pcie_setup() fails.

I didn't follow the suggestion of adding extra braces to the
if-statement as the kernel style is not to add unnecessary braces in
this case: https://www.kernel.org/doc/html/latest/process/coding-style.html?highlight=style#placing-braces-and-spaces

Best,
Alex

 drivers/pci/controller/pcie-brcmstb.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c
index 7a3ff4632e7c..8bae3a4f8e49 100644
--- a/drivers/pci/controller/pcie-brcmstb.c
+++ b/drivers/pci/controller/pcie-brcmstb.c
@@ -1154,7 +1154,8 @@ static int brcm_pcie_resume(struct device *dev)
 	clk_prepare_enable(pcie->clk);
 
 	ret = brcm_phy_start(pcie);
-		return ret;
+	if (ret)
+		goto err;
 
 	/* Take bridge out of reset so we can access the SERDES reg */
 	pcie->bridge_sw_init_set(pcie, 0);
@@ -1169,12 +1170,16 @@ static int brcm_pcie_resume(struct device *dev)
 
 	ret = brcm_pcie_setup(pcie);
 	if (ret)
-		return ret;
+		goto err;
 
 	if (pcie->msi)
 		brcm_msi_set_regs(pcie->msi);
 
 	return 0;
+
+err:
+	clk_disable_unprepare(pcie->clk);
+	return ret;
 }
 
 static void __brcm_pcie_remove(struct brcm_pcie *pcie)
-- 
2.28.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-21 20:45 [PATCH] PCI: brcmstb: Add missing if statement Alex Dewar
2020-09-21 20:56 ` Jim Quinlan
2020-09-21 21:16   ` Alex Dewar [this message]
2020-09-21 21:21     ` [PATCH v2] PCI: brcmstb: Add missing if statement and error path Florian Fainelli
2020-09-23  8:20     ` Lorenzo Pieralisi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200921211623.33908-1-alex.dewar90@gmail.com \
    --to=alex.dewar90@gmail.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=bhelgaas@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=jquinlan@broadcom.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=nsaenzjulienne@suse.de \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-ARM-Kernel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/0 linux-arm-kernel/git/0.git
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/1 linux-arm-kernel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-arm-kernel linux-arm-kernel/ https://lore.kernel.org/linux-arm-kernel \
		linux-arm-kernel@lists.infradead.org
	public-inbox-index linux-arm-kernel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-arm-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git