Skip to content

Commit c841179

Browse files
Ma Kegregkh
authored andcommitted
USB: lpc32xx_udc: Fix error handling in probe
lpc32xx_udc_probe() acquires an i2c_client reference through isp1301_get_client() but fails to release it in both error handling paths and the normal removal path. This could result in a reference count leak for the I2C device, preventing proper cleanup and potentially leading to resource exhaustion. Add put_device() to release the reference in the probe failure path and in the remove function. Calling path: isp1301_get_client() -> of_find_i2c_device_by_node() -> i2c_find_device_by_fwnode(). As comments of i2c_find_device_by_fwnode() says, 'The user must call put_device(&client->dev) once done with the i2c client.' Found by code review. Cc: stable <stable@kernel.org> Fixes: 24a28e4 ("USB: gadget driver for LPC32xx") Signed-off-by: Ma Ke <make24@iscas.ac.cn> Link: https://patch.msgid.link/20251215020931.15324-1-make24@iscas.ac.cn Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 128bb7f commit c841179

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

drivers/usb/gadget/udc/lpc32xx_udc.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3020,7 +3020,7 @@ static int lpc32xx_udc_probe(struct platform_device *pdev)
30203020
pdev->dev.dma_mask = &lpc32xx_usbd_dmamask;
30213021
retval = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
30223022
if (retval)
3023-
return retval;
3023+
goto i2c_fail;
30243024

30253025
udc->board = &lpc32xx_usbddata;
30263026

@@ -3038,28 +3038,32 @@ static int lpc32xx_udc_probe(struct platform_device *pdev)
30383038
/* Get IRQs */
30393039
for (i = 0; i < 4; i++) {
30403040
udc->udp_irq[i] = platform_get_irq(pdev, i);
3041-
if (udc->udp_irq[i] < 0)
3042-
return udc->udp_irq[i];
3041+
if (udc->udp_irq[i] < 0) {
3042+
retval = udc->udp_irq[i];
3043+
goto i2c_fail;
3044+
}
30433045
}
30443046

30453047
udc->udp_baseaddr = devm_platform_ioremap_resource(pdev, 0);
30463048
if (IS_ERR(udc->udp_baseaddr)) {
30473049
dev_err(udc->dev, "IO map failure\n");
3048-
return PTR_ERR(udc->udp_baseaddr);
3050+
retval = PTR_ERR(udc->udp_baseaddr);
3051+
goto i2c_fail;
30493052
}
30503053

30513054
/* Get USB device clock */
30523055
udc->usb_slv_clk = devm_clk_get(&pdev->dev, NULL);
30533056
if (IS_ERR(udc->usb_slv_clk)) {
30543057
dev_err(udc->dev, "failed to acquire USB device clock\n");
3055-
return PTR_ERR(udc->usb_slv_clk);
3058+
retval = PTR_ERR(udc->usb_slv_clk);
3059+
goto i2c_fail;
30563060
}
30573061

30583062
/* Enable USB device clock */
30593063
retval = clk_prepare_enable(udc->usb_slv_clk);
30603064
if (retval < 0) {
30613065
dev_err(udc->dev, "failed to start USB device clock\n");
3062-
return retval;
3066+
goto i2c_fail;
30633067
}
30643068

30653069
/* Setup deferred workqueue data */
@@ -3161,6 +3165,8 @@ static int lpc32xx_udc_probe(struct platform_device *pdev)
31613165
dma_free_coherent(&pdev->dev, UDCA_BUFF_SIZE,
31623166
udc->udca_v_base, udc->udca_p_base);
31633167
i2c_fail:
3168+
if (udc->isp1301_i2c_client)
3169+
put_device(&udc->isp1301_i2c_client->dev);
31643170
clk_disable_unprepare(udc->usb_slv_clk);
31653171
dev_err(udc->dev, "%s probe failed, %d\n", driver_name, retval);
31663172

@@ -3189,6 +3195,9 @@ static void lpc32xx_udc_remove(struct platform_device *pdev)
31893195
dma_free_coherent(&pdev->dev, UDCA_BUFF_SIZE,
31903196
udc->udca_v_base, udc->udca_p_base);
31913197

3198+
if (udc->isp1301_i2c_client)
3199+
put_device(&udc->isp1301_i2c_client->dev);
3200+
31923201
clk_disable_unprepare(udc->usb_slv_clk);
31933202
}
31943203

0 commit comments

Comments
 (0)