* [PATCH] lib/lzo: add unlikely hints to overrun checks
@ 2025-08-07 11:44 David Sterba
2025-08-16 9:36 ` Herbert Xu
0 siblings, 1 reply; 2+ messages in thread
From: David Sterba @ 2025-08-07 11:44 UTC (permalink / raw)
To: linux-crypto; +Cc: linux-kernel, ebiggers, herbert, David Sterba
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>
---
lib/lzo/lzo1x_compress.c | 2 +-
lib/lzo/lzo1x_decompress_safe.c | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/lzo/lzo1x_compress.c b/lib/lzo/lzo1x_compress.c
index 7b10ca86a89300..01586af2347f5e 100644
--- a/lib/lzo/lzo1x_compress.c
+++ b/lib/lzo/lzo1x_compress.c
@@ -26,7 +26,7 @@
#define HAVE_OP(x) 1
#endif
-#define NEED_OP(x) if (!HAVE_OP(x)) goto output_overrun
+#define NEED_OP(x) if (unlikely(!HAVE_OP(x))) goto output_overrun
static noinline int
LZO_SAFE(lzo1x_1_do_compress)(const unsigned char *in, size_t in_len,
diff --git a/lib/lzo/lzo1x_decompress_safe.c b/lib/lzo/lzo1x_decompress_safe.c
index c94f4928e1888b..318abb82c63d2c 100644
--- a/lib/lzo/lzo1x_decompress_safe.c
+++ b/lib/lzo/lzo1x_decompress_safe.c
@@ -22,9 +22,9 @@
#define HAVE_IP(x) ((size_t)(ip_end - ip) >= (size_t)(x))
#define HAVE_OP(x) ((size_t)(op_end - op) >= (size_t)(x))
-#define NEED_IP(x) if (!HAVE_IP(x)) goto input_overrun
-#define NEED_OP(x) if (!HAVE_OP(x)) goto output_overrun
-#define TEST_LB(m_pos) if ((m_pos) < out) goto lookbehind_overrun
+#define NEED_IP(x) if (unlikely(!HAVE_IP(x))) goto input_overrun
+#define NEED_OP(x) if (unlikely(!HAVE_OP(x))) goto output_overrun
+#define TEST_LB(m_pos) if (unlikely((m_pos) < out)) goto lookbehind_overrun
/* This MAX_255_COUNT is the maximum number of times we can add 255 to a base
* count without overflowing an integer. The multiply will overflow when
--
2.50.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] lib/lzo: add unlikely hints to overrun checks
2025-08-07 11:44 [PATCH] lib/lzo: add unlikely hints to overrun checks David Sterba
@ 2025-08-16 9:36 ` Herbert Xu
0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2025-08-16 9:36 UTC (permalink / raw)
To: David Sterba; +Cc: linux-crypto, linux-kernel, ebiggers
On Thu, Aug 07, 2025 at 01:44:44PM +0200, David Sterba wrote:
> 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>
> ---
> lib/lzo/lzo1x_compress.c | 2 +-
> lib/lzo/lzo1x_decompress_safe.c | 6 +++---
> 2 files changed, 4 insertions(+), 4 deletions(-)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-08-16 9:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-07 11:44 [PATCH] lib/lzo: add unlikely hints to overrun checks David Sterba
2025-08-16 9:36 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®