All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thorsten Blum <blum@kernel.org>
To: Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>
Cc: Thorsten Blum <blum@kernel.org>,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] crypto: sa2ul - avoid rollback in sa_init_ctx_info()
Date: Wed,  4 Nov 2026 09:20:56 +0100	[thread overview]
Message-ID: <20261104082056.47165-2-blum@kernel.org> (raw)

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)

             reply	other threads:[~2026-11-04  8:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04  8:20 Thorsten Blum [this message]
2026-11-04 13:06 ` [PATCH] crypto: sa2ul - avoid rollback in sa_init_ctx_info() Chawdhry, Manorit
2026-11-04 13:23   ` Thorsten Blum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261104082056.47165-2-blum@kernel.org \
    --to=blum@kernel.org \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.