From patchwork Mon Nov 28 13:53:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 127993 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 247B6B6F85 for ; Tue, 29 Nov 2011 00:54:46 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1RV1ds-0001Ij-EA; Mon, 28 Nov 2011 13:53:08 +0000 Received: from rcsinet15.oracle.com ([148.87.113.117]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1RV1dm-0001GK-Sx for linux-mtd@lists.infradead.org; Mon, 28 Nov 2011 13:53:06 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by rcsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id pASDqpRq022788 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 28 Nov 2011 13:52:51 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id pASDqnEJ011480 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 28 Nov 2011 13:52:49 GMT Received: from abhmt113.oracle.com (abhmt113.oracle.com [141.146.116.65]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id pASDqiPv031074; Mon, 28 Nov 2011 07:52:44 -0600 Received: from mwanda (/41.139.221.94) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 28 Nov 2011 05:52:43 -0800 Date: Mon, 28 Nov 2011 16:53:13 +0300 From: Dan Carpenter To: Robert Jarzmik Subject: [patch v2] mtd/docg3: dereferencing an ERR_PTR() in docg3_probe() Message-ID: <20111128134947.GK21128@mwanda> References: <20111124072117.GC14122@elgon.mountain> <87pqghygbv.fsf@free.fr> <20111124103147.GF3195@mwanda> <87r50vi20u.fsf@free.fr> MIME-Version: 1.0 In-Reply-To: <87r50vi20u.fsf@free.fr> User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: acsinet22.oracle.com [141.146.126.238] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A090202.4ED39234.0072,ss=1,re=0.000,fgs=0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -5.4 (-----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-5.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [148.87.113.117 listed in list.dnswl.org] -1.2 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linux-mtd@lists.infradead.org, kernel-janitors@vger.kernel.org, David Woodhouse X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 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 If doc_probe_device() returned an ERR_PTR, then we accidentally saved that to docg3_floors[floor] = mtd; which gets derefenced in the error handling when we call doc_release_device(). I've reworked the error handling to take care of that and hopefully make it a little simpler. Signed-off-by: Dan Carpenter Acked-by: Robert Jarzmik --- v2: Version 1 conflicted with another patch in stream. diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index d7df311..f7490a014 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -2027,21 +2027,24 @@ static int __init docg3_probe(struct platform_device *pdev) if (!docg3_bch) goto nomem2; - ret = 0; for (floor = 0; floor < DOC_MAX_NBFLOORS; floor++) { mtd = doc_probe_device(base, floor, dev); - if (floor == 0 && !mtd) - goto notfound; - if (!IS_ERR_OR_NULL(mtd)) - ret = mtd_device_parse_register(mtd, part_probes, - NULL, NULL, 0); - else + if (IS_ERR(mtd)) { ret = PTR_ERR(mtd); + goto err_probe; + } + if (!mtd) { + if (floor == 0) + goto notfound; + else + continue; + } docg3_floors[floor] = mtd; + ret = mtd_device_parse_register(mtd, part_probes, NULL, NULL, + 0); if (ret) goto err_probe; - if (mtd) - found++; + found++; } ret = doc_register_sysfs(pdev, docg3_floors);