From patchwork Wed May 18 12:00:02 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: john.maxin@nokia.com X-Patchwork-Id: 96143 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1784FB6F65 for ; Wed, 18 May 2011 20:04:29 +1000 (EST) Received: from canuck.infradead.org ([2001:4978:20e::1]) by bombadil.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QMdZ9-0004S8-KE; Wed, 18 May 2011 10:01:19 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QMdZ7-00083Q-TI; Wed, 18 May 2011 10:01:18 +0000 Received: from smtp.nokia.com ([147.243.128.24] helo=mgw-da01.nokia.com) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QMdZ1-000837-7e for linux-mtd@lists.infradead.org; Wed, 18 May 2011 10:01:12 +0000 Received: from nokia.com (localhost [127.0.0.1]) by mgw-da01.nokia.com (Switch-3.4.4/Switch-3.4.3) with ESMTP id p4I9xWrw032209; Wed, 18 May 2011 13:01:02 +0300 Received: from [172.21.38.95] ([esdhcp03895.research.nokia.com [172.21.38.95]]) by mgw-da01.nokia.com with RELAY id p4IA0tcv001374 ; Wed, 18 May 2011 13:00:57 +0300 Message-ID: <4DD3B4C2.30301@nokia.com> Date: Wed, 18 May 2011 13:00:02 +0100 From: maxin User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 MIME-Version: 1.0 To: linux-mtd@lists.infradead.org Subject: [PATCH] drivers: mtd: mtdswap: fix possible null dereference X-Nokia-AV: Clean X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110518_060111_431937_BE824B05 X-CRM114-Status: GOOD ( 10.60 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 TVD_RCVD_SPACE_BRACKET TVD_RCVD_SPACE_BRACKET -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [147.243.128.24 listed in list.dnswl.org] Cc: Jarkko Lavinen , David Woodhouse X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This patch fixes the possible null dereference of the variable "oinfo" Thanks to Coverity for spotting this. Signed-off-by: Maxin B. John diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c index fed215c..863987c 100644 --- a/drivers/mtd/mtdswap.c +++ b/drivers/mtd/mtdswap.c @@ -1450,7 +1450,12 @@ 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 "Not enough free bytes available for ECC"); + 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);