]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mtd: spi-nor: swp: Cosmetic changes
authorMiquel Raynal <miquel.raynal@bootlin.com>
Tue, 26 May 2026 14:56:40 +0000 (16:56 +0200)
committerPratyush Yadav <pratyush@kernel.org>
Tue, 26 May 2026 15:21:04 +0000 (17:21 +0200)
As a final preparation step for the introduction of CMP support, make
a few more cosmetic changes to simplify the reading of the diff when
adding the CMP feature. In particular, define "min_prot_len" earlier as
it will be reused and move the definition of the "ret" variable at the
end of the stack just because it looks better.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Pratyush Yadav <pratyush@kernel.org>
drivers/mtd/spi-nor/swp.c

index 229074d4e121dbc2f8217e77e114a84ef8f1fa20..2d1b1c8a535a59ee1f5c187c6b3a75cbcdc86cd1 100644 (file)
@@ -197,14 +197,14 @@ static int spi_nor_build_sr(struct spi_nor *nor, const u8 *old_sr, u8 *new_sr,
  */
 static int spi_nor_sr_lock(struct spi_nor *nor, loff_t ofs, u64 len)
 {
-       u64 min_prot_len;
-       int ret;
+       u64 min_prot_len = spi_nor_get_min_prot_length_sr(nor);
        u8 status_old[1] = {}, status_new[1] = {};
        loff_t ofs_old, ofs_new;
        u64 len_old, len_new;
        loff_t lock_len;
        bool can_be_top = true, can_be_bottom = nor->flags & SNOR_F_HAS_SR_TB;
        bool use_top;
+       int ret;
        u8 pow;
 
        ret = spi_nor_read_sr(nor, nor->bouncebuf);
@@ -238,12 +238,10 @@ static int spi_nor_sr_lock(struct spi_nor *nor, loff_t ofs, u64 len)
        else
                lock_len = ofs + len;
 
-       if (lock_len == nor->params->size) {
+       if (lock_len == nor->params->size)
                pow = (nor->flags & SNOR_F_HAS_4BIT_BP) ? GENMASK(3, 0) : GENMASK(2, 0);
-       } else {
-               min_prot_len = spi_nor_get_min_prot_length_sr(nor);
+       else
                pow = ilog2(lock_len) - ilog2(min_prot_len) + 1;
-       }
 
        ret = spi_nor_build_sr(nor, status_old, status_new, pow, use_top);
        if (ret)
@@ -283,14 +281,14 @@ static int spi_nor_sr_lock(struct spi_nor *nor, loff_t ofs, u64 len)
  */
 static int spi_nor_sr_unlock(struct spi_nor *nor, loff_t ofs, u64 len)
 {
-       u64 min_prot_len;
-       int ret;
+       u64 min_prot_len = spi_nor_get_min_prot_length_sr(nor);
        u8 status_old[1], status_new[1];
        loff_t ofs_old, ofs_new;
        u64 len_old, len_new;
        loff_t lock_len;
        bool can_be_top = true, can_be_bottom = nor->flags & SNOR_F_HAS_SR_TB;
        bool use_top;
+       int ret;
        u8 pow;
 
        ret = spi_nor_read_sr(nor, nor->bouncebuf);
@@ -331,14 +329,11 @@ static int spi_nor_sr_unlock(struct spi_nor *nor, loff_t ofs, u64 len)
        else
                lock_len = ofs;
 
-       if (lock_len == 0) {
+       if (lock_len == 0)
                pow = 0; /* fully unlocked */
-       } else {
-               min_prot_len = spi_nor_get_min_prot_length_sr(nor);
+       else
                pow = ilog2(lock_len) - ilog2(min_prot_len) + 1;
 
-       }
-
        ret = spi_nor_build_sr(nor, status_old, status_new, pow, use_top);
        if (ret)
                return ret;