[PATCH v2] PCI: rockchip-dwc: Potential error pointer dereference in probe
Lorenzo Pieralisi
lorenzo.pieralisi at arm.com
Mon Aug 23 09:15:27 PDT 2021
On Fri, Aug 13, 2021 at 05:26:48PM +0300, Dan Carpenter wrote:
> 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 at 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(-)
I squashed it in with the patch that is fixing, thanks a lot.
Lorenzo
> 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
>
More information about the linux-arm-kernel
mailing list