Skip to contentSkip to conversation

fix mtd_part_lock/unlock

PATCH New Zahari Doychev 2 participants 3 messages Jul 8, 2014 – Jul 9, 2014 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix mtd_part_lock/unlock

Hi,

Some mtd drivers does not define lock and unlock partition functions. This patch avoids crashing when these undefined functions are called from barebox code e.g. saveenv. Please review this patch and apply it if it is ok.

Thanks

Zahari Doychev (1):
drivers/mtd: fix NULL pointer dereference in partition lock/unlock

 drivers/mtd/partition.c |    6 ++++++
 1 file changed, 6 insertions(+)
Signature · 7 lines
1.7.9.5


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

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

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.

---
 drivers/mtd/partition.c |    6 ++++++
 1 file changed, 6 insertions(+)
drivers/mtd/partition.c +6 -0
index 5c0d46f..5a3d1ae 100644
@@ -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;
 
Signature · 7 lines
1.7.9.5


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#2 lore raw

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

Quoted 4 lines · Zahari Doychev

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.

Applied, thanks

Sascha

Quoted 37 lines
---
 drivers/mtd/partition.c |    6 ++++++
 1 file changed, 6 insertions(+)
drivers/mtd/partition.c +6 -0
index 5c0d46f..5a3d1ae 100644
@@ -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;
 
Signature · 7 lines
1.7.9.5


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox