9
0
Fork 0

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.

Signed-off-by: Zahari Doychev <zahari.doychev@linux.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Zahari Doychev 2014-07-08 09:37:35 +02:00 committed by Sascha Hauer
parent 3f4e7adae9
commit 433135c85c
1 changed files with 6 additions and 0 deletions

View File

@ -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;