From patchwork Tue Dec 2 12:58:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 416851 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5418114012C for ; Wed, 3 Dec 2014 00:02:57 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Xvn4x-0003Qf-Co; Tue, 02 Dec 2014 13:01:19 +0000 Received: from mailapp01.imgtec.com ([195.59.15.196]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Xvn4p-0003Jf-Gq for linux-mtd@lists.infradead.org; Tue, 02 Dec 2014 13:01:15 +0000 Received: from KLMAIL01.kl.imgtec.org (unknown [192.168.5.35]) by Websense Email Security Gateway with ESMTPS id 3D4D6C2855F7E; Tue, 2 Dec 2014 13:00:50 +0000 (GMT) Received: from hhmail02.hh.imgtec.org (10.100.10.20) by KLMAIL01.kl.imgtec.org (192.168.5.35) with Microsoft SMTP Server (TLS) id 14.3.195.1; Tue, 2 Dec 2014 13:00:52 +0000 Received: from arch.hh.imgtec.org (10.100.200.198) by hhmail02.hh.imgtec.org (10.100.10.20) with Microsoft SMTP Server (TLS) id 14.3.210.2; Tue, 2 Dec 2014 13:00:51 +0000 From: Ezequiel Garcia To: Andrew Bresticker , Ionela Voinescu , James Hartley , "Brian Norris" , , , Subject: [PATCH 1/6] mtd: nand: Check length of ID before reading bits per cell Date: Tue, 2 Dec 2014 09:58:51 -0300 Message-ID: <1417525136-25731-2-git-send-email-ezequiel.garcia@imgtec.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1417525136-25731-1-git-send-email-ezequiel.garcia@imgtec.com> References: <1417525136-25731-1-git-send-email-ezequiel.garcia@imgtec.com> MIME-Version: 1.0 X-Originating-IP: [10.100.200.198] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141202_050111_831825_0BB67C01 X-CRM114-Status: UNSURE ( 7.34 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Cc: Ezequiel Garcia , linux-mtd@lists.infradead.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The table-based NAND identification currently reads the number of bits per cell from the 3rd byte of the extended ID. This is done for the so-called 'full ID' devices; i.e. devices that have a known length ID. However, if the ID length is shorter than three, there's no 3rd byte, and so it's wrong to read the bits per cell from there. Fix this by adding a check for the ID length. Signed-off-by: Ezequiel Garcia Reviewed-by: Dan Ehrenberg --- drivers/mtd/nand/nand_base.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 5b5c627..a4c9cee 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -3589,7 +3589,8 @@ static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip, mtd->erasesize = type->erasesize; mtd->oobsize = type->oobsize; - chip->bits_per_cell = nand_get_bits_per_cell(id_data[2]); + if (type->id_len > 2) + chip->bits_per_cell = nand_get_bits_per_cell(id_data[2]); chip->chipsize = (uint64_t)type->chipsize << 20; chip->options |= type->options; chip->ecc_strength_ds = NAND_ECC_STRENGTH(type);