Skip to content

Commit 3bc694d

Browse files
madhurimaparuchuricarlescufi
authored andcommitted
drivers: flash: npcx: Fix offset alignment check bug
Removed single offset alignment check mechanism and replaced it with offset alignment check for each iteration Signed-off-by: Madhurima Paruchuri <[email protected]>
1 parent 571f859 commit 3bc694d

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

drivers/flash/flash_npcx_fiu_nor.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,6 @@ static int flash_npcx_nor_erase(const struct device *dev, off_t addr, size_t siz
258258
{
259259
const struct flash_npcx_nor_config *config = dev->config;
260260
int ret = 0;
261-
bool offset_4k_aligned = SPI_NOR_IS_SECTOR_ALIGNED(addr);
262-
bool offset_64k_aligned = SPI_NOR_IS_64K_ALIGNED(addr);
263261

264262
/* Out of the region of nor flash device? */
265263
if (!is_within_region(addr, size, 0, config->flash_size)) {
@@ -268,7 +266,7 @@ static int flash_npcx_nor_erase(const struct device *dev, off_t addr, size_t siz
268266
}
269267

270268
/* address must be sector-aligned */
271-
if (!offset_4k_aligned) {
269+
if (!SPI_NOR_IS_SECTOR_ALIGNED(addr)) {
272270
LOG_ERR("Addr %ld is not sector-aligned", addr);
273271
return -EINVAL;
274272
}
@@ -290,16 +288,14 @@ static int flash_npcx_nor_erase(const struct device *dev, off_t addr, size_t siz
290288
while (size > 0) {
291289
flash_npcx_uma_cmd_only(dev, SPI_NOR_CMD_WREN);
292290
/* Send page/block erase command with addr */
293-
if ((size >= BLOCK_64K_SIZE) && offset_64k_aligned) {
291+
if ((size >= BLOCK_64K_SIZE) && SPI_NOR_IS_64K_ALIGNED(addr)) {
294292
flash_npcx_uma_cmd_by_addr(dev, SPI_NOR_CMD_BE, addr);
295293
addr += BLOCK_64K_SIZE;
296294
size -= BLOCK_64K_SIZE;
297-
} else if ((size >= BLOCK_4K_SIZE) && offset_4k_aligned) {
295+
} else {
298296
flash_npcx_uma_cmd_by_addr(dev, SPI_NOR_CMD_SE, addr);
299297
addr += BLOCK_4K_SIZE;
300298
size -= BLOCK_4K_SIZE;
301-
} else {
302-
return -EINVAL;
303299
}
304300
ret = flash_npcx_nor_wait_until_ready(dev);
305301
if (ret != 0) {

0 commit comments

Comments
 (0)