Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: gadget: lpc32xx_udc: fix clock imbalance in error path

A recent change fixing a device reference leak introduced a clock
imbalance by reusing an error path so that the clock may be disabled
before having been enabled.

Note that the clock framework allows for passing in NULL clocks so there
is no risk for a NULL pointer dereference.

Also drop the bogus I2C client NULL check added by the offending commit
as the pointer has already been verified to be non-NULL.

Fixes: c84117912bdd ("USB: lpc32xx_udc: Fix error handling in probe")
Cc: stable@vger.kernel.org
Cc: Ma Ke <make24@iscas.ac.cn>
Signed-off-by: Johan Hovold <johan@kernel.org>
Reviewed-by: Vladimir Zapolskiy <vz@mleia.com>
Link: https://patch.msgid.link/20251218153519.19453-2-johan@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Johan Hovold and committed by
Greg Kroah-Hartman
782be79e 5106dbab

+10 -10
+10 -10
drivers/usb/gadget/udc/lpc32xx_udc.c
··· 3020 3020 pdev->dev.dma_mask = &lpc32xx_usbd_dmamask; 3021 3021 retval = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); 3022 3022 if (retval) 3023 - goto i2c_fail; 3023 + goto err_put_client; 3024 3024 3025 3025 udc->board = &lpc32xx_usbddata; 3026 3026 ··· 3040 3040 udc->udp_irq[i] = platform_get_irq(pdev, i); 3041 3041 if (udc->udp_irq[i] < 0) { 3042 3042 retval = udc->udp_irq[i]; 3043 - goto i2c_fail; 3043 + goto err_put_client; 3044 3044 } 3045 3045 } 3046 3046 ··· 3048 3048 if (IS_ERR(udc->udp_baseaddr)) { 3049 3049 dev_err(udc->dev, "IO map failure\n"); 3050 3050 retval = PTR_ERR(udc->udp_baseaddr); 3051 - goto i2c_fail; 3051 + goto err_put_client; 3052 3052 } 3053 3053 3054 3054 /* Get USB device clock */ ··· 3056 3056 if (IS_ERR(udc->usb_slv_clk)) { 3057 3057 dev_err(udc->dev, "failed to acquire USB device clock\n"); 3058 3058 retval = PTR_ERR(udc->usb_slv_clk); 3059 - goto i2c_fail; 3059 + goto err_put_client; 3060 3060 } 3061 3061 3062 3062 /* Enable USB device clock */ 3063 3063 retval = clk_prepare_enable(udc->usb_slv_clk); 3064 3064 if (retval < 0) { 3065 3065 dev_err(udc->dev, "failed to start USB device clock\n"); 3066 - goto i2c_fail; 3066 + goto err_put_client; 3067 3067 } 3068 3068 3069 3069 /* Setup deferred workqueue data */ ··· 3165 3165 dma_free_coherent(&pdev->dev, UDCA_BUFF_SIZE, 3166 3166 udc->udca_v_base, udc->udca_p_base); 3167 3167 i2c_fail: 3168 - if (udc->isp1301_i2c_client) 3169 - put_device(&udc->isp1301_i2c_client->dev); 3170 3168 clk_disable_unprepare(udc->usb_slv_clk); 3169 + err_put_client: 3170 + put_device(&udc->isp1301_i2c_client->dev); 3171 + 3171 3172 dev_err(udc->dev, "%s probe failed, %d\n", driver_name, retval); 3172 3173 3173 3174 return retval; ··· 3196 3195 dma_free_coherent(&pdev->dev, UDCA_BUFF_SIZE, 3197 3196 udc->udca_v_base, udc->udca_p_base); 3198 3197 3199 - if (udc->isp1301_i2c_client) 3200 - put_device(&udc->isp1301_i2c_client->dev); 3201 - 3202 3198 clk_disable_unprepare(udc->usb_slv_clk); 3199 + 3200 + put_device(&udc->isp1301_i2c_client->dev); 3203 3201 } 3204 3202 3205 3203 #ifdef CONFIG_PM