From: Lin Yujun Date: Wed, 14 Sep 2022 03:32:06 +0000 (+0800) Subject: clk: imx: scu: fix memleak on platform_device_add() fails X-Git-Tag: baikal/aarch64/sdk6.1~2919^2~2^6 X-Git-Url: https://git.baikalelectronics.ru/?a=commitdiff_plain;h=37176b26c4d84b58e23e308dd29e4980c98eaf6f;p=kernel.git clk: imx: scu: fix memleak on platform_device_add() fails No error handling is performed when platform_device_add() fails. Add error processing before return, and modified the return value. Fixes: deddeb75f9f2 ("clk: imx: scu: add two cells binding support") Signed-off-by: Lin Yujun Link: https://lore.kernel.org/r/20220914033206.98046-1-linyujun809@huawei.com Signed-off-by: Stephen Boyd --- diff --git a/drivers/clk/imx/clk-scu.c b/drivers/clk/imx/clk-scu.c index c56e406138dbe..1e6870f3671f6 100644 --- a/drivers/clk/imx/clk-scu.c +++ b/drivers/clk/imx/clk-scu.c @@ -695,7 +695,11 @@ struct clk_hw *imx_clk_scu_alloc_dev(const char *name, pr_warn("%s: failed to attached the power domain %d\n", name, ret); - platform_device_add(pdev); + ret = platform_device_add(pdev); + if (ret) { + platform_device_put(pdev); + return ERR_PTR(ret); + } /* For API backwards compatiblilty, simply return NULL for success */ return NULL;