Skip to content

Commit 5ab9bbf

Browse files
committed
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
1 parent 5995061 commit 5ab9bbf

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

drivers/mtd/mtdcore.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ static void mtd_check_of_node(struct mtd_info *mtd)
621621
if (plen == mtd_name_len &&
622622
!strncmp(mtd->name, pname + offset, plen)) {
623623
mtd_set_of_node(mtd, mtd_dn);
624+
of_node_put(mtd_dn);
624625
break;
625626
}
626627
}

0 commit comments

Comments
 (0)