usb: dwc3: st: fix probed platform device ref count on probe error path

commit ddfcfeba891064b88bb844208b43bef2ef970f0c upstream.

The probe function never performs any paltform device allocation, thus
error path "undo_platform_dev_alloc" is entirely bogus.  It drops the
reference count from the platform device being probed.  If error path is
triggered, this will lead to unbalanced device reference counts and
premature release of device resources, thus possible use-after-free when
releasing remaining devm-managed resources.

Fixes: f83fca0707 ("usb: dwc3: add ST dwc3 glue layer to manage dwc3 HC")
Cc: stable@vger.kernel.org
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Link: https://lore.kernel.org/r/20240814093957.37940-1-krzysztof.kozlowski@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Krzysztof Kozlowski 2024-08-14 11:39:56 +02:00 committed by Greg Kroah-Hartman
parent 7bb11a75dd
commit e1e5e8ea27
1 changed files with 3 additions and 8 deletions

View File

@ -219,10 +219,8 @@ static int st_dwc3_probe(struct platform_device *pdev)
dwc3_data->regmap = regmap; dwc3_data->regmap = regmap;
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "syscfg-reg"); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "syscfg-reg");
if (!res) { if (!res)
ret = -ENXIO; return -ENXIO;
goto undo_platform_dev_alloc;
}
dwc3_data->syscfg_reg_off = res->start; dwc3_data->syscfg_reg_off = res->start;
@ -233,8 +231,7 @@ static int st_dwc3_probe(struct platform_device *pdev)
devm_reset_control_get_exclusive(dev, "powerdown"); devm_reset_control_get_exclusive(dev, "powerdown");
if (IS_ERR(dwc3_data->rstc_pwrdn)) { if (IS_ERR(dwc3_data->rstc_pwrdn)) {
dev_err(&pdev->dev, "could not get power controller\n"); dev_err(&pdev->dev, "could not get power controller\n");
ret = PTR_ERR(dwc3_data->rstc_pwrdn); return PTR_ERR(dwc3_data->rstc_pwrdn);
goto undo_platform_dev_alloc;
} }
/* Manage PowerDown */ /* Manage PowerDown */
@ -300,8 +297,6 @@ undo_softreset:
reset_control_assert(dwc3_data->rstc_rst); reset_control_assert(dwc3_data->rstc_rst);
undo_powerdown: undo_powerdown:
reset_control_assert(dwc3_data->rstc_pwrdn); reset_control_assert(dwc3_data->rstc_pwrdn);
undo_platform_dev_alloc:
platform_device_put(pdev);
return ret; return ret;
} }