From: Richard Weinberger Date: Sun, 6 Dec 2020 20:22:20 +0000 (+0100) Subject: mtd: core: Fix refcounting for unpartitioned MTDs X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=1ca71415f075353974524e96ed175306d8a937a8;p=linux.git mtd: core: Fix refcounting for unpartitioned MTDs Apply changes to usecount also to the master partition. Otherwise we have no refcounting at all if an MTD has no partitions. Cc: stable@vger.kernel.org Fixes: 46b5889cc2c5 ("mtd: implement proper partition handling") Signed-off-by: Richard Weinberger Signed-off-by: Miquel Raynal Link: https://lore.kernel.org/linux-mtd/20201206202220.27290-1-richard@nod.at --- diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 31d1be4b22617..2d6423d89a175 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -993,6 +993,8 @@ int __get_mtd_device(struct mtd_info *mtd) } } + master->usecount++; + while (mtd->parent) { mtd->usecount++; mtd = mtd->parent; @@ -1059,6 +1061,8 @@ void __put_mtd_device(struct mtd_info *mtd) mtd = mtd->parent; } + master->usecount--; + if (master->_put_device) master->_put_device(master);