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

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: f83fca0707c6 ("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>

authored by Krzysztof Kozlowski and committed by Greg Kroah-Hartman ddfcfeba 72fca837

+3 -8
+3 -8
drivers/usb/dwc3/dwc3-st.c
··· 219 219 dwc3_data->regmap = regmap; 220 220 221 221 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "syscfg-reg"); 222 - if (!res) { 223 - ret = -ENXIO; 224 - goto undo_platform_dev_alloc; 225 - } 222 + if (!res) 223 + return -ENXIO; 226 224 227 225 dwc3_data->syscfg_reg_off = res->start; 228 226 ··· 231 233 devm_reset_control_get_exclusive(dev, "powerdown"); 232 234 if (IS_ERR(dwc3_data->rstc_pwrdn)) { 233 235 dev_err(&pdev->dev, "could not get power controller\n"); 234 - ret = PTR_ERR(dwc3_data->rstc_pwrdn); 235 - goto undo_platform_dev_alloc; 236 + return PTR_ERR(dwc3_data->rstc_pwrdn); 236 237 } 237 238 238 239 /* Manage PowerDown */ ··· 297 300 reset_control_assert(dwc3_data->rstc_rst); 298 301 undo_powerdown: 299 302 reset_control_assert(dwc3_data->rstc_pwrdn); 300 - undo_platform_dev_alloc: 301 - platform_device_put(pdev); 302 303 return ret; 303 304 } 304 305