Subject: [PATCH] cpufreq:exynos-cpufreq - Fix for memory leak in case SOC name does not match.

From: [email-masked] (Viresh Kumar)
Date: Sat, 23 May 2015 10:12:02 +0530

On 23-05-15, 08:32, Shailendra Verma wrote:
> During probe free the memory allocated to "exynos_info" in case of
> unknown SOC type.
> 
> Signed-off-by: Shailendra Verma <[email-masked]>
> ---
>  drivers/cpufreq/exynos-cpufreq.c |   15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/cpufreq/exynos-cpufreq.c b/drivers/cpufreq/exynos-cpufreq.c
> index 82d2fbb..5b57a0f 100644
> --- a/drivers/cpufreq/exynos-cpufreq.c
> +++ b/drivers/cpufreq/exynos-cpufreq.c
> @@ -182,20 +182,25 @@ static int exynos_cpufreq_probe(struct platform_device *pdev)
>  		ret = exynos5250_cpufreq_init(exynos_info);
>  	} else {
>  		pr_err("%s: Unknown SoC type\n", __func__);
> -		return -ENODEV;
> +		ret = -ENODEV;
> +		goto err_vdd_arm;

Because we are going to check ret again, don't add the goto here. The
below code will take care of this.

>  	}
> -	if (ret)
> +	if (ret) {
> +		ret = -EINVAL;

Why update ret here ?

>  		goto err_vdd_arm;
> +	}
>  
>  	if (exynos_info->set_freq == NULL) {
>  		dev_err(&pdev->dev, "No set_freq function (ERR)\n");
> +		ret = -EINVAL;
>  		goto err_vdd_arm;
>  	}
>  
>  	arm_regulator = regulator_get(NULL, "vdd_arm");
>  	if (IS_ERR(arm_regulator)) {
>  		dev_err(&pdev->dev, "failed to get resource vdd_arm\n");
> +		ret = -EINVAL;
>  		goto err_vdd_arm;
>  	}
>  
> @@ -203,8 +208,10 @@ static int exynos_cpufreq_probe(struct platform_device *pdev)
>  	locking_frequency = clk_get_rate(exynos_info->cpu_clk) / 1000;
>  
>  	ret = cpufreq_register_driver(&exynos_driver);
> -	if (ret)
> +	if (ret) {
> +		ret = -EINVAL;

Wrong again.

>  		goto err_cpufreq_reg;
> +	}
>  
>  	cpu0 = of_get_cpu_node(0, NULL);
>  	if (!cpu0) {
> @@ -227,7 +234,7 @@ err_cpufreq_reg:
>  	regulator_put(arm_regulator);
>  err_vdd_arm:
>  	kfree(exynos_info);
> -	return -EINVAL;
> +	return ret;
>  }

-- 
viresh