]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
crypto/init.c optimize ossl_(un)likely
authorNorbert Pocs <norbertp@openssl.org>
Thu, 3 Jul 2025 14:16:34 +0000 (16:16 +0200)
committerNeil Horman <nhorman@openssl.org>
Wed, 16 Jul 2025 17:07:15 +0000 (13:07 -0400)
Signed-off-by: Norbert Pocs <norbertp@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27961)

crypto/init.c

index 2da4914707b1f2ce5e036354851e2d9acf0a50b0..e2fe479db5f025cc49693faea2c95554f97b5db2 100644 (file)
@@ -502,7 +502,7 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
     int aloaddone = 0;
 
    /* Applications depend on 0 being returned when cleanup was already done */
-    if (stopped) {
+    if (ossl_unlikely(stopped)) {
         if (!(opts & OPENSSL_INIT_BASE_ONLY))
             ERR_raise(ERR_LIB_CRYPTO, ERR_R_INIT_FAIL);
         return 0;
@@ -521,7 +521,7 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
      * unnecessarily - but all the critical code is contained in RUN_ONCE
      * functions anyway so we are safe.
      */
-    if (CRYPTO_atomic_load(&optsdone, &tmp, NULL)) {
+    if (ossl_likely(CRYPTO_atomic_load(&optsdone, &tmp, NULL))) {
         if ((tmp & opts) == opts)
             return 1;
         aloaddone = 1;
@@ -541,7 +541,7 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
      * If we remain the only caller of err_shelve_state() the recursion should
      * perhaps be removed, but if in doubt, it can be left in place.
      */
-    if (!RUN_ONCE(&base, ossl_init_base))
+    if (ossl_unlikely(!RUN_ONCE(&base, ossl_init_base)))
         return 0;
 
     if (opts & OPENSSL_INIT_BASE_ONLY)