1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-30 00:00:16 +01:00

drivers: spi: avoid leaking uninitialized bits

Before this commit, line 84 read 'u' before it had a value, on 1st for-loop iteration. See comment on line 84 below:

82		for (n = 0; n < 8; n++) {
83			ctx->gpio->set(ctx->clk, inv);
84			u = (u << 1) | !!ctx->gpio->read(ctx->miso); /* <-- u is used uninitialized here */
85			ctx->gpio->set(ctx->mosi, !!(u & 0x80));
86			ctx->gpio->set(ctx->clk, !inv);
87		}
This commit is contained in:
kokke 2021-04-13 14:45:11 +02:00 committed by Andy Green
parent 0a8f64ad5f
commit 2850de1afa

View file

@ -74,7 +74,8 @@ lws_bb_spi_write(lws_bb_spi_t *ctx, const uint8_t *buf, size_t len)
static void static void
lws_bb_spi_read(lws_bb_spi_t *ctx, uint8_t *buf, size_t len) lws_bb_spi_read(lws_bb_spi_t *ctx, uint8_t *buf, size_t len)
{ {
uint8_t u, inv = !!(ctx->bb_ops.bus_mode & LWSSPIMODE_CPOL); uint8_t u = 0;
uint8_t inv = !!(ctx->bb_ops.bus_mode & LWSSPIMODE_CPOL);
while (len--) { while (len--) {
int n; int n;