ARM: mxs: fix memory leak in mxs_machine_init()
authorZheng Yongjun <zhengyongjun3@huawei.com>
Thu, 17 Nov 2022 06:20:11 +0000 (06:20 +0000)
committerShawn Guo <shawnguo@kernel.org>
Sat, 19 Nov 2022 01:40:36 +0000 (09:40 +0800)
If of_property_read_string() failed, 'soc_dev_attr' should be
freed before return. Otherwise there is a memory leak.

Fixes: 2046338dcbc6 ("ARM: mxs: Use soc bus infrastructure")
Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com>
Reviewed-by: Marco Felsch <m.felsch@pengutronix.de>
Signed-off-by: Shawn Guo <shawnguo@kernel.org>
arch/arm/mach-mxs/mach-mxs.c

index 25c9d184fa4c6da8caef30bdac7306a0caef2165..1c57ac401649382f8db912a54d3d46c512656e44 100644 (file)
@@ -393,8 +393,10 @@ static void __init mxs_machine_init(void)
 
        root = of_find_node_by_path("/");
        ret = of_property_read_string(root, "model", &soc_dev_attr->machine);
-       if (ret)
+       if (ret) {
+               kfree(soc_dev_attr);
                return;
+       }
 
        soc_dev_attr->family = "Freescale MXS Family";
        soc_dev_attr->soc_id = mxs_get_soc_id();