]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
mtd: spi-nor: Rewrite rem_bank_len calculation
authorMarek Vasut <marek.vasut+renesas@mailbox.org>
Sat, 26 Oct 2024 20:16:24 +0000 (22:16 +0200)
committerTom Rini <trini@konsulko.com>
Thu, 31 Oct 2024 16:49:47 +0000 (10:49 -0600)
Rewrite the code to make it clear exactly where the
SNOR_F_HAS_PARALLEL flag leads to *2 and /2 operation
compared to regular code path. No functional change.

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 e49b7cad0234584ff468ee34e182659cfdda659c..c1ee466bcc0249ae9b80d7fa227eed88fbbb924e 100644 (file)
@@ -1593,13 +1593,14 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
        }
 
        while (len) {
-               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;
-               }
+               bank = (u32)from / SZ_16M;
+               if (nor->flags & SNOR_F_HAS_PARALLEL)
+                       bank /= 2;
+
+               rem_bank_len = SZ_16M * (bank + 1);
+               if (nor->flags & SNOR_F_HAS_PARALLEL)
+                       rem_bank_len *= 2;
+               rem_bank_len -= from;
 
                offset = from;