From: Alexandru Gagniuc Date: Thu, 22 Nov 2012 01:30:26 +0000 (-0600) Subject: radioshack-dmm: Check for valid mode before calculating checksum X-Git-Tag: dsupstream~530 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=2ecc5d432fd17127fd221ca4940f9617569911d1;p=libsigrok.git radioshack-dmm: Check for valid mode before calculating checksum The packet mode byte is akin to a signature. If that is invalid, there's no point in calculating the checksum, so check the mode first. Signed-off-by: Alexandru Gagniuc --- diff --git a/hardware/radioshack-dmm/protocol.c b/hardware/radioshack-dmm/protocol.c index de925b56..f74e7017 100644 --- a/hardware/radioshack-dmm/protocol.c +++ b/hardware/radioshack-dmm/protocol.c @@ -176,10 +176,14 @@ static gboolean selection_good(const struct rs_22_812_packet *rs_packet) */ SR_PRIV gboolean rs_22_812_packet_valid(const struct rs_22_812_packet *rs_packet) { - if (!checksum_valid(rs_packet)) + /* + * Check for valid mode first, before calculating the checksum. + * No point calculating the checksum, if we know we'll reject the packet + * */ + if (!(rs_packet->mode < MODE_INVALID)) return FALSE; - if (!(rs_packet->mode < MODE_INVALID)) + if (!checksum_valid(rs_packet)) return FALSE; if (!selection_good(rs_packet))