]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
crypto: pcrypt - Optimize pcrypt_aead_init_tfm()
authorYury Norov [NVIDIA] <yury.norov@gmail.com>
Wed, 4 Jun 2025 20:47:40 +0000 (16:47 -0400)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 13 Jun 2025 09:26:17 +0000 (17:26 +0800)
The function opencodes cpumask_nth(). The dedicated helper is faster
than an open for-loop.

Signed-off-by: Yury Norov [NVIDIA] <yury.norov@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/pcrypt.c

index c33d29a523e0206d0fa19d065d03ad5ff1814b45..c3a9d4f2995c7a4b6b55d5342ff726774d68d79d 100644 (file)
@@ -178,7 +178,7 @@ static int pcrypt_aead_decrypt(struct aead_request *req)
 
 static int pcrypt_aead_init_tfm(struct crypto_aead *tfm)
 {
-       int cpu, cpu_index;
+       int cpu_index;
        struct aead_instance *inst = aead_alg_instance(tfm);
        struct pcrypt_instance_ctx *ictx = aead_instance_ctx(inst);
        struct pcrypt_aead_ctx *ctx = crypto_aead_ctx(tfm);
@@ -187,10 +187,7 @@ static int pcrypt_aead_init_tfm(struct crypto_aead *tfm)
        cpu_index = (unsigned int)atomic_inc_return(&ictx->tfm_count) %
                    cpumask_weight(cpu_online_mask);
 
-       ctx->cb_cpu = cpumask_first(cpu_online_mask);
-       for (cpu = 0; cpu < cpu_index; cpu++)
-               ctx->cb_cpu = cpumask_next(ctx->cb_cpu, cpu_online_mask);
-
+       ctx->cb_cpu = cpumask_nth(cpu_index, cpu_online_mask);
        cipher = crypto_spawn_aead(&ictx->spawn);
 
        if (IS_ERR(cipher))