Skip to content

Commit b6cbd91

Browse files
committed
mtd: spi-nor: swp: Improve code around spi_nor_check_lock_status_sr()
- bool return value for spi_nor_check_lock_status_sr(), gets rid of the return 1, - introduce temporary variables for better readability. Suggested-by: Joe Perches <joe@perches.com> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> Reviewed-by: Pratyush Yadav <p.yadav@ti.com> Reviewed-by: Michael Walle <michael@walle.cc> Link: https://lore.kernel.org/r/20210322075131.45093-3-tudor.ambarus@microchip.com
1 parent c4c7951 commit b6cbd91

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

drivers/mtd/spi-nor/swp.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,36 +81,39 @@ static void spi_nor_get_locked_range_sr(struct spi_nor *nor, u8 sr, loff_t *ofs,
8181
}
8282

8383
/*
84-
* Return 1 if the entire region is locked (if @locked is true) or unlocked (if
85-
* @locked is false); 0 otherwise
84+
* Return true if the entire region is locked (if @locked is true) or unlocked
85+
* (if @locked is false); false otherwise.
8686
*/
87-
static int spi_nor_check_lock_status_sr(struct spi_nor *nor, loff_t ofs,
88-
uint64_t len, u8 sr, bool locked)
87+
static bool spi_nor_check_lock_status_sr(struct spi_nor *nor, loff_t ofs,
88+
uint64_t len, u8 sr, bool locked)
8989
{
90-
loff_t lock_offs;
90+
loff_t lock_offs, lock_offs_max, offs_max;
9191
uint64_t lock_len;
9292

9393
if (!len)
94-
return 1;
94+
return true;
9595

9696
spi_nor_get_locked_range_sr(nor, sr, &lock_offs, &lock_len);
9797

98+
lock_offs_max = lock_offs + lock_len;
99+
offs_max = ofs + len;
100+
98101
if (locked)
99102
/* Requested range is a sub-range of locked range */
100-
return (ofs + len <= lock_offs + lock_len) && (ofs >= lock_offs);
103+
return (offs_max <= lock_offs_max) && (ofs >= lock_offs);
101104
else
102105
/* Requested range does not overlap with locked range */
103-
return (ofs >= lock_offs + lock_len) || (ofs + len <= lock_offs);
106+
return (ofs >= lock_offs_max) || (offs_max <= lock_offs);
104107
}
105108

106-
static int spi_nor_is_locked_sr(struct spi_nor *nor, loff_t ofs, uint64_t len,
107-
u8 sr)
109+
static bool spi_nor_is_locked_sr(struct spi_nor *nor, loff_t ofs, uint64_t len,
110+
u8 sr)
108111
{
109112
return spi_nor_check_lock_status_sr(nor, ofs, len, sr, true);
110113
}
111114

112-
static int spi_nor_is_unlocked_sr(struct spi_nor *nor, loff_t ofs, uint64_t len,
113-
u8 sr)
115+
static bool spi_nor_is_unlocked_sr(struct spi_nor *nor, loff_t ofs,
116+
uint64_t len, u8 sr)
114117
{
115118
return spi_nor_check_lock_status_sr(nor, ofs, len, sr, false);
116119
}

0 commit comments

Comments
 (0)