Skip to content

Commit

Permalink
Fix uninitialized variable on unaligned SPI Xfer
Browse files Browse the repository at this point in the history
We use a stack-allocated u32 to store a temporary word that gets memcpy'd from a potentially unaligned buffer, but the size of the copy could be less than 4 bytes, therefore leaving garbage in the upper bits of said word. This fixes CODEC in Corgi3DS.
  • Loading branch information
Wolfvak authored and d0k3 committed Dec 23, 2020
1 parent d63db4b commit 65f6748
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion common/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static void SPI_SingleXfer(u32 reg, u32 bus, void *buffer, u32 len, bool read)
u32 tmp = REG_SPI(bus, REG_SPI_FIFO);
memcpy((u8 *) buffer + pos, &tmp, min(4, len - pos));
} else {
u32 tmp;
u32 tmp = 0;
memcpy(&tmp, (u8 *) buffer + pos, min(4, len - pos));
REG_SPI(bus, REG_SPI_FIFO) = tmp;
}
Expand Down

0 comments on commit 65f6748

Please sign in to comment.