From 3e04fc102005885b65f02c0673848a9e24bc6df3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ronald=20Tschal=C3=A4r?= Date: Sun, 25 Feb 2018 18:38:25 -0800 Subject: [PATCH 1/2] applespi: Fix spelling mistake in comment. --- applespi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applespi.c b/applespi.c index 96c7155..4c099bc 100644 --- a/applespi.c +++ b/applespi.c @@ -32,7 +32,7 @@ * of exchanges: reads, and writes. A read is signaled by a GPE, upon which one * message can be read from the device. A write exchange consists of writing a * command message, immediately reading a short status packet, and then, upon - * receiving a GPE, reading the response messsage. Write exchanges cannot be + * receiving a GPE, reading the response message. Write exchanges cannot be * interleaved, i.e. a new write exchange must not be started till the previous * write exchange is complete. Whether a received message is part of a read or * write exchange is indicated in the encapsulating packet's flags field. 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 2/2] 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) {