common: Improve crc8 generation

Start with 0xff instead of 0x00, so the CRC will be nonzero (and length
dependent) for data that is all zeroes.

Remove unnecessary masking, since `crc` is already an 8-bit integer.
This commit is contained in:
Samuel Holland 2021-07-08 22:38:06 -05:00 committed by Ondrej Jirman
parent 206b96c1e2
commit bd69a00f7a
2 changed files with 6 additions and 6 deletions

View file

@ -291,11 +291,11 @@ static const uint8_t crc8_0x7_table[] = {
static uint8_t crc8(const uint8_t *pdata, size_t nbytes)
{
unsigned int idx;
uint8_t crc = 0;
uint8_t crc = 0xff;
while (nbytes--) {
idx = (crc ^ *pdata);
crc = (crc8_0x7_table[idx]) & 0xff;
idx = crc ^ *pdata;
crc = crc8_0x7_table[idx];
pdata++;
}

View file

@ -557,11 +557,11 @@ static const uint8_t crc8_0x7_table[] = {
static uint8_t crc8(const uint8_t *pdata, size_t nbytes)
{
unsigned int idx;
uint8_t crc = 0;
uint8_t crc = 0xff;
while (nbytes--) {
idx = (crc ^ *pdata);
crc = (crc8_0x7_table[idx]) & 0xff;
idx = crc ^ *pdata;
crc = crc8_0x7_table[idx];
pdata++;
}