Commit 8d8f26e19cae48541b824f164021e1ff05067f8c

Authored by Maxin B. John
Committed by David Woodhouse
1 parent 5c8d260775

mtd: mtdswap: fix possible null dereference

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>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>

Showing 1 changed file with 7 additions and 1 deletions Side-by-side Diff

drivers/mtd/mtdswap.c
... ... @@ -1450,7 +1450,13 @@
1450 1450 }
1451 1451  
1452 1452 oinfo = mtd->ecclayout;
1453   - if (!mtd->oobsize || !oinfo || oinfo->oobavail < MTDSWAP_OOBSIZE) {
  1453 + if (!oinfo) {
  1454 + printk(KERN_ERR "%s: mtd%d does not have OOB\n",
  1455 + MTDSWAP_PREFIX, mtd->index);
  1456 + return;
  1457 + }
  1458 +
  1459 + if (!mtd->oobsize || oinfo->oobavail < MTDSWAP_OOBSIZE) {
1454 1460 printk(KERN_ERR "%s: Not enough free bytes in OOB, "
1455 1461 "%d available, %zu needed.\n",
1456 1462 MTDSWAP_PREFIX, oinfo->oobavail, MTDSWAP_OOBSIZE);