From patchwork Fri May 20 13:22:25 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: 96599 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 1AC33B6F84 for ; Fri, 20 May 2011 23:10:32 +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 1QNPS4-0004cO-6N; Fri, 20 May 2011 13:09:12 +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 1QNPS2-0006i8-GD; Fri, 20 May 2011 13:09:10 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QNPRz-0006i0-Ld for linux-mtd@canuck.infradead.org; Fri, 20 May 2011 13:09:07 +0000 Received: from smtp.nokia.com ([147.243.1.47] helo=mgw-sa01.nokia.com) by casper.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QNNoO-0003r5-3G for linux-mtd@lists.infradead.org; Fri, 20 May 2011 11:24:08 +0000 Received: from nokia.com (localhost [127.0.0.1]) by mgw-sa01.nokia.com (Switch-3.4.4/Switch-3.4.3) with ESMTP id p4KBNmwE021033; Fri, 20 May 2011 14:23:49 +0300 Received: from [172.21.38.95] ([esdhcp03895.research.nokia.com [172.21.38.95]]) by mgw-sa01.nokia.com with RELAY id p4KBNIk6020451 ; Fri, 20 May 2011 14:23:19 +0300 Message-ID: <4DD66B11.4070605@nokia.com> Date: Fri, 20 May 2011 14:22:25 +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: dedekind1@gmail.com Subject: Re: [PATCH] drivers: mtd: mtdswap: fix possible null dereference References: <4DD3B4C2.30301@nokia.com> <1305870365.2630.92.camel@localhost> <4DD65673.8080801@nokia.com> <1305886801.2630.132.camel@localhost> In-Reply-To: <1305886801.2630.132.camel@localhost> X-Nokia-AV: Clean X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110520_122408_405571_2D830930 X-CRM114-Status: UNSURE ( 9.63 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2-r929478 on casper.infradead.org summary: Content analysis details: (-1.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, low trust [147.243.1.47 listed in list.dnswl.org] 0.0 TVD_RCVD_SPACE_BRACKET TVD_RCVD_SPACE_BRACKET -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Jarkko Lavinen , linux-mtd@lists.infradead.org, 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..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);