diff mbox series

ARM: mxs: fix memory leak in mxs_machine_init()

Message ID 20221117062011.84602-1-zhengyongjun3@huawei.com
State New
Headers show
Series ARM: mxs: fix memory leak in mxs_machine_init() | expand

Commit Message

Zheng Yongjun Nov. 17, 2022, 6:20 a.m. UTC
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>
---
 arch/arm/mach-mxs/mach-mxs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

--
2.17.1

Comments

Marco Felsch Nov. 17, 2022, 9:13 a.m. UTC | #1
On 22-11-17, Zheng Yongjun wrote:
> 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>

> ---
>  arch/arm/mach-mxs/mach-mxs.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/mach-mxs/mach-mxs.c b/arch/arm/mach-mxs/mach-mxs.c
> index 25c9d184fa4c..1c57ac401649 100644
> --- a/arch/arm/mach-mxs/mach-mxs.c
> +++ b/arch/arm/mach-mxs/mach-mxs.c
> @@ -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();
> --
> 2.17.1
> 
> 
>
Shawn Guo Nov. 19, 2022, 1:41 a.m. UTC | #2
On Thu, Nov 17, 2022 at 10:13:15AM +0100, Marco Felsch wrote:
> On 22-11-17, Zheng Yongjun wrote:
> > 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>

Applied, thanks!
diff mbox series

Patch

diff --git a/arch/arm/mach-mxs/mach-mxs.c b/arch/arm/mach-mxs/mach-mxs.c
index 25c9d184fa4c..1c57ac401649 100644
--- a/arch/arm/mach-mxs/mach-mxs.c
+++ b/arch/arm/mach-mxs/mach-mxs.c
@@ -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();