From: Zahari Doychev <zahari.doychev@linux.com>
To: barebox@lists.infradead.org
Subject: [PATCH] drivers/mtd: fix NULL pointer dereference in partition lock/unlock
Date: Tue, 8 Jul 2014 09:37:35 +0200 [thread overview]
Message-ID: <a2949dd62538a64ec5689b63d6ff531620ceb198.1404734020.git.zahari.doychev@linux.com> (raw)
In-Reply-To: <cover.1404734020.git.zahari.doychev@linux.com>
In-Reply-To: <cover.1404734020.git.zahari.doychev@linux.com>
Some mtd device does not support lock and unlock functions. Adding this check
avoids crashing when mtd_part_lock/unlock are called for such devices.
Signed-off-by: Zahari Doychev <zahari.doychev@linux.com>
---
drivers/mtd/partition.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/mtd/partition.c b/drivers/mtd/partition.c
index 5c0d46f..5a3d1ae 100644
--- a/drivers/mtd/partition.c
+++ b/drivers/mtd/partition.c
@@ -51,6 +51,9 @@ static int mtd_part_erase(struct mtd_info *mtd, struct erase_info *instr)
static int mtd_part_lock(struct mtd_info *mtd, loff_t offset, size_t len)
{
+ if (!mtd->master->lock)
+ return -ENOSYS;
+
if (!(mtd->flags & MTD_WRITEABLE))
return -EROFS;
@@ -64,6 +67,9 @@ static int mtd_part_lock(struct mtd_info *mtd, loff_t offset, size_t len)
static int mtd_part_unlock(struct mtd_info *mtd, loff_t offset, size_t len)
{
+ if (!mtd->master->unlock)
+ return -ENOSYS;
+
if (!(mtd->flags & MTD_WRITEABLE))
return -EROFS;
--
1.7.9.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2014-07-08 7:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-08 7:37 [PATCH] fix mtd_part_lock/unlock Zahari Doychev
2014-07-08 7:37 ` Zahari Doychev [this message]
2014-07-09 5:31 ` [PATCH] drivers/mtd: fix NULL pointer dereference in partition lock/unlock Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a2949dd62538a64ec5689b63d6ff531620ceb198.1404734020.git.zahari.doychev@linux.com \
--to=zahari.doychev@linux.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox