Skip to content

Commit

Permalink
mctp: serial: Fix starting value for frame check sequence
Browse files Browse the repository at this point in the history
RFC1662 defines the start state for the crc16 FCS to be 0xffff, but
we're currently starting at zero.

This change uses the correct start state. We're only early in the
adoption for the serial binding, so there aren't yet any other users to
interface to.

Fixes: a0c2ccd ("mctp: Add MCTP-over-serial transport binding")
Reported-by: Harsh Tyagi <harshtya@google.com>
Tested-by: Harsh Tyagi <harshtya@google.com>
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Reviewed-by: Alexander Duyck <alexanderduyck@fb.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jeremy Kerr authored and David S. Miller committed Dec 19, 2022
1 parent 1b0c84a commit 2856a62
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/net/mctp/mctp-serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#define BYTE_FRAME 0x7e
#define BYTE_ESC 0x7d

#define FCS_INIT 0xffff

static DEFINE_IDA(mctp_serial_ida);

enum mctp_serial_state {
Expand Down Expand Up @@ -123,7 +125,7 @@ static void mctp_serial_tx_work(struct work_struct *work)
buf[2] = dev->txlen;

if (!dev->txpos)
dev->txfcs = crc_ccitt(0, buf + 1, 2);
dev->txfcs = crc_ccitt(FCS_INIT, buf + 1, 2);

txlen = write_chunk(dev, buf + dev->txpos, 3 - dev->txpos);
if (txlen <= 0) {
Expand Down Expand Up @@ -303,7 +305,7 @@ static void mctp_serial_push_header(struct mctp_serial *dev, unsigned char c)
case 1:
if (c == MCTP_SERIAL_VERSION) {
dev->rxpos++;
dev->rxfcs = crc_ccitt_byte(0, c);
dev->rxfcs = crc_ccitt_byte(FCS_INIT, c);
} else {
dev->rxstate = STATE_ERR;
}
Expand Down

0 comments on commit 2856a62

Please sign in to comment.