* [PATCH] mtd: mtd_blkdevs: fix error path in blktrans_open
@ 2011-04-18 5:04 Artem Bityutskiy
2011-04-18 5:02 ` Artem Bityutskiy
0 siblings, 1 reply; 2+ messages in thread
From: Artem Bityutskiy @ 2011-04-18 5:04 UTC (permalink / raw)
To: MTD list; +Cc: Mike Turner
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
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 but returns an error. Instead, it should
_not_ try to get the mtd device, then it should put back the module and kref.
This patch fixes the issue. Note, I only compile-test it but did not test.
This patch was inspired 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>
---
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 a534e1f..ca38569 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)
kref_get(&dev->ref);
__module_get(dev->tr->owner);
- if (dev->mtd) {
- ret = dev->tr->open ? dev->tr->open(dev) : 0;
- __get_mtd_device(dev->mtd);
+ if (!dev->mtd)
+ goto unlock;
+
+ if (dev->tr->open) {
+ ret = dev->tr->open(dev);
+ if (ret)
+ goto error_put;
}
+ ret = __get_mtd_device(dev->mtd);
+ if (ret)
+ goto error_release;
+
unlock:
mutex_unlock(&dev->lock);
blktrans_dev_put(dev);
return ret;
+
+error_release:
+ if (dev->tr->release)
+ dev->tr->release(dev);
+error_put:
+ module_put(dev->tr->owner);
+ kref_put(&dev->ref, blktrans_dev_release);
+ mutex_unlock(&dev->lock);
+ blktrans_dev_put(dev);
+ return ret;
}
static int blktrans_release(struct gendisk *disk, fmode_t mode)
--
1.7.4.2
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] mtd: mtd_blkdevs: fix error path in blktrans_open
2011-04-18 5:04 [PATCH] mtd: mtd_blkdevs: fix error path in blktrans_open Artem Bityutskiy
@ 2011-04-18 5:02 ` Artem Bityutskiy
0 siblings, 0 replies; 2+ messages in thread
From: Artem Bityutskiy @ 2011-04-18 5:02 UTC (permalink / raw)
To: MTD list; +Cc: Mike Turner
On Mon, 2011-04-18 at 08:04 +0300, Artem Bityutskiy wrote:
> From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
>
> 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 but returns an error. Instead, it should
> _not_ try to get the mtd device, then it should put back the module and kref.
>
> This patch fixes the issue. Note, I only compile-test it but did not test.
> This patch was inspired 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>
Fixed typos in the commit message:
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:
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-04-18 5:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-18 5:04 [PATCH] mtd: mtd_blkdevs: fix error path in blktrans_open Artem Bityutskiy
2011-04-18 5:02 ` Artem Bityutskiy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox