Skip to content

Commit

Permalink
drivers/flash/soc_flash_mcux: adjust alignment logic
Browse files Browse the repository at this point in the history
The current alignment logic does not work as expected if given unaligned
values, resulting in a skip of the first word. The length also has to
take into account the starting address: for example, asking for 2 bytes
at offset 3 should actually check 8 bytes.

This patch adjusts the logic so that it always includes the first and
the last word of the input area.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
  • Loading branch information
pillo79 committed Nov 5, 2024
1 parent 9d78c65 commit 14f63ba
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/flash/soc_flash_mcux.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ static int flash_mcux_read(const struct device *dev, off_t offset,
/* Check id the ECC issue is due to the Flash being erased
* ("addr" and "len" must be word-aligned for this call).
*/
rc = FLASH_VerifyErase(&priv->config, ((addr + 0x3) & ~0x3), ((len + 0x3) & ~0x3));
rc = FLASH_VerifyErase(&priv->config,
ROUND_DOWN(addr, 4),
ROUND_DOWN(addr + len + 3, 4) - ROUND_DOWN(addr, 4));

Check notice on line 226 in drivers/flash/soc_flash_mcux.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/flash/soc_flash_mcux.c:226 - rc = FLASH_VerifyErase(&priv->config, - ROUND_DOWN(addr, 4), + rc = FLASH_VerifyErase(&priv->config, ROUND_DOWN(addr, 4),
if (rc == kStatus_FLASH_Success) {
rc = -ENODATA;
} else {
Expand Down

0 comments on commit 14f63ba

Please sign in to comment.