mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] crypto: sa2ul - avoid rollback in sa_init_ctx_info()
@ 2026-11-04  8:20 Thorsten Blum
  2026-11-04 13:06 ` Chawdhry, Manorit
  0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Blum @ 2026-11-04  8:20 UTC (permalink / raw)
  To: Herbert Xu, David S. Miller; +Cc: Thorsten Blum, linux-crypto, linux-kernel

Allocate the security context before reserving a security context ID to
avoid the rollback on allocation failure. Remove the now-unused local
error variable.

Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 drivers/crypto/sa2ul.c | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/drivers/crypto/sa2ul.c b/drivers/crypto/sa2ul.c
index e026fc14a411..964ddadaa211 100644
--- a/drivers/crypto/sa2ul.c
+++ b/drivers/crypto/sa2ul.c
@@ -748,7 +748,12 @@ static int sa_init_ctx_info(struct sa_ctx_info *ctx,
 			    struct sa_crypto_data *data)
 {
 	unsigned long bn;
-	int err;
+
+	ctx->sc = dma_pool_alloc(data->sc_pool, GFP_KERNEL, &ctx->sc_phys);
+	if (!ctx->sc) {
+		dev_err(&data->pdev->dev, "Failed to allocate SC memory\n");
+		return -ENOMEM;
+	}
 
 	spin_lock(&data->scid_lock);
 	bn = find_first_zero_bit(data->ctx_bm, SA_MAX_NUM_CTX);
@@ -758,22 +763,7 @@ static int sa_init_ctx_info(struct sa_ctx_info *ctx,
 
 	ctx->sc_id = (u16)(data->sc_id_start + bn);
 
-	ctx->sc = dma_pool_alloc(data->sc_pool, GFP_KERNEL, &ctx->sc_phys);
-	if (!ctx->sc) {
-		dev_err(&data->pdev->dev, "Failed to allocate SC memory\n");
-		err = -ENOMEM;
-		goto scid_rollback;
-	}
-
 	return 0;
-
-scid_rollback:
-	spin_lock(&data->scid_lock);
-	__clear_bit(bn, data->ctx_bm);
-	data->sc_id--;
-	spin_unlock(&data->scid_lock);
-
-	return err;
 }
 
 static void sa_cipher_cra_exit(struct crypto_skcipher *tfm)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-04 13:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-04  8:20 [PATCH] crypto: sa2ul - avoid rollback in sa_init_ctx_info() Thorsten Blum
2026-11-04 13:06 ` Chawdhry, Manorit
2026-11-04 13:23   ` Thorsten Blum

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®