diff options
author | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2011-04-18 00:50:37 -0400 |
---|---|---|
committer | David Woodhouse <David.Woodhouse@intel.com> | 2011-05-24 20:53:45 -0400 |
commit | 94735ec4044a6d318b83ad3c5794e931ed168d10 (patch) | |
tree | a5704163f225330f25102e8daf5668b2215c86ed /drivers/mtd/mtd_blkdevs.c | |
parent | 5c39c4c54c585e13a8d6b5a8f64af682e7c68091 (diff) |
mtd: mtd_blkdevs: fix error path in blktrans_open
The 'blktrans_open()' does not handle possible '__get_mtd_device()' failures
because it does not check the error code. Moreover, the 'dev->tr->open()'
failures are not handled correctly because in this case the function just
goes ahead and gets the mtd device, then returns an error. But Instead, it
should _not_ try to get the mtd device, then it should put back the module
and the kref.
This patch fixes the issue. Note, I only compile-tested it. This patch was
inspired by a bug report about a similar issue in 2.6.34 kernels
sent by Mike Turner <admin@islandsoftware.co.uk> to the MTD mailing list:
http://lists.infradead.org/pipermail/linux-mtd/2011-April/034980.html
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/mtd/mtd_blkdevs.c')
-rw-r--r-- | drivers/mtd/mtd_blkdevs.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index a534e1f0c348..ca385697446e 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c | |||
@@ -221,15 +221,33 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) | |||
221 | kref_get(&dev->ref); | 221 | kref_get(&dev->ref); |
222 | __module_get(dev->tr->owner); | 222 | __module_get(dev->tr->owner); |
223 | 223 | ||
224 | if (dev->mtd) { | 224 | if (!dev->mtd) |
225 | ret = dev->tr->open ? dev->tr->open(dev) : 0; | 225 | goto unlock; |
226 | __get_mtd_device(dev->mtd); | 226 | |
227 | if (dev->tr->open) { | ||
228 | ret = dev->tr->open(dev); | ||
229 | if (ret) | ||
230 | goto error_put; | ||
227 | } | 231 | } |
228 | 232 | ||
233 | ret = __get_mtd_device(dev->mtd); | ||
234 | if (ret) | ||
235 | goto error_release; | ||
236 | |||
229 | unlock: | 237 | unlock: |
230 | mutex_unlock(&dev->lock); | 238 | mutex_unlock(&dev->lock); |
231 | blktrans_dev_put(dev); | 239 | blktrans_dev_put(dev); |
232 | return ret; | 240 | return ret; |
241 | |||
242 | error_release: | ||
243 | if (dev->tr->release) | ||
244 | dev->tr->release(dev); | ||
245 | error_put: | ||
246 | module_put(dev->tr->owner); | ||
247 | kref_put(&dev->ref, blktrans_dev_release); | ||
248 | mutex_unlock(&dev->lock); | ||
249 | blktrans_dev_put(dev); | ||
250 | return ret; | ||
233 | } | 251 | } |
234 | 252 | ||
235 | static int blktrans_release(struct gendisk *disk, fmode_t mode) | 253 | static int blktrans_release(struct gendisk *disk, fmode_t mode) |