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 <mr.nuke.me@gmail.com>
This commit is contained in:
Alexandru Gagniuc 2012-11-21 19:30:26 -06:00
parent 54be7c005e
commit 2ecc5d432f
1 changed files with 6 additions and 2 deletions

View 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) 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; return FALSE;
if (!(rs_packet->mode < MODE_INVALID)) if (!checksum_valid(rs_packet))
return FALSE; return FALSE;
if (!selection_good(rs_packet)) if (!selection_good(rs_packet))