linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [linux-next:master 3779/5053] drivers/thermal/thermal_core.c:1020 __thermal_cooling_device_register() warn: possible memory leak of 'cdev'
@ 2021-03-17 14:22 Dan Carpenter
  0 siblings, 0 replies; only message in thread
From: Dan Carpenter @ 2021-03-17 14:22 UTC (permalink / raw)
  To: kbuild, Daniel Lezcano
  Cc: lkp, kbuild-all, Linux Memory Management List, Lukasz Luba

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

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   fa903833ae344e4f4d798a8b85ba3ef0c5ce96c9
commit: 58483761810087e5ffdf36e84ac1bf26df909097 [3779/5053] thermal/drivers/core: Use a char pointer for the cooling device name
config: x86_64-randconfig-m001-20210317 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

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

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

vim +/cdev +1020 drivers/thermal/thermal_core.c

a116b5d44f1445 drivers/thermal/thermal_core.c Eduardo Valentin       2013-09-26   956  static struct thermal_cooling_device *
a116b5d44f1445 drivers/thermal/thermal_core.c Eduardo Valentin       2013-09-26   957  __thermal_cooling_device_register(struct device_node *np,
f991de53a8abef drivers/thermal/thermal_core.c Jean-Francois Dagenais 2019-04-18   958  				  const char *type, void *devdata,
caca8b803520b0 drivers/thermal/thermal_sys.c  Joe Perches            2012-03-21   959  				  const struct thermal_cooling_device_ops *ops)
203d3d4aa48233 drivers/thermal/thermal.c      Zhang Rui              2008-01-17   960  {
203d3d4aa48233 drivers/thermal/thermal.c      Zhang Rui              2008-01-17   961  	struct thermal_cooling_device *cdev;
4511f7166a2deb drivers/thermal/thermal_core.c Chen Yu                2015-10-30   962  	struct thermal_zone_device *pos = NULL;
58483761810087 drivers/thermal/thermal_core.c Daniel Lezcano         2021-03-14   963  	int ret;
203d3d4aa48233 drivers/thermal/thermal.c      Zhang Rui              2008-01-17   964  
203d3d4aa48233 drivers/thermal/thermal.c      Zhang Rui              2008-01-17   965  	if (!ops || !ops->get_max_state || !ops->get_cur_state ||
203d3d4aa48233 drivers/thermal/thermal.c      Zhang Rui              2008-01-17   966  	    !ops->set_cur_state)
3e6fda5c115982 drivers/thermal/thermal.c      Thomas Sujith          2008-02-15   967  		return ERR_PTR(-EINVAL);
203d3d4aa48233 drivers/thermal/thermal.c      Zhang Rui              2008-01-17   968  
95e3ed1513494a drivers/thermal/thermal_core.c Eduardo Valentin       2016-11-07   969  	cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
203d3d4aa48233 drivers/thermal/thermal.c      Zhang Rui              2008-01-17   970  	if (!cdev)
3e6fda5c115982 drivers/thermal/thermal.c      Thomas Sujith          2008-02-15   971  		return ERR_PTR(-ENOMEM);
203d3d4aa48233 drivers/thermal/thermal.c      Zhang Rui              2008-01-17   972  
58483761810087 drivers/thermal/thermal_core.c Daniel Lezcano         2021-03-14   973  	ret = ida_simple_get(&thermal_cdev_ida, 0, 0, GFP_KERNEL);
58483761810087 drivers/thermal/thermal_core.c Daniel Lezcano         2021-03-14   974  	if (ret < 0)
58483761810087 drivers/thermal/thermal_core.c Daniel Lezcano         2021-03-14   975  		goto out_kfree_cdev;
                                                                                                ^^^^^^^^^^^^^^^^^^^^

58483761810087 drivers/thermal/thermal_core.c Daniel Lezcano         2021-03-14   976  	cdev->id = ret;
58483761810087 drivers/thermal/thermal_core.c Daniel Lezcano         2021-03-14   977  
58483761810087 drivers/thermal/thermal_core.c Daniel Lezcano         2021-03-14   978  	cdev->type = kstrdup(type ? type : "", GFP_KERNEL);
58483761810087 drivers/thermal/thermal_core.c Daniel Lezcano         2021-03-14   979  	if (!cdev->type) {
58483761810087 drivers/thermal/thermal_core.c Daniel Lezcano         2021-03-14   980  		ret = -ENOMEM;
58483761810087 drivers/thermal/thermal_core.c Daniel Lezcano         2021-03-14   981  		goto out_ida_remove;
203d3d4aa48233 drivers/thermal/thermal.c      Zhang Rui              2008-01-17   982  	}
203d3d4aa48233 drivers/thermal/thermal.c      Zhang Rui              2008-01-17   983  
f4a821ce6ed419 drivers/thermal/thermal_sys.c  Zhang Rui              2012-07-24   984  	mutex_init(&cdev->lock);
b5e4ae620b0627 drivers/thermal/thermal_sys.c  Zhang Rui              2012-06-27   985  	INIT_LIST_HEAD(&cdev->thermal_instances);
a116b5d44f1445 drivers/thermal/thermal_core.c Eduardo Valentin       2013-09-26   986  	cdev->np = np;
203d3d4aa48233 drivers/thermal/thermal.c      Zhang Rui              2008-01-17   987  	cdev->ops = ops;
5ca0cce5622bf4 drivers/thermal/thermal_core.c Ni Wade                2014-02-17   988  	cdev->updated = false;
203d3d4aa48233 drivers/thermal/thermal.c      Zhang Rui              2008-01-17   989  	cdev->device.class = &thermal_class;
203d3d4aa48233 drivers/thermal/thermal.c      Zhang Rui              2008-01-17   990  	cdev->devdata = devdata;
8ea229511e06f9 drivers/thermal/thermal_core.c Viresh Kumar           2018-04-02   991  	thermal_cooling_device_setup_sysfs(cdev);
354655ea9714e5 drivers/thermal/thermal_sys.c  Kay Sievers            2009-01-06   992  	dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
58483761810087 drivers/thermal/thermal_core.c Daniel Lezcano         2021-03-14   993  	ret = device_register(&cdev->device);
58483761810087 drivers/thermal/thermal_core.c Daniel Lezcano         2021-03-14   994  	if (ret)
58483761810087 drivers/thermal/thermal_core.c Daniel Lezcano         2021-03-14   995  		goto out_kfree_type;
203d3d4aa48233 drivers/thermal/thermal.c      Zhang Rui              2008-01-17   996  
7e8ee1e9d7561f drivers/thermal/thermal_sys.c  Durgadoss R            2012-09-18   997  	/* Add 'this' new cdev to the global cdev list */
203d3d4aa48233 drivers/thermal/thermal.c      Zhang Rui              2008-01-17   998  	mutex_lock(&thermal_list_lock);
203d3d4aa48233 drivers/thermal/thermal.c      Zhang Rui              2008-01-17   999  	list_add(&cdev->node, &thermal_cdev_list);
203d3d4aa48233 drivers/thermal/thermal.c      Zhang Rui              2008-01-17  1000  	mutex_unlock(&thermal_list_lock);
203d3d4aa48233 drivers/thermal/thermal.c      Zhang Rui              2008-01-17  1001  
7e8ee1e9d7561f drivers/thermal/thermal_sys.c  Durgadoss R            2012-09-18  1002  	/* Update binding information for 'this' new cdev */
7e8ee1e9d7561f drivers/thermal/thermal_sys.c  Durgadoss R            2012-09-18  1003  	bind_cdev(cdev);
7e8ee1e9d7561f drivers/thermal/thermal_sys.c  Durgadoss R            2012-09-18  1004  
4511f7166a2deb drivers/thermal/thermal_core.c Chen Yu                2015-10-30  1005  	mutex_lock(&thermal_list_lock);
4511f7166a2deb drivers/thermal/thermal_core.c Chen Yu                2015-10-30  1006  	list_for_each_entry(pos, &thermal_tz_list, node)
4511f7166a2deb drivers/thermal/thermal_core.c Chen Yu                2015-10-30  1007  		if (atomic_cmpxchg(&pos->need_update, 1, 0))
0e70f466fb910a drivers/thermal/thermal_core.c Srinivas Pandruvada    2016-08-26  1008  			thermal_zone_device_update(pos,
0e70f466fb910a drivers/thermal/thermal_core.c Srinivas Pandruvada    2016-08-26  1009  						   THERMAL_EVENT_UNSPECIFIED);
4511f7166a2deb drivers/thermal/thermal_core.c Chen Yu                2015-10-30  1010  	mutex_unlock(&thermal_list_lock);
4511f7166a2deb drivers/thermal/thermal_core.c Chen Yu                2015-10-30  1011  
203d3d4aa48233 drivers/thermal/thermal.c      Zhang Rui              2008-01-17  1012  	return cdev;
58483761810087 drivers/thermal/thermal_core.c Daniel Lezcano         2021-03-14  1013  
58483761810087 drivers/thermal/thermal_core.c Daniel Lezcano         2021-03-14  1014  out_kfree_type:
58483761810087 drivers/thermal/thermal_core.c Daniel Lezcano         2021-03-14  1015  	kfree(cdev->type);
58483761810087 drivers/thermal/thermal_core.c Daniel Lezcano         2021-03-14  1016  	put_device(&cdev->device);
58483761810087 drivers/thermal/thermal_core.c Daniel Lezcano         2021-03-14  1017  out_ida_remove:
58483761810087 drivers/thermal/thermal_core.c Daniel Lezcano         2021-03-14  1018  	ida_simple_remove(&thermal_cdev_ida, cdev->id);
58483761810087 drivers/thermal/thermal_core.c Daniel Lezcano         2021-03-14  1019  out_kfree_cdev:

Presumably there was supposed to be a kfree(cdev) here.  ;)

58483761810087 drivers/thermal/thermal_core.c Daniel Lezcano         2021-03-14 @1020  	return ERR_PTR(ret);
203d3d4aa48233 drivers/thermal/thermal.c      Zhang Rui              2008-01-17  1021  }

---
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: 34560 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-17 14:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-17 14:22 [linux-next:master 3779/5053] drivers/thermal/thermal_core.c:1020 __thermal_cooling_device_register() warn: possible memory leak of 'cdev' Dan Carpenter

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).