cpufreq: ti-cpufreq: fix memory leak in ti_cpufreq_probe()
PATCH 1/1 cpufreq: ti-cpufreq: fix memory leak in ti_cpufreq_probe()
Similar to commit<05829d9431df>("cpufreq: ti-cpufreq: kfree opp_data when failure"), opp_data needs to be freed when failure, including fail_put_node.
--- drivers/cpufreq/ti-cpufreq.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/cpufreq/ti-cpufreq.c +4 -2
@@ -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; }
Signature · 1 line
1.9.1
kernel test robot
build botThank you for the patch! Yet something to improve:
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
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(a)lists.01.org
Viresh Kumar
maintainerQuoted 1 line · Defang Bo
Similar to commit<05829d9431df>("cpufreq: ti-cpufreq: kfree
opp_datawhen failure"),opp_dataneeds to be freed when failure, includingfail_put_node.
This is allocated using devm_kzalloc() and so we don't need to free it explicitly.
Quoted 20 lines
Signed-off-by Defang Bo <[email protected]>--- drivers/cpufreq/ti-cpufreq.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/cpufreq/ti-cpufreq.c +2
-1@@ -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);
drivers/cpufreq/ti-cpufreq.c static int ti_cpufreq_probe(struct platform_device *pdev) · line 409
Quoted 6 lines
drivers/cpufreq/ti-cpufreq.c +2
-1@@ -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 ?
Quoted 5 lines
drivers/cpufreq/ti-cpufreq.c +0
-0return ret; }Signature · 1 line
1.9.1
Signature · 1 line
viresh