Patchwork ] mtdconcat: fix bug with uninitialized lock and unlock functions

login
register
mail settings
Submitter Martin Krause
Date June 22, 2010, 1 p.m.
Message ID <47F3F98010FF784EBEE6526EAAB078D10635E728@tq-mailsrv.tq-net.de>
Download mbox | patch
Permalink /patch/56477/
State New
Headers show

Comments

Martin Krause - June 22, 2010, 1 p.m.
Test if a lock or unlock function is present (pointer not NULL) before
calling it, to prevent a kernel dump.

Signed-off-by: Martin Krause <martin.krause@tqs.de>
---
 drivers/mtd/mtdconcat.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)
Artem Bityutskiy - July 8, 2010, 9:10 a.m.
On Tue, 2010-06-22 at 15:00 +0200, Martin Krause wrote:
> Test if a lock or unlock function is present (pointer not NULL) before
> calling it, to prevent a kernel dump.
> 
> Signed-off-by: Martin Krause <martin.krause@tqs.de>
> ---
>  drivers/mtd/mtdconcat.c |   18 ++++++++++++------
>  1 files changed, 12 insertions(+), 6 deletions(-)

Pushed to l2-mtd-2.6.git, thanks!

Patch

diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index db6de74..0a7ee03 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -541,10 +541,13 @@  static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 		else
 			size = len;
 
-		err = subdev->lock(subdev, ofs, size);
+		if (subdev->lock) {
+			err = subdev->lock(subdev, ofs, size);
 
-		if (err)
-			break;
+			if (err)
+				break;
+		} else
+			err = -EOPNOTSUPP;
 
 		len -= size;
 		if (len == 0)
@@ -579,10 +582,13 @@  static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 		else
 			size = len;
 
-		err = subdev->unlock(subdev, ofs, size);
+		if (subdev->unlock) {
+			err = subdev->unlock(subdev, ofs, size);
 
-		if (err)
-			break;
+			if (err)
+				break;
+		} else
+			err = -EOPNOTSUPP;
 
 		len -= size;
 		if (len == 0)