mtd: mtdconcat: fix bug with uninitialized lock and unlock functions
authorMartin Krause <Martin.Krause@tqs.de>
Tue, 22 Jun 2010 13:00:19 +0000 (15:00 +0200)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Mon, 2 Aug 2010 08:04:20 +0000 (09:04 +0100)
Test if a lock or unlock function is present (pointer not NULL) before
calling it, to prevent a kernel dump.

Artem: removed extra blank lines

Signed-off-by: Martin Krause <martin.krause@tqs.de>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
drivers/mtd/mtdconcat.c

index 7e07562..4567bc3 100644 (file)
@@ -540,10 +540,12 @@ static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
                else
                        size = len;
 
-               err = subdev->lock(subdev, ofs, size);
-
-               if (err)
-                       break;
+               if (subdev->lock) {
+                       err = subdev->lock(subdev, ofs, size);
+                       if (err)
+                               break;
+               } else
+                       err = -EOPNOTSUPP;
 
                len -= size;
                if (len == 0)
@@ -578,10 +580,12 @@ static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
                else
                        size = len;
 
-               err = subdev->unlock(subdev, ofs, size);
-
-               if (err)
-                       break;
+               if (subdev->unlock) {
+                       err = subdev->unlock(subdev, ofs, size);
+                       if (err)
+                               break;
+               } else
+                       err = -EOPNOTSUPP;
 
                len -= size;
                if (len == 0)