[PATCH] drivers/mtd: fix NULL pointer dereference in partition lock/unlock

Zahari Doychev zahari.doychev at linux.com
Tue Jul 8 00:37:35 PDT 2014


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 at 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




More information about the barebox mailing list