From 917d8bc68be8f1f5dd2daa336ad2eeafd44280b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ronald=20Tschal=C3=A4r?= Date: Sat, 3 Mar 2018 21:37:35 -0800 Subject: [PATCH] applespi: Verify crc before verifying fields. Minor, but we shouldn't really be looking at anything inside a message before verifying the crc. --- applespi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/applespi.c b/applespi.c index 4c099bc..532add4 100644 --- a/applespi.c +++ b/applespi.c @@ -1385,15 +1385,15 @@ static void applespi_got_data(struct applespi_data *applespi) applespi->saved_msg_len = 0; /* got complete message - verify */ + if (!applespi_verify_crc(applespi, (u8 *)message, msg_len)) + goto cleanup; + if (le16_to_cpu(message->length) != msg_len - MSG_HEADER_SIZE - 2) { dev_warn_ratelimited(&applespi->spi->dev, "Received corrupted packet (invalid message length)\n"); goto cleanup; } - if (!applespi_verify_crc(applespi, (u8 *)message, msg_len)) - goto cleanup; - /* handle message */ if (packet->flags == PACKET_TYPE_READ && packet->device == PACKET_DEV_KEYB) {