]> sigrok.org Git - libsigrok.git/blobdiff - hardware/radioshack-dmm/protocol.c
radioshack-dmm: Check for valid mode before calculating checksum
[libsigrok.git] / hardware / radioshack-dmm / protocol.c
index de925b56838ebd376bbecb723fb710cee2b8172b..f74e7017a473515d366b142a104bdf77a59dd273 100644 (file)
@@ -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))