Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6658682imu; Wed, 14 Nov 2018 05:09:58 -0800 (PST) X-Google-Smtp-Source: AJdET5eTLZqO2D4iqAa5/V8YoRTq9nMjUIGakWwWwRfmbad1YmeQgesCPZL41NXJwTxRY7hXfm+N X-Received: by 2002:a62:8145:: with SMTP id t66-v6mr1918730pfd.246.1542200998391; Wed, 14 Nov 2018 05:09:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542200998; cv=none; d=google.com; s=arc-20160816; b=v3r4BwyfEsAbnWMn3Eio5lGTPGVpSAB3VcmA4w5Li3stGUE+ukPIVaiKoysD/PFLWy yEnIc304cH/M5TZZQvGcEoQF5TpalR3uT6365S750VdGaqAG6kMYnTDClhRpS08xKBGt tAXq8fUMKBPShLiRQbwSda/2g3f+FRL6ugl7zhU3Z9NLM2a5dncV2IAzsVOXSxMY2Ipp +B7F/o3F+AiJg86wGf5/p2hkR54Mx7RTmVbosS6/FJqHj6TwfSOG3GyYvXxWmWz9pt14 yfioH8qItF+zuk39WJp/jEvzXpBYHr85kaGyr2HXJzY9j3JhMk08lgnrpXHaUDRB0VeE rDtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=OZUDuwP8pKgAQKGaSQGQ1gGfRMmIj7lWrTBULJjbkc4=; b=Fy0yxfb6PoRLg36mq0WoHHP4/JKnbFb/9DjVl+B2aCKsqOr0qTutof1NyEvNHEFBXn E0OG8rAA+ORV1ytz9aAsbxSKdyICFPg8keOAyZx8ayc5rHEesUHaK8v/LnreBQbAai/D 0uieF88S8XPvVaMG4kX3R826xcVnjCz7O0ZsbODSY1FX3fv8lfjV+5v1SGzPDZ0mdO5k 5cqkX73xlTQhcga5WzQHMMmuUdO/oPC/oTw3xRoZIFdV1V5ORgDszXGJ5hPQsoHdhHDZ mxhqVjjgxa7txLPpIhIePpBjBEdcrnEXlEfCb0OYMkrHXysOEGPiG2EFzGbTrpUeqmVF Zkjw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d17si23335109pgl.484.2018.11.14.05.09.43; Wed, 14 Nov 2018 05:09:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732565AbeKNXMa (ORCPT + 99 others); Wed, 14 Nov 2018 18:12:30 -0500 Received: from smtprz15.163.net ([106.3.154.248]:34930 "EHLO smtp.tom.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727731AbeKNXMa (ORCPT ); Wed, 14 Nov 2018 18:12:30 -0500 Received: from antispam1.tom.com (unknown [172.25.16.55]) by freemail01.tom.com (Postfix) with ESMTP id 296491C80EEF for ; Wed, 14 Nov 2018 20:56:17 +0800 (CST) Received: from antispam1.tom.com (antispam1.tom.com [127.0.0.1]) by antispam1.tom.com (Postfix) with ESMTP id DBAC2100156A 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 cZHxs1Qxvr-X 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 Cc: linux-kernel@vger.kernel.org, boris.brezillon@bootlin.com, marek.vasut@gmail.com, dwmw2@infradead.org, computersforpeace@gmail.com, richard@nod.at, liuxiang_1999@126.com, Liu Xiang 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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]; -- 1.9.1