Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thermal/core: Fix memory leak in the error path

Fix the following error:

smatch warnings:
drivers/thermal/thermal_core.c:1020 __thermal_cooling_device_register() warn: possible memory leak of 'cdev'

by freeing the cdev when exiting the function in the error path.

Fixes: 584837618100 ("thermal/drivers/core: Use a char pointer for the cooling device name")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20210319202257.890848-1-daniel.lezcano@linaro.org

+1
+1
drivers/thermal/thermal_core.c
··· 1017 1017 out_ida_remove: 1018 1018 ida_simple_remove(&thermal_cdev_ida, cdev->id); 1019 1019 out_kfree_cdev: 1020 + kfree(cdev); 1020 1021 return ERR_PTR(ret); 1021 1022 } 1022 1023