From patchwork Fri May 20 11:54:27 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: drivers: mtd: mtdswap: fix possible null dereference Date: Fri, 20 May 2011 01:54:27 -0000 From: john.maxin@nokia.com X-Patchwork-Id: 96576 Message-Id: <4DD65673.8080801@nokia.com> To: dedekind1@gmail.com Cc: Jarkko Lavinen , linux-mtd@lists.infradead.org, David Woodhouse Hi Artem, On 11-05-20 06:46 AM, ext Artem Bityutskiy wrote: > On Wed, 2011-05-18 at 13:00 +0100, maxin wrote: >> This patch fixes the possible null dereference of the variable "oinfo" > > Does this print makes sense? Which ECC? I think it should me something > like "mtd% does not have OOB", mtd->index. > Thank you very much for reviewing the patch.I have updated the print message as per your suggestion as it makes more sense for this case. > Moreover, you should make the print consistent with the other prints > which start with MTDSWAP_PREFIX. > I have updated the patch as per your comments. Signed-off-by: Maxin B. John --- diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c index fed215c..62ddb3a 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);