From 4ec4d341eb5b9505c5dee5a2f4ebcf017573f0e4 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Wed, 28 Sep 2011 02:18:44 +0000 Subject: [PATCH] Micro-optimize scst_unpack_lun(): avoid comparing "len" twice with the constant "2". Signed-off-by: Bart Van Assche git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@3883 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_lib.c | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index f5b1dd42a..e9c70bb1b 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -5292,30 +5292,28 @@ uint64_t scst_unpack_lun(const uint8_t *lun, int len) TRACE_BUFF_FLAG(TRACE_DEBUG, "Raw LUN", lun, len); - if (unlikely(len < 2)) { - PRINT_ERROR("Illegal lun length %d, expected 2 bytes or " - "more", len); - goto out; - } - - if (len > 2) { - switch (len) { - case 8: - if ((*((__be64 *)lun) & - cpu_to_be64(0x0000FFFFFFFFFFFFLL)) != 0) - goto out_err; - break; - case 4: - if (*((__be16 *)&lun[2]) != 0) - goto out_err; - break; - case 6: - if (*((__be32 *)&lun[2]) != 0) - goto out_err; - break; - default: + switch (len) { + case 2: + break; + case 8: + if ((*((__be64 *)lun) & cpu_to_be64(0x0000FFFFFFFFFFFFLL)) != 0) goto out_err; - } + break; + case 4: + if (*((__be16 *)&lun[2]) != 0) + goto out_err; + break; + case 6: + if (*((__be32 *)&lun[2]) != 0) + goto out_err; + break; + case 1: + case 0: + PRINT_ERROR("Illegal lun length %d, expected 2 bytes " + "or more", len); + goto out; + default: + goto out_err; } address_method = (*lun) >> 6; /* high 2 bits of byte 0 */