diff mbox

drivers: mtd: mtdswap: fix possible null dereference

Message ID 4DD67E3A.4090802@nokia.com
State Accepted
Commit 8d8f26e19cae48541b824f164021e1ff05067f8c
Headers show

Commit Message

john.maxin@nokia.com May 20, 2011, 2:44 p.m. UTC
This patch fixes the possible null dereference of the variable "oinfo"
Thanks to Coverity for spotting this.

Signed-off-by: Maxin B. John <john.maxin@nokia.com>
---

Comments

Artem Bityutskiy May 20, 2011, 12:47 p.m. UTC | #1
On Fri, 2011-05-20 at 15:44 +0100, Maxin B. John wrote:
> This patch fixes the possible null dereference of the variable "oinfo"
> Thanks to Coverity for spotting this.
> 
> Signed-off-by: Maxin B. John <john.maxin@nokia.com>

Pushed to l2-mtd-2.6.git, thanks.
Artem Bityutskiy May 20, 2011, 1:51 p.m. UTC | #2
On Fri, 2011-05-20 at 15:44 +0100, Maxin B. John wrote:
> This patch fixes the possible null dereference of the variable "oinfo"
> Thanks to Coverity for spotting this.
> 
> Signed-off-by: Maxin B. John <john.maxin@nokia.com>

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

Patch

diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c
index fed215c..fd78853 100644
--- a/drivers/mtd/mtdswap.c
+++ b/drivers/mtd/mtdswap.c
@@ -1450,7 +1450,13 @@  static void mtdswap_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
 	}
 
 	oinfo = mtd->ecclayout;
-	if (!mtd->oobsize || !oinfo || oinfo->oobavail < MTDSWAP_OOBSIZE) {
+	if (!oinfo) {
+		printk(KERN_ERR "%s: mtd%d does not have OOB\n",
+			MTDSWAP_PREFIX, mtd->index);
+		return;
+	}
+
+	if (!mtd->oobsize || oinfo->oobavail < MTDSWAP_OOBSIZE) {
 		printk(KERN_ERR "%s: Not enough free bytes in OOB, "
 			"%d available, %zu needed.\n",
 			MTDSWAP_PREFIX, oinfo->oobavail, MTDSWAP_OOBSIZE);