From: Thorsten Blum <thorsten.blum@linux.dev>
To: Gilad Ben-Yossef <gilad@benyossef.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] crypto: ccree - replace snprintf("%s") with strscpy
Date: Wed, 6 May 2026 11:21:51 +0200 [thread overview]
Message-ID: <20260506092150.177660-2-thorsten.blum@linux.dev> (raw)
Replace snprintf("%s") with the faster and more direct strscpy().
In cc_aead.c, group the includes while at it.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
drivers/crypto/ccree/cc_aead.c | 9 ++++-----
drivers/crypto/ccree/cc_cipher.c | 7 +++----
drivers/crypto/ccree/cc_hash.c | 13 +++++--------
3 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/drivers/crypto/ccree/cc_aead.c b/drivers/crypto/ccree/cc_aead.c
index 81533681f7fb..088c4603047f 100644
--- a/drivers/crypto/ccree/cc_aead.c
+++ b/drivers/crypto/ccree/cc_aead.c
@@ -3,11 +3,12 @@
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/rtnetlink.h>
+#include <linux/string.h>
#include <crypto/algapi.h>
#include <crypto/internal/aead.h>
#include <crypto/authenc.h>
#include <crypto/gcm.h>
-#include <linux/rtnetlink.h>
#include <crypto/internal/des.h>
#include "cc_driver.h"
#include "cc_buffer_mgr.h"
@@ -2569,11 +2570,9 @@ static struct cc_crypto_alg *cc_create_aead_alg(struct cc_alg_template *tmpl,
alg = &tmpl->template_aead;
- if (snprintf(alg->base.cra_name, CRYPTO_MAX_ALG_NAME, "%s",
- tmpl->name) >= CRYPTO_MAX_ALG_NAME)
+ if (strscpy(alg->base.cra_name, tmpl->name) < 0)
return ERR_PTR(-EINVAL);
- if (snprintf(alg->base.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
- tmpl->driver_name) >= CRYPTO_MAX_ALG_NAME)
+ if (strscpy(alg->base.cra_driver_name, tmpl->driver_name) < 0)
return ERR_PTR(-EINVAL);
alg->base.cra_module = THIS_MODULE;
diff --git a/drivers/crypto/ccree/cc_cipher.c b/drivers/crypto/ccree/cc_cipher.c
index e2cbfdf7a0e4..5339b3796c80 100644
--- a/drivers/crypto/ccree/cc_cipher.c
+++ b/drivers/crypto/ccree/cc_cipher.c
@@ -3,6 +3,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/string.h>
#include <crypto/algapi.h>
#include <crypto/internal/skcipher.h>
#include <crypto/internal/des.h>
@@ -1386,11 +1387,9 @@ static struct cc_crypto_alg *cc_create_alg(const struct cc_alg_template *tmpl,
memcpy(alg, &tmpl->template_skcipher, sizeof(*alg));
- if (snprintf(alg->base.cra_name, CRYPTO_MAX_ALG_NAME, "%s",
- tmpl->name) >= CRYPTO_MAX_ALG_NAME)
+ if (strscpy(alg->base.cra_name, tmpl->name) < 0)
return ERR_PTR(-EINVAL);
- if (snprintf(alg->base.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
- tmpl->driver_name) >= CRYPTO_MAX_ALG_NAME)
+ if (strscpy(alg->base.cra_driver_name, tmpl->driver_name) < 0)
return ERR_PTR(-EINVAL);
alg->base.cra_module = THIS_MODULE;
diff --git a/drivers/crypto/ccree/cc_hash.c b/drivers/crypto/ccree/cc_hash.c
index c6d085c8ff79..e090692e4371 100644
--- a/drivers/crypto/ccree/cc_hash.c
+++ b/drivers/crypto/ccree/cc_hash.c
@@ -3,6 +3,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/string.h>
#include <crypto/algapi.h>
#include <crypto/hash.h>
#include <crypto/md5.h>
@@ -1834,16 +1835,12 @@ static struct cc_hash_alg *cc_alloc_hash_alg(struct cc_hash_template *template,
alg = &halg->halg.base;
if (keyed) {
- snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s",
- template->mac_name);
- snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
- template->mac_driver_name);
+ strscpy(alg->cra_name, template->mac_name);
+ strscpy(alg->cra_driver_name, template->mac_driver_name);
} else {
halg->setkey = NULL;
- snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s",
- template->name);
- snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
- template->driver_name);
+ strscpy(alg->cra_name, template->name);
+ strscpy(alg->cra_driver_name, template->driver_name);
}
alg->cra_module = THIS_MODULE;
alg->cra_ctxsize = sizeof(struct cc_hash_ctx) + crypto_dma_padding();
reply other threads:[~2026-05-06 9:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260506092150.177660-2-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=davem@davemloft.net \
--cc=gilad@benyossef.com \
--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