Re: [PATCH v4 10/20] nvmem: core: use nvmem_add_one_cell() in nvmem_add_cells_from_of()

From: Michael Walle
Date: Mon Dec 05 2022 - 03:45:51 EST


Am 2022-12-03 09:30, schrieb Dan Carpenter:
Hi Michael,

https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Michael-Walle/nvmem-core-introduce-NVMEM-layouts/20221124-020554
patch link:
https://lore.kernel.org/r/20221123180151.2160033-11-michael%40walle.cc
patch subject: [PATCH v4 10/20] nvmem: core: use nvmem_add_one_cell()
in nvmem_add_cells_from_of()
config: i386-randconfig-m021
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Reported-by: Dan Carpenter <error27@xxxxxxxxx>

New smatch warnings:
drivers/nvmem/core.c:731 nvmem_add_cells_from_of() warn: possible
memory leak of 'cell'

Old smatch warnings:
drivers/nvmem/core.c:735 nvmem_add_cells_from_of() warn: possible
memory leak of 'cell'

vim +/cell +731 drivers/nvmem/core.c

e888d445ac33a5 Bartosz Golaszewski 2018-09-21 689 static int
nvmem_add_cells_from_of(struct nvmem_device *nvmem)
e888d445ac33a5 Bartosz Golaszewski 2018-09-21 690 {
e888d445ac33a5 Bartosz Golaszewski 2018-09-21 691 struct device
*dev = &nvmem->dev;
7ae6478b304bc0 Srinivas Kandagatla 2021-10-13 692 struct
nvmem_cell_entry *cell;
18f50dbcfd3676 Michael Walle 2022-11-23 693 struct device_node *child;
e888d445ac33a5 Bartosz Golaszewski 2018-09-21 694 const __be32 *addr;
18f50dbcfd3676 Michael Walle 2022-11-23 695 int len, ret;
e888d445ac33a5 Bartosz Golaszewski 2018-09-21 696
18f50dbcfd3676 Michael Walle 2022-11-23 697
for_each_child_of_node(dev->of_node, child) {
18f50dbcfd3676 Michael Walle 2022-11-23 698 struct
nvmem_cell_info info = {0};
e888d445ac33a5 Bartosz Golaszewski 2018-09-21 699
e888d445ac33a5 Bartosz Golaszewski 2018-09-21 700 addr =
of_get_property(child, "reg", &len);
0445efacec75b8 Ahmad Fatoum 2021-01-29 701 if (!addr)
0445efacec75b8 Ahmad Fatoum 2021-01-29 702 continue;
0445efacec75b8 Ahmad Fatoum 2021-01-29 703 if (len < 2 *
sizeof(u32)) {
e888d445ac33a5 Bartosz Golaszewski 2018-09-21 704 dev_err(dev,
"nvmem: invalid reg on %pOF\n", child);
63879e2964bcee Christophe JAILLET 2021-06-11 705 of_node_put(child);
e888d445ac33a5 Bartosz Golaszewski 2018-09-21 706 return -EINVAL;
e888d445ac33a5 Bartosz Golaszewski 2018-09-21 707 }
e888d445ac33a5 Bartosz Golaszewski 2018-09-21 708
e888d445ac33a5 Bartosz Golaszewski 2018-09-21 709 cell =
kzalloc(sizeof(*cell), GFP_KERNEL);
63879e2964bcee Christophe JAILLET 2021-06-11 710 if (!cell) {
63879e2964bcee Christophe JAILLET 2021-06-11 711 of_node_put(child);
e888d445ac33a5 Bartosz Golaszewski 2018-09-21 712 return -ENOMEM;
63879e2964bcee Christophe JAILLET 2021-06-11 713 }

Seems like "cell" is not used any more so this just leaks.

Damn, what a stupid bug from me. Thanks for catching this.

-michael