linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cpufreq: ti-cpufreq: fix memory leak in ti_cpufreq_probe()
@ 2020-10-19 13:12 Defang Bo
  2020-10-19 19:15 ` kernel test robot
  2020-10-20  7:42 ` Viresh Kumar
  0 siblings, 2 replies; 3+ messages in thread
From: Defang Bo @ 2020-10-19 13:12 UTC (permalink / raw)
  To: rjw, viresh.kumar; +Cc: linux-pm, linux-kernel, Defang Bo

Similar to commit<05829d9431df>("cpufreq: ti-cpufreq: kfree opp_data when failure"), opp_data needs to be freed when failure, including fail_put_node.

Signed-off-by: Defang Bo <bodefang@126.com>
---
 drivers/cpufreq/ti-cpufreq.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/cpufreq/ti-cpufreq.c b/drivers/cpufreq/ti-cpufreq.c
index ab0de27..f23be8f 100644
--- a/drivers/cpufreq/ti-cpufreq.c
+++ b/drivers/cpufreq/ti-cpufreq.c
@@ -342,7 +342,8 @@ static int ti_cpufreq_probe(struct platform_device *pdev)
 	opp_data->cpu_dev = get_cpu_device(0);
 	if (!opp_data->cpu_dev) {
 		pr_err("%s: Failed to get device for CPU0\n", __func__);
-		return -ENODEV;
+		ret = ENODEV;
+		goto free_opp_data;
 	}
 
 	opp_data->opp_node = dev_pm_opp_of_get_opp_desc_node(opp_data->cpu_dev);
@@ -404,7 +405,8 @@ static int ti_cpufreq_probe(struct platform_device *pdev)
 
 fail_put_node:
 	of_node_put(opp_data->opp_node);
-
+free_opp_data:
+	kfree(opp_data)
 	return ret;
 }
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] cpufreq: ti-cpufreq: fix memory leak in ti_cpufreq_probe()
  2020-10-19 13:12 [PATCH] cpufreq: ti-cpufreq: fix memory leak in ti_cpufreq_probe() Defang Bo
@ 2020-10-19 19:15 ` kernel test robot
  2020-10-20  7:42 ` Viresh Kumar
  1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2020-10-19 19:15 UTC (permalink / raw)
  To: Defang Bo, rjw, viresh.kumar
  Cc: kbuild-all, linux-pm, linux-kernel, Defang Bo

[-- Attachment #1: Type: text/plain, Size: 4891 bytes --]

Hi Defang,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on pm/linux-next]
[also build test ERROR on v5.9 next-20201016]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Defang-Bo/cpufreq-ti-cpufreq-fix-memory-leak-in-ti_cpufreq_probe/20201019-214548
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
config: arm-allyesconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/5a1fa3fa4d1aa57096d518b14240a0e5ea50c012
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Defang-Bo/cpufreq-ti-cpufreq-fix-memory-leak-in-ti_cpufreq_probe/20201019-214548
        git checkout 5a1fa3fa4d1aa57096d518b14240a0e5ea50c012
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>):

   drivers/cpufreq/ti-cpufreq.c: In function 'ti_cpufreq_probe':
>> drivers/cpufreq/ti-cpufreq.c:409:17: error: expected ';' before 'return'
     409 |  kfree(opp_data)
         |                 ^
         |                 ;
     410 |  return ret;
         |  ~~~~~~          
>> drivers/cpufreq/ti-cpufreq.c:411:1: warning: control reaches end of non-void function [-Wreturn-type]
     411 | }
         | ^

vim +409 drivers/cpufreq/ti-cpufreq.c

   322	
   323	static int ti_cpufreq_probe(struct platform_device *pdev)
   324	{
   325		u32 version[VERSION_COUNT];
   326		const struct of_device_id *match;
   327		struct opp_table *ti_opp_table;
   328		struct ti_cpufreq_data *opp_data;
   329		const char * const default_reg_names[] = {"vdd", "vbb"};
   330		int ret;
   331	
   332		match = dev_get_platdata(&pdev->dev);
   333		if (!match)
   334			return -ENODEV;
   335	
   336		opp_data = devm_kzalloc(&pdev->dev, sizeof(*opp_data), GFP_KERNEL);
   337		if (!opp_data)
   338			return -ENOMEM;
   339	
   340		opp_data->soc_data = match->data;
   341	
   342		opp_data->cpu_dev = get_cpu_device(0);
   343		if (!opp_data->cpu_dev) {
   344			pr_err("%s: Failed to get device for CPU0\n", __func__);
   345			ret = ENODEV;
   346			goto free_opp_data;
   347		}
   348	
   349		opp_data->opp_node = dev_pm_opp_of_get_opp_desc_node(opp_data->cpu_dev);
   350		if (!opp_data->opp_node) {
   351			dev_info(opp_data->cpu_dev,
   352				 "OPP-v2 not supported, cpufreq-dt will attempt to use legacy tables.\n");
   353			goto register_cpufreq_dt;
   354		}
   355	
   356		ret = ti_cpufreq_setup_syscon_register(opp_data);
   357		if (ret)
   358			goto fail_put_node;
   359	
   360		/*
   361		 * OPPs determine whether or not they are supported based on
   362		 * two metrics:
   363		 *	0 - SoC Revision
   364		 *	1 - eFuse value
   365		 */
   366		ret = ti_cpufreq_get_rev(opp_data, &version[0]);
   367		if (ret)
   368			goto fail_put_node;
   369	
   370		ret = ti_cpufreq_get_efuse(opp_data, &version[1]);
   371		if (ret)
   372			goto fail_put_node;
   373	
   374		ti_opp_table = dev_pm_opp_set_supported_hw(opp_data->cpu_dev,
   375							   version, VERSION_COUNT);
   376		if (IS_ERR(ti_opp_table)) {
   377			dev_err(opp_data->cpu_dev,
   378				"Failed to set supported hardware\n");
   379			ret = PTR_ERR(ti_opp_table);
   380			goto fail_put_node;
   381		}
   382	
   383		opp_data->opp_table = ti_opp_table;
   384	
   385		if (opp_data->soc_data->multi_regulator) {
   386			const char * const *reg_names = default_reg_names;
   387	
   388			if (opp_data->soc_data->reg_names)
   389				reg_names = opp_data->soc_data->reg_names;
   390			ti_opp_table = dev_pm_opp_set_regulators(opp_data->cpu_dev,
   391								 reg_names,
   392								 ARRAY_SIZE(default_reg_names));
   393			if (IS_ERR(ti_opp_table)) {
   394				dev_pm_opp_put_supported_hw(opp_data->opp_table);
   395				ret =  PTR_ERR(ti_opp_table);
   396				goto fail_put_node;
   397			}
   398		}
   399	
   400		of_node_put(opp_data->opp_node);
   401	register_cpufreq_dt:
   402		platform_device_register_simple("cpufreq-dt", -1, NULL, 0);
   403	
   404		return 0;
   405	
   406	fail_put_node:
   407		of_node_put(opp_data->opp_node);
   408	free_opp_data:
 > 409		kfree(opp_data)
   410		return ret;
 > 411	}
   412	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 76238 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] cpufreq: ti-cpufreq: fix memory leak in ti_cpufreq_probe()
  2020-10-19 13:12 [PATCH] cpufreq: ti-cpufreq: fix memory leak in ti_cpufreq_probe() Defang Bo
  2020-10-19 19:15 ` kernel test robot
@ 2020-10-20  7:42 ` Viresh Kumar
  1 sibling, 0 replies; 3+ messages in thread
From: Viresh Kumar @ 2020-10-20  7:42 UTC (permalink / raw)
  To: Defang Bo; +Cc: rjw, linux-pm, linux-kernel

On 19-10-20, 21:12, Defang Bo wrote:
> Similar to commit<05829d9431df>("cpufreq: ti-cpufreq: kfree opp_data when failure"), opp_data needs to be freed when failure, including fail_put_node.

This is allocated using devm_kzalloc() and so we don't need to free it
explicitly.

> Signed-off-by: Defang Bo <bodefang@126.com>
> ---
>  drivers/cpufreq/ti-cpufreq.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/cpufreq/ti-cpufreq.c b/drivers/cpufreq/ti-cpufreq.c
> index ab0de27..f23be8f 100644
> --- a/drivers/cpufreq/ti-cpufreq.c
> +++ b/drivers/cpufreq/ti-cpufreq.c
> @@ -342,7 +342,8 @@ static int ti_cpufreq_probe(struct platform_device *pdev)
>  	opp_data->cpu_dev = get_cpu_device(0);
>  	if (!opp_data->cpu_dev) {
>  		pr_err("%s: Failed to get device for CPU0\n", __func__);
> -		return -ENODEV;
> +		ret = ENODEV;
> +		goto free_opp_data;
>  	}
>  
>  	opp_data->opp_node = dev_pm_opp_of_get_opp_desc_node(opp_data->cpu_dev);
> @@ -404,7 +405,8 @@ static int ti_cpufreq_probe(struct platform_device *pdev)
>  
>  fail_put_node:
>  	of_node_put(opp_data->opp_node);
> -
> +free_opp_data:
> +	kfree(opp_data)

Did you even try to compile this code ?

>  	return ret;
>  }
>  
> -- 
> 1.9.1

-- 
viresh

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-10-20  7:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-19 13:12 [PATCH] cpufreq: ti-cpufreq: fix memory leak in ti_cpufreq_probe() Defang Bo
2020-10-19 19:15 ` kernel test robot
2020-10-20  7:42 ` Viresh Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).