From patchwork Sun Aug 9 09:38:31 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: roel kluin X-Patchwork-Id: 31014 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 0B7B2B7B73 for ; Sun, 9 Aug 2009 19:36:44 +1000 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1Ma4no-0005bQ-N7; Sun, 09 Aug 2009 09:34:56 +0000 Received: from mail-ew0-f211.google.com ([209.85.219.211]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1Ma4ng-0005b3-UN for linux-mtd@lists.infradead.org; Sun, 09 Aug 2009 09:34:53 +0000 Received: by ewy7 with SMTP id 7so2089665ewy.18 for ; Sun, 09 Aug 2009 02:34:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:content-type :content-transfer-encoding; bh=4uK2VuzJsTpKQo8aW+a5BedtXbkVNuuXsu7NpoZqDQ4=; b=HoH7ID/HzieQcSjk2JZER2NZL173Mxw3F0Pl5/xzKfFq2LVg1+SJTaatr3ccnrDh9N +t/eDJXcOLhl5hO1i9TygLTNIiqRwY26BUIxVrDlnMKDocLPSGPBJ95aLyQFBxo8D2r2 YMKg1Fx+Z/gCvSD0E1dMcHKChBcsEVT2CzDjo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; b=GhSshcmdhvQ+Ep7EHWYNukKndYBGLI1EFYxAihs/v09jJfvqpu9V7ppzo+NAWtyEeh QsYpdMfOOeHtZp5VmS1WkUTy2A/NAMaF712By2Lv77agrz4fE9KlUFdpi/4JuOBa8ZzL E3Ur6Q4d3EDvu+wFOxUabSf8vBYdXIOdmV08g= Received: by 10.210.43.10 with SMTP id q10mr3740196ebq.23.1249810488094; Sun, 09 Aug 2009 02:34:48 -0700 (PDT) Received: from zoinx.mars (d133062.upc-d.chello.nl [213.46.133.62]) by mx.google.com with ESMTPS id 5sm5803621eyh.56.2009.08.09.02.34.47 (version=SSLv3 cipher=RC4-MD5); Sun, 09 Aug 2009 02:34:47 -0700 (PDT) Message-ID: <4A7E9917.4050307@gmail.com> Date: Sun, 09 Aug 2009 11:38:31 +0200 From: Roel Kluin User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1b3pre) Gecko/20090513 Fedora/3.0-2.3.beta2.fc11 Thunderbird/3.0b2 MIME-Version: 1.0 To: David Woodhouse , linux-mtd@lists.infradead.org, Andrew Morton Subject: [PATCH] MTD: Prevent a read from regions[-1] X-Spam-Score: 0.0 (/) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.11 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 the erase region was found in the first iteration we read from regions[-1] Signed-off-by: Roel Kluin diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 349fcbe..a83cfa1 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -453,7 +453,8 @@ static struct mtd_part *add_one_partition(struct mtd_info *master, for (i = 0; i < max && regions[i].offset <= slave->offset; i++) ; /* The loop searched for the region _behind_ the first one */ - i--; + if (i > 0) + i--; /* Pick biggest erasesize */ for (; i < max && regions[i].offset < end; i++) {