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