]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
crypto: stm32 - use list_first_entry_or_null to simplify cryp_find_dev
authorThorsten Blum <thorsten.blum@linux.dev>
Fri, 20 Mar 2026 08:49:14 +0000 (09:49 +0100)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 27 Mar 2026 09:52:43 +0000 (18:52 +0900)
Use list_first_entry_or_null() to simplify stm32_cryp_find_dev() and
remove the now-unused local variable 'struct stm32_cryp *tmp'.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: Kees Cook <kees@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/stm32/stm32-cryp.c

index 3c9b3f67946158dd8aa92aaec764e8c69bd688f9..b79877099942e530e17cf61ab0b4d96333e6e958 100644 (file)
@@ -361,19 +361,13 @@ static int stm32_cryp_it_start(struct stm32_cryp *cryp);
 
 static struct stm32_cryp *stm32_cryp_find_dev(struct stm32_cryp_ctx *ctx)
 {
-       struct stm32_cryp *tmp, *cryp = NULL;
+       struct stm32_cryp *cryp;
 
        spin_lock_bh(&cryp_list.lock);
-       if (!ctx->cryp) {
-               list_for_each_entry(tmp, &cryp_list.dev_list, list) {
-                       cryp = tmp;
-                       break;
-               }
-               ctx->cryp = cryp;
-       } else {
-               cryp = ctx->cryp;
-       }
-
+       if (!ctx->cryp)
+               ctx->cryp = list_first_entry_or_null(&cryp_list.dev_list,
+                                                    struct stm32_cryp, list);
+       cryp = ctx->cryp;
        spin_unlock_bh(&cryp_list.lock);
 
        return cryp;