]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
mtd: core: Fix refcounting for unpartitioned MTDs
authorRichard Weinberger <richard@nod.at>
Sun, 6 Dec 2020 20:22:20 +0000 (21:22 +0100)
committerPaolo Pisati <paolo.pisati@canonical.com>
Mon, 4 Jan 2021 15:48:03 +0000 (16:48 +0100)
BugLink: https://bugs.launchpad.net/bugs/1910111
commit 1ca71415f075353974524e96ed175306d8a937a8 upstream.

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 <richard@nod.at>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20201206202220.27290-1-richard@nod.at
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
drivers/mtd/mtdcore.c

index e9e163ae9d863c93139aa7347b6b257b367d64d2..b07cbb0661fb1862528c130df5901ad888a38a76 100644 (file)
@@ -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);