From: Rajveer Chaudhari <rajveer.chaudhari.linux@gmail.com>
To: herbert@gondor.apana.org.au, davem@davemloft.net
Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
Rajveer Chaudhari <rajveer.chaudhari.linux@gmail.com>
Subject: [PATCH] crypto: drbg - convert to guard(mutex)
Date: Sun, 8 Feb 2026 04:59:25 +0530 [thread overview]
Message-ID: <20260207232925.80976-1-rajveer.chaudhari.linux@gmail.com> (raw)
Replaced old manual mutex locking/unlocking with
new safe guard(mutex) in drbg_instantiate().
This ensures mutex gets unlocked on every return and prevents deadlocks.
Signed-off-by: Rajveer Chaudhari <rajveer.chaudhari.linux@gmail.com>
---
crypto/drbg.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/crypto/drbg.c b/crypto/drbg.c
index 1d433dae9955..d52a7bd07322 100644
--- a/crypto/drbg.c
+++ b/crypto/drbg.c
@@ -103,6 +103,7 @@
#include <linux/kernel.h>
#include <linux/jiffies.h>
#include <linux/string_choices.h>
+#include <linux/cleanup.h>
/***************************************************************
* Backend cipher definitions available to DRBG
@@ -1349,7 +1350,7 @@ static int drbg_instantiate(struct drbg_state *drbg, struct drbg_string *pers,
pr_devel("DRBG: Initializing DRBG core %d with prediction resistance "
"%s\n", coreref, str_enabled_disabled(pr));
- mutex_lock(&drbg->drbg_mutex);
+ guard(mutex)(&drbg->drbg_mutex);
/* 9.1 step 1 is implicit with the selected DRBG type */
@@ -1370,7 +1371,7 @@ static int drbg_instantiate(struct drbg_state *drbg, struct drbg_string *pers,
ret = drbg_alloc_state(drbg);
if (ret)
- goto unlock;
+ return ret;
ret = drbg_prepare_hrng(drbg);
if (ret)
@@ -1384,15 +1385,9 @@ static int drbg_instantiate(struct drbg_state *drbg, struct drbg_string *pers,
if (ret && !reseed)
goto free_everything;
- mutex_unlock(&drbg->drbg_mutex);
- return ret;
-
-unlock:
- mutex_unlock(&drbg->drbg_mutex);
return ret;
free_everything:
- mutex_unlock(&drbg->drbg_mutex);
drbg_uninstantiate(drbg);
return ret;
}
--
2.52.0
next reply other threads:[~2026-02-07 23:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-07 23:29 Rajveer Chaudhari [this message]
2026-02-28 3:20 ` Herbert Xu
2026-03-01 11:46 ` Rajveer Chaudhari
2026-03-02 12:24 ` Herbert Xu
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=20260207232925.80976-1-rajveer.chaudhari.linux@gmail.com \
--to=rajveer.chaudhari.linux@gmail.com \
--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 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®