From: Dan Carpenter <dan.carpenter@oracle.com>
To: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: "Rob Herring" <robh@kernel.org>,
"Krzysztof Wilczyński" <kw@linux.com>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Heiko Stuebner" <heiko@sntech.de>,
"Liam Girdwood" <lgirdwood@gmail.com>,
"Mark Brown" <broonie@kernel.org>,
"Shawn Lin" <shawn.lin@rock-chips.com>,
"Kever Yang" <kever.yang@rock-chips.com>,
"Simon Xue" <xxm@rock-chips.com>,
linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-rockchip@lists.infradead.org,
kernel-janitors@vger.kernel.org
Subject: [PATCH v2] PCI: rockchip-dwc: Potential error pointer dereference in probe
Date: Fri, 13 Aug 2021 17:26:48 +0300 [thread overview]
Message-ID: <20210813142648.GA12057@kili> (raw)
In-Reply-To: <20210813141257.GB7722@kadam>
If devm_regulator_get_optional() returns -ENODEV then it would lead
to an error pointer dereference on the next line and in the error
handling code.
Fixes: e1229e884e19 ("PCI: rockchip-dwc: Add Rockchip RK356X host controller driver")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: The -ENODEV from devm_regulator_get_optional() has to be handled
specially.
drivers/pci/controller/dwc/pcie-dw-rockchip.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
index 20cef2e06f66..c9b341e55cbb 100644
--- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
+++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
@@ -224,15 +224,17 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
/* DON'T MOVE ME: must be enable before PHY init */
rockchip->vpcie3v3 = devm_regulator_get_optional(dev, "vpcie3v3");
- if (IS_ERR(rockchip->vpcie3v3))
+ if (IS_ERR(rockchip->vpcie3v3)) {
if (PTR_ERR(rockchip->vpcie3v3) != -ENODEV)
return dev_err_probe(dev, PTR_ERR(rockchip->vpcie3v3),
"failed to get vpcie3v3 regulator\n");
-
- ret = regulator_enable(rockchip->vpcie3v3);
- if (ret) {
- dev_err(dev, "failed to enable vpcie3v3 regulator\n");
- return ret;
+ rockchip->vpcie3v3 = NULL;
+ } else {
+ ret = regulator_enable(rockchip->vpcie3v3);
+ if (ret) {
+ dev_err(dev, "failed to enable vpcie3v3 regulator\n");
+ return ret;
+ }
}
ret = rockchip_pcie_phy_init(rockchip);
@@ -255,7 +257,8 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
deinit_phy:
rockchip_pcie_phy_deinit(rockchip);
disable_regulator:
- regulator_disable(rockchip->vpcie3v3);
+ if (rockchip->vpcie3v3)
+ regulator_disable(rockchip->vpcie3v3);
return ret;
}
--
2.20.1
next prev parent reply other threads:[~2021-08-13 14:27 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-13 11:33 [PATCH] PCI: rockchip-dwc: Potential error pointer dereference in probe Dan Carpenter
2021-08-13 12:55 ` Robin Murphy
2021-08-13 13:34 ` Rob Herring
2021-08-13 13:47 ` Robin Murphy
2021-08-13 15:57 ` Rob Herring
2021-08-13 16:01 ` Mark Brown
2021-08-13 13:54 ` Dan Carpenter
2021-08-13 14:01 ` Robin Murphy
2021-08-13 14:12 ` Dan Carpenter
2021-08-13 14:26 ` Dan Carpenter [this message]
2021-08-23 16:15 ` [PATCH v2] " Lorenzo Pieralisi
2021-08-13 14:32 ` [PATCH] " Mark Brown
2021-08-13 15:00 ` Robin Murphy
2021-08-13 15:30 ` Mark Brown
2021-08-13 15:45 ` Dan Carpenter
2021-08-13 15:53 ` Mark Brown
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=20210813142648.GA12057@kili \
--to=dan.carpenter@oracle.com \
--cc=bhelgaas@google.com \
--cc=broonie@kernel.org \
--cc=heiko@sntech.de \
--cc=kernel-janitors@vger.kernel.org \
--cc=kever.yang@rock-chips.com \
--cc=kw@linux.com \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=robh@kernel.org \
--cc=shawn.lin@rock-chips.com \
--cc=xxm@rock-chips.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).