crypto: ccree - replace snprintf("%s") with strscpy
Subsystems (2)
PATCH 1/1 crypto: ccree - replace snprintf("%s") with strscpy
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 <[email protected]>
--- 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(-)
drivers/crypto/ccree/cc_aead.c +4 -5
@@ -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 ;
drivers/crypto/ccree/cc_cipher.c +3 -4
@@ -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 ;
drivers/crypto/ccree/cc_hash.c +5 -8
@@ -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 ();
Herbert Xu
maintainerQuoted 10 lines · Thorsten Blum
Replace
snprintf("%s")with the faster and more directstrscpy().In
cc_aead.c, group the includes while at it.Signed-off-by Thorsten Blum <[email protected]>--- 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(-)
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt