usb: fotg210-udc: fix potential memory leak in fotg210_udc_probe()
authorYi Yang <yiyang13@huawei.com>
Fri, 2 Dec 2022 01:21:26 +0000 (09:21 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 8 Dec 2022 15:45:58 +0000 (16:45 +0100)
commit0cd142b4665ee3133cd80539b5a430be5fd326c6
treee7492d44bdfab7a12cf91b64faf86463900bec57
parent59d54aa09020fe52061d4cda51d474f5bd5e6be1
usb: fotg210-udc: fix potential memory leak in fotg210_udc_probe()

In fotg210_udc_probe(), if devm_clk_get() or clk_prepare_enable()
fails, 'fotg210' will not be freed, which will lead to a memory leak.
Fix it by moving kfree() to a proper location.

In addition,we can use "return -ENOMEM" instead of "goto err"
to simplify the code.

Fixes: 718a38d092ec ("fotg210-udc: Handle PCLK")
Reviewed-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Yi Yang <yiyang13@huawei.com>
Link: https://lore.kernel.org/r/20221202012126.246953-1-yiyang13@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/fotg210/fotg210-udc.c