From 9bb568b7997f25cfc34612d6235e12357a859722 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 22 Sep 2013 19:06:48 +0200 Subject: [PATCH] driver acr122_usb: fix dead code issue Redundant result check leading to dead code was probably indicative of a missing return value check of acr122_usb_send_apdu() Problem reported by Coverity: at_least: At condition "res < 0", the value of "res" must be at least 12. cannot_single: At condition "res < 0", the value of "res" cannot be equal to -6. dead_error_condition: The condition "res < 0" cannot be true. CID 1090327 (#1 of 1): Logically dead code (DEADCODE) dead_error_begin: Execution cannot reach this statement "acr122_usb_ack(pnd);". --- libnfc/drivers/acr122_usb.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/libnfc/drivers/acr122_usb.c b/libnfc/drivers/acr122_usb.c index ec33dfe..8a16920 100644 --- a/libnfc/drivers/acr122_usb.c +++ b/libnfc/drivers/acr122_usb.c @@ -616,6 +616,8 @@ read: } if (res < 12) { log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Invalid RDR_to_PC_DataBlock frame"); + // try to interrupt current device state + acr122_usb_ack(pnd); pnd->last_error = NFC_EIO; return pnd->last_error; } @@ -644,27 +646,25 @@ read: pnd->last_error = NFC_EIO; return pnd->last_error; } - acr122_usb_send_apdu(pnd, APDU_GetAdditionnalData, 0x00, 0x00, NULL, 0, abtRxBuf[11], abtRxBuf, sizeof(abtRxBuf)); - } - offset = 0; - if (res == NFC_ETIMEOUT) { - if (DRIVER_DATA(pnd)->abort_flag) { - DRIVER_DATA(pnd)->abort_flag = false; + res = acr122_usb_send_apdu(pnd, APDU_GetAdditionnalData, 0x00, 0x00, NULL, 0, abtRxBuf[11], abtRxBuf, sizeof(abtRxBuf)); + if (res == NFC_ETIMEOUT) { + if (DRIVER_DATA(pnd)->abort_flag) { + DRIVER_DATA(pnd)->abort_flag = false; + acr122_usb_ack(pnd); + pnd->last_error = NFC_EOPABORTED; + return pnd->last_error; + } else { + goto read; // FIXME May cause some trouble on Touchatag, right ? + } + } + if (res < 12) { + // try to interrupt current device state acr122_usb_ack(pnd); - pnd->last_error = NFC_EOPABORTED; + pnd->last_error = NFC_EIO; return pnd->last_error; - } else { - goto read; // FIXME May cause some trouble on Touchatag, right ? } } - - if (res < 0) { - // try to interrupt current device state - acr122_usb_ack(pnd); - pnd->last_error = res; - return pnd->last_error; - } - + offset = 0; if (abtRxBuf[offset] != attempted_response) { log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Frame header mismatch"); pnd->last_error = NFC_EIO;