public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] mtd: spi-nor: Return error when nor->addr_width not match the device size
@ 2018-11-14 12:56 Liu Xiang
  2018-11-14 13:51 ` Boris Brezillon
  0 siblings, 1 reply; 7+ messages in thread
From: Liu Xiang @ 2018-11-14 12:56 UTC (permalink / raw)
  To: linux-mtd
  Cc: linux-kernel, boris.brezillon, marek.vasut, dwmw2,
	computersforpeace, richard, liuxiang_1999, Liu Xiang

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 <boris.brezillon@bootlin.com>
Signed-off-by: Liu Xiang <liu.xiang6@zte.com.cn>
---
 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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-03-13 13:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-14 12:56 [PATCH] mtd: spi-nor: Return error when nor->addr_width not match the device size Liu Xiang
2018-11-14 13:51 ` Boris Brezillon
2018-11-14 14:46   ` Liu Xiang
2018-11-15 10:54   ` Tudor.Ambarus
2018-11-15 11:02     ` Boris Brezillon
2018-11-16 13:24       ` Liu Xiang
2019-03-13 13:20         ` Liu Xiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox