Nick: icon E-mail: none Board: ch347 Contents: diff --git a/ch347_spi.c b/ch347_spi.c index 71700f01590f..715f7e308264 100644 --- a/ch347_spi.c +++ b/ch347_spi.c @@ -167,12 +167,12 @@ static int ch347_read(struct ch347_spi_data *ch347_data, unsigned int readcnt, u msg_perr("CH347 returned less data than data length header indicates\n"); return -1; } - bytes_read += ch347_data_length; - if (bytes_read > readcnt) { + if (bytes_read + ch347_data_length > readcnt) { msg_perr("CH347 returned more bytes than requested"); return -1; } memcpy(readarr + bytes_read, buffer + 3, ch347_data_length); + bytes_read += ch347_data_length; } return 0; }