From patchwork Wed Nov 14 12:56:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Xiang X-Patchwork-Id: 997707 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=zte.com.cn Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="VdAUFwxS"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="yTetUiC/"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42w4J56GkDz9s8J for ; Wed, 14 Nov 2018 23:56:37 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=8hn1fa1JgvGV1sB6w8LY02wj2dVMNwpyLA7Cb+UXlJw=; b=VdA UFwxSj85JrNbH/RMQleXizLj+d84ZeM+6wQ7VQmW0jjyCLEGGZm9cbeHOB3qYXSq6kFLtjtX1nZOQ bDPSXtrTn7E9dfaFR6FFqH7safskOhNMShFTDGIj4snYH0rCI4GRIumzVRRhwavXxSLW+4KzAnLXF ORS8uMdMaeWAFUoGP/VckWVixehN7coxd9yPMiG5US9vgkbyvQL0LdXguaWe5orPPY2WlReW0tAyN 3QQIWZaXRaLi9RlsT2ss7kHmhaVhedNwIdiIQUtrQO4Tp/0oOkGRWPrvxWc3Ra/jPnvUQkcW8n05G RuL/yMgpclo4HSpuxMk8YTSBDEmlvPg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMuig-0006Iv-Ne; Wed, 14 Nov 2018 12:56:34 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMuie-0006Ib-MP for linux-mtd@bombadil.infradead.org; Wed, 14 Nov 2018 12:56:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=OZUDuwP8pKgAQKGaSQGQ1gGfRMmIj7lWrTBULJjbkc4=; b=yTetUiC/Tmcv1PkR5ODmyjE41 6VA8uF3Vc15Blna+qIsHXoA0E7WnvSQi2POr4khQt4Gx25T9kqPdUK3PU0V8jpS90JjPI+RGHv74U jzpW3Bq2dBBfxzFKi+wXAumAe28Tq9dk6a+H2RqBdt5jWM/HsAdg9f4q8EhpGBPwM9h8G6OShFX66 3cRWsd6nKr6Ml+nOu0KzKiyjQ6kWQz8XexoVxq+3W1+MYGCBpZt12G2Lj6GE3vbwvISVsXJAyB5NS IW0pkwvgLFjOB0aZbhidaOuIChWZWsE+qb2SANpYwMnQqAC5BMpOZL+ZkVbMWla/3HPJEtACgtiTh XNkoVyWcw==; Received: from smtprz14.163.net ([106.3.154.247] helo=smtp.tom.com) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMuib-0004nM-Ow for linux-mtd@lists.infradead.org; Wed, 14 Nov 2018 12:56:30 +0000 Received: from antispam1.tom.com (unknown [172.25.16.55]) by freemail01.tom.com (Postfix) with ESMTP id E0DF61C80EDE for ; Wed, 14 Nov 2018 20:56:15 +0800 (CST) Received: from antispam1.tom.com (antispam1.tom.com [127.0.0.1]) by antispam1.tom.com (Postfix) with ESMTP id DB3941001566 for ; Wed, 14 Nov 2018 20:56:15 +0800 (CST) X-Virus-Scanned: Debian amavisd-new at antispam1.tom.com Received: from antispam1.tom.com ([127.0.0.1]) by antispam1.tom.com (antispam1.tom.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CdCgFn9Of4bb for ; Wed, 14 Nov 2018 20:56:15 +0800 (CST) Received: from localhost (unknown [110.184.153.105]) by antispam1.tom.com (Postfix) with ESMTPA id 7DDBB1001423; Wed, 14 Nov 2018 20:56:14 +0800 (CST) From: Liu Xiang To: linux-mtd@lists.infradead.org Subject: [PATCH] mtd: spi-nor: Return error when nor->addr_width not match the device size Date: Wed, 14 Nov 2018 20:56:05 +0800 Message-Id: <1542200165-3073-1-git-send-email-liu.xiang6@zte.com.cn> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181114_075630_349031_2A48C429 X-CRM114-Status: GOOD ( 10.31 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marek.vasut@gmail.com, richard@nod.at, Liu Xiang , linux-kernel@vger.kernel.org, boris.brezillon@bootlin.com, liuxiang_1999@126.com, computersforpeace@gmail.com, dwmw2@infradead.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org In is25lp256, the DWORD1 of JEDEC Basic Flash Parameter Header is 0xfff920e5. So the DWORD1[18:17] Address Bytes bits are 0b00, means that 3-Byte only addressing. But the device size is larger than 16MB, nor->addr_width must be 4 to access the whole address. An error should be returned when nor->addr_width not match the device size in spi_nor_parse_sfdp(). Suggested-by: Boris Brezillon Signed-off-by: Liu Xiang --- drivers/mtd/spi-nor/spi-nor.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 3eba13a..77eaf22 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -2669,6 +2669,10 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor, } params->size >>= 3; /* Convert to bytes. */ + /*if the device exceeds 16MiB, addr_width must be 4*/ + if ((params->size > 0x1000000) && (nor->addr_width == 3)) + return -EINVAL; + /* Fast Read settings. */ for (i = 0; i < ARRAY_SIZE(sfdp_bfpt_reads); i++) { const struct sfdp_bfpt_read *rd = &sfdp_bfpt_reads[i];