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

mtd: blkdevs: do not forget to get MTD devices

Nowadays MTD devices have to be "get" before they can be
used. This has to be done with 'get_mtd_device()'. The
'blktrans_open()' function did not do this and instead
used 'try_module_get()'. Fix this.

Since 'get_mtd_device()' already gets the module, extra
'try_module_get()' is not needed.

This fixes oops when one tries to use mtdblock on top of
gluebi.

Reported-by: Holger Brunck <holger.brunck@keymile.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>

authored by

Artem Bityutskiy and committed by
David Woodhouse
8022c13c 6afc4fdb

+3 -3
+3 -3
drivers/mtd/mtd_blkdevs.c
··· 144 144 struct mtd_blktrans_ops *tr = dev->tr; 145 145 int ret = -ENODEV; 146 146 147 - if (!try_module_get(dev->mtd->owner)) 147 + if (!get_mtd_device(NULL, dev->mtd->index)) 148 148 goto out; 149 149 150 150 if (!try_module_get(tr->owner)) ··· 158 158 ret = 0; 159 159 if (tr->open && (ret = tr->open(dev))) { 160 160 dev->mtd->usecount--; 161 - module_put(dev->mtd->owner); 161 + put_mtd_device(dev->mtd); 162 162 out_tr: 163 163 module_put(tr->owner); 164 164 } ··· 177 177 178 178 if (!ret) { 179 179 dev->mtd->usecount--; 180 - module_put(dev->mtd->owner); 180 + put_mtd_device(dev->mtd); 181 181 module_put(tr->owner); 182 182 } 183 183