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

nvmem: core: add a missing of_node_put

'for_each_child_of_node' performs an of_node_get on each iteration, so a
return from the middle of the loop requires an of_node_put.

Fixes: e888d445ac33 ("nvmem: resolve cells from DT at registration time")
Cc: <stable@vger.kernel.org>
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20210611102321.11509-1-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Christophe JAILLET and committed by
Greg Kroah-Hartman
63879e29 fd307a4a

+6 -3
+6 -3
drivers/nvmem/core.c
··· 690 690 continue; 691 691 if (len < 2 * sizeof(u32)) { 692 692 dev_err(dev, "nvmem: invalid reg on %pOF\n", child); 693 + of_node_put(child); 693 694 return -EINVAL; 694 695 } 695 696 696 697 cell = kzalloc(sizeof(*cell), GFP_KERNEL); 697 - if (!cell) 698 + if (!cell) { 699 + of_node_put(child); 698 700 return -ENOMEM; 701 + } 699 702 700 703 cell->nvmem = nvmem; 701 - cell->np = of_node_get(child); 702 704 cell->offset = be32_to_cpup(addr++); 703 705 cell->bytes = be32_to_cpup(addr); 704 706 cell->name = kasprintf(GFP_KERNEL, "%pOFn", child); ··· 721 719 cell->name, nvmem->stride); 722 720 /* Cells already added will be freed later. */ 723 721 kfree_const(cell->name); 724 - of_node_put(cell->np); 725 722 kfree(cell); 723 + of_node_put(child); 726 724 return -EINVAL; 727 725 } 728 726 727 + cell->np = of_node_get(child); 729 728 nvmem_cell_add(cell); 730 729 } 731 730