Skip to content

Commit

Permalink
drivers: flash: nrf_qspi_nor: refine alignment requirements
Browse files Browse the repository at this point in the history
It's not sufficient that the read size be a multiple of four bytes;
the destination address for the read must also be properly aligned.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
  • Loading branch information
pabigot committed Apr 7, 2020
1 parent 8bd676e commit 4caa587
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions drivers/flash/nrf_qspi_nor.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,13 @@ static inline int qspi_nor_read_id(struct device *dev,
static int qspi_nor_read(struct device *dev, off_t addr, void *dest,
size_t size)
{
if (!dest) {
/* destination must be aligned to a 32-bit word. */
if ((dest == NULL) || (((uintptr_t)dest % sizeof(u32_t)) != 0)) {
return -EINVAL;
}

/* read size must be multiple of 4 bytes */
if (size % sizeof(uint32_t) ||
!(size > 0)) {
/* read size must be multiple of 32-bit words */
if ((size == 0) || ((size % sizeof(u32_t)) != 0)) {
return -EINVAL;
}

Expand Down Expand Up @@ -518,7 +518,7 @@ static int qspi_nor_write(struct device *dev, off_t addr, const void *src,
}

/* write size must be multiple of 4 bytes */
if (size % sizeof(uint32_t) ||
if (size % sizeof(u32_t) ||
!(size > 0)) {
return -EINVAL;
}
Expand Down

0 comments on commit 4caa587

Please sign in to comment.