mtd: Fix possible refcounting issue when going through partition nodes
authorMiquel Raynal <miquel.raynal@bootlin.com>
Thu, 4 Jan 2024 08:14:46 +0000 (09:14 +0100)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Mon, 5 Feb 2024 12:39:33 +0000 (13:39 +0100)
commit5ab9bbf6c678444dd99afabd44665e7f04047cc5
tree443bee5cac029b7b46e4a913a25a6baa5a8a81e1
parent59950610c0c00c7a06d8a75d2ee5d73dba4274cf
mtd: Fix possible refcounting issue when going through partition nodes

Under normal conditions, the loop goes over all child partitions, and
'breaks' when the relevant partition is found. In this case we get a
reference to the partition node without ever releasing it. Indeed, right
after the mtd_check_of_node() function returns, we call of_node_get()
again over this very same node. It is probably safer to keep the
counters even in this helper and call of_node_put() before break-ing.

Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Julia Lawall <julia.lawall@inria.fr>
Closes: https://lore.kernel.org/r/202312250546.ISzglvM2-lkp@intel.com/
Cc: Christian Marangi <ansuelsmth@gmail.com>
Cc: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20240104081446.126540-1-miquel.raynal@bootlin.com
drivers/mtd/mtdcore.c