Skip to content

Commit

Permalink
usb: dwc3: st: fix probed platform device ref count on probe error path
Browse files Browse the repository at this point in the history
commit ddfcfeb 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: f83fca0 ("usb: dwc3: add ST dwc3 glue layer to manage dwc3 HC")
Cc: [email protected]
Signed-off-by: Krzysztof Kozlowski <[email protected]>
Acked-by: Thinh Nguyen <[email protected]>
Reviewed-by: Patrice Chotard <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
krzk authored and gregkh committed Sep 4, 2024
1 parent eca3f54 commit b0979a8
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions drivers/usb/dwc3/dwc3-st.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,8 @@ static int st_dwc3_probe(struct platform_device *pdev)
dwc3_data->regmap = regmap;

res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "syscfg-reg");
if (!res) {
ret = -ENXIO;
goto undo_platform_dev_alloc;
}
if (!res)
return -ENXIO;

dwc3_data->syscfg_reg_off = res->start;

Expand All @@ -233,8 +231,7 @@ static int st_dwc3_probe(struct platform_device *pdev)
devm_reset_control_get_exclusive(dev, "powerdown");
if (IS_ERR(dwc3_data->rstc_pwrdn)) {
dev_err(&pdev->dev, "could not get power controller\n");
ret = PTR_ERR(dwc3_data->rstc_pwrdn);
goto undo_platform_dev_alloc;
return PTR_ERR(dwc3_data->rstc_pwrdn);
}

/* Manage PowerDown */
Expand Down Expand Up @@ -296,8 +293,6 @@ static int st_dwc3_probe(struct platform_device *pdev)
reset_control_assert(dwc3_data->rstc_rst);
undo_powerdown:
reset_control_assert(dwc3_data->rstc_pwrdn);
undo_platform_dev_alloc:
platform_device_put(pdev);
return ret;
}

Expand Down

0 comments on commit b0979a8

Please sign in to comment.