Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib/lzo: add unlikely hints to overrun checks

The NEED_* macros do an implicit goto in case the safety bounds checks
fail. Add the unlikely hints as this is the error case and not a hot
path. The final assembly is slightly shorter and some jumps got
reordered according to the hints.

text data bss dec hex filename
2294 16 0 2310 906 pre/lzo1x_decompress_safe.o
2277 16 0 2293 8f5 post/lzo1x_decompress_safe.o

text data bss dec hex filename
3444 48 0 3492 da4 pre/lzo1x_compress_safe.o
3372 48 0 3420 d5c post/lzo1x_compress_safe.o

Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

David Sterba and committed by
Herbert Xu
d2236198 817fcdbd

+4 -4
+1 -1
lib/lzo/lzo1x_compress.c
··· 26 26 #define HAVE_OP(x) 1 27 27 #endif 28 28 29 - #define NEED_OP(x) if (!HAVE_OP(x)) goto output_overrun 29 + #define NEED_OP(x) if (unlikely(!HAVE_OP(x))) goto output_overrun 30 30 31 31 static noinline int 32 32 LZO_SAFE(lzo1x_1_do_compress)(const unsigned char *in, size_t in_len,
+3 -3
lib/lzo/lzo1x_decompress_safe.c
··· 22 22 23 23 #define HAVE_IP(x) ((size_t)(ip_end - ip) >= (size_t)(x)) 24 24 #define HAVE_OP(x) ((size_t)(op_end - op) >= (size_t)(x)) 25 - #define NEED_IP(x) if (!HAVE_IP(x)) goto input_overrun 26 - #define NEED_OP(x) if (!HAVE_OP(x)) goto output_overrun 27 - #define TEST_LB(m_pos) if ((m_pos) < out) goto lookbehind_overrun 25 + #define NEED_IP(x) if (unlikely(!HAVE_IP(x))) goto input_overrun 26 + #define NEED_OP(x) if (unlikely(!HAVE_OP(x))) goto output_overrun 27 + #define TEST_LB(m_pos) if (unlikely((m_pos) < out)) goto lookbehind_overrun 28 28 29 29 /* This MAX_255_COUNT is the maximum number of times we can add 255 to a base 30 30 * count without overflowing an integer. The multiply will overflow when