]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
mtd: spi-nor: Remove recently added nor->addr_width == 3 test
authorMarek Vasut <marek.vasut+renesas@mailbox.org>
Sat, 26 Oct 2024 20:16:18 +0000 (22:16 +0200)
committerTom Rini <trini@konsulko.com>
Thu, 31 Oct 2024 16:49:47 +0000 (10:49 -0600)
Remove undocumented nor->addr_width == 3 test. This was added in commit
5d40b3d384dc ("mtd: spi-nor: Add parallel and stacked memories support")
without any explanation in the commit message. Remove it.

This also has a bad side-effect which breaks READ operation of every SPI NOR
which does not use addr_width == 3, e.g. s25fs512s does not work at all. This
is because if addr_width != 3, rem_bank_len is always 0, and if rem_bank_len
is 0, then read_len is 0 and if read_len is 0, then the spi_nor_read() returns
-EIO.

Basic reproducer is as follows:
"
=> sf probe ; sf read 0x50000000 0 0x10000
SF: Detected s25fs512s with page size 256 Bytes, erase size 256 KiB, total 64 MiB
device 0 offset 0x0, size 0x10000
SF: 65536 bytes @ 0x0 Read: ERROR -5
"

Fixes: 5d40b3d384dc ("mtd: spi-nor: Add parallel and stacked memories support")
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
drivers/mtd/spi/spi-nor-core.c

index f5c9868bbca7c495676717bc8ba56fe97b10b985..8dfdcda47fb70d87d13cc27fd69b97f3293b7d7e 100644 (file)
@@ -1595,16 +1595,14 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
        }
 
        while (len) {
-               if (nor->addr_width == 3) {
-                       if (nor->flags & SNOR_F_HAS_PARALLEL) {
-                               bank = (u32)from / (SZ_16M << 0x01);
-                               rem_bank_len = ((SZ_16M << 0x01) *
-                                       (bank + 1)) - from;
-                       } else {
-                               bank = (u32)from / SZ_16M;
-                               rem_bank_len = (SZ_16M * (bank + 1)) - from;
-                       }
+               if (nor->flags & SNOR_F_HAS_PARALLEL) {
+                       bank = (u32)from / (SZ_16M << 0x01);
+                       rem_bank_len = ((SZ_16M << 0x01) * (bank + 1)) - from;
+               } else {
+                       bank = (u32)from / SZ_16M;
+                       rem_bank_len = (SZ_16M * (bank + 1)) - from;
                }
+
                offset = from;
 
                if (nor->flags & SNOR_F_HAS_STACKED) {
@@ -1619,13 +1617,11 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
                if (nor->flags & SNOR_F_HAS_PARALLEL)
                        offset /= 2;
 
-               if (nor->addr_width == 3) {
 #ifdef CONFIG_SPI_FLASH_BAR
-                       ret = write_bar(nor, offset);
-                       if (ret < 0)
-                               return log_ret(ret);
+               ret = write_bar(nor, offset);
+               if (ret < 0)
+                       return log_ret(ret);
 #endif
-               }
 
                if (len < rem_bank_len)
                        read_len = len;
@@ -2012,13 +2008,12 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
                        }
                }
 
-               if (nor->addr_width == 3) {
 #ifdef CONFIG_SPI_FLASH_BAR
-                       ret = write_bar(nor, offset);
-                       if (ret < 0)
-                               return ret;
+               ret = write_bar(nor, offset);
+               if (ret < 0)
+                       return ret;
 #endif
-               }
+
                /* the size of data remaining on the first page */
                page_remain = min_t(size_t,
                                    nor->page_size - page_offset, len - i);