mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 01:32:21 +02:00
crypto: api - use designated initializers for report structs
Use designated initializers for the report structs instead of clearing the struct with memset() and then copying fixed strings with strscpy() at runtime. This keeps the structs zero-initialized, lets the compiler diagnose oversized string literals, and makes the code easier to read. Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
c36faca103
commit
6b261b9bae
|
|
@ -51,11 +51,9 @@ static inline struct acomp_alg *crypto_acomp_alg(struct crypto_acomp *tfm)
|
|||
static int __maybe_unused crypto_acomp_report(
|
||||
struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct crypto_report_acomp racomp;
|
||||
|
||||
memset(&racomp, 0, sizeof(racomp));
|
||||
|
||||
strscpy(racomp.type, "acomp", sizeof(racomp.type));
|
||||
struct crypto_report_acomp racomp = {
|
||||
.type = "acomp",
|
||||
};
|
||||
|
||||
return nla_put(skb, CRYPTOCFGA_REPORT_ACOMP, sizeof(racomp), &racomp);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,13 +136,11 @@ static int crypto_aead_init_tfm(struct crypto_tfm *tfm)
|
|||
static int __maybe_unused crypto_aead_report(
|
||||
struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct crypto_report_aead raead;
|
||||
struct aead_alg *aead = container_of(alg, struct aead_alg, base);
|
||||
|
||||
memset(&raead, 0, sizeof(raead));
|
||||
|
||||
strscpy(raead.type, "aead", sizeof(raead.type));
|
||||
strscpy(raead.geniv, "<none>", sizeof(raead.geniv));
|
||||
struct crypto_report_aead raead = {
|
||||
.type = "aead",
|
||||
.geniv = "<none>",
|
||||
};
|
||||
|
||||
raead.blocksize = alg->cra_blocksize;
|
||||
raead.maxauthsize = aead->maxauthsize;
|
||||
|
|
|
|||
|
|
@ -789,11 +789,9 @@ static void crypto_ahash_free_instance(struct crypto_instance *inst)
|
|||
static int __maybe_unused crypto_ahash_report(
|
||||
struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct crypto_report_hash rhash;
|
||||
|
||||
memset(&rhash, 0, sizeof(rhash));
|
||||
|
||||
strscpy(rhash.type, "ahash", sizeof(rhash.type));
|
||||
struct crypto_report_hash rhash = {
|
||||
.type = "ahash",
|
||||
};
|
||||
|
||||
rhash.blocksize = alg->cra_blocksize;
|
||||
rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize;
|
||||
|
|
|
|||
|
|
@ -36,11 +36,9 @@ struct crypto_akcipher_sync_data {
|
|||
static int __maybe_unused crypto_akcipher_report(
|
||||
struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct crypto_report_akcipher rakcipher;
|
||||
|
||||
memset(&rakcipher, 0, sizeof(rakcipher));
|
||||
|
||||
strscpy(rakcipher.type, "akcipher", sizeof(rakcipher.type));
|
||||
struct crypto_report_akcipher rakcipher = {
|
||||
.type = "akcipher",
|
||||
};
|
||||
|
||||
return nla_put(skb, CRYPTOCFGA_REPORT_AKCIPHER,
|
||||
sizeof(rakcipher), &rakcipher);
|
||||
|
|
|
|||
|
|
@ -70,11 +70,9 @@ static struct crypto_alg *crypto_alg_match(struct crypto_user_alg *p, int exact)
|
|||
|
||||
static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct crypto_report_cipher rcipher;
|
||||
|
||||
memset(&rcipher, 0, sizeof(rcipher));
|
||||
|
||||
strscpy(rcipher.type, "cipher", sizeof(rcipher.type));
|
||||
struct crypto_report_cipher rcipher = {
|
||||
.type = "cipher",
|
||||
};
|
||||
|
||||
rcipher.blocksize = alg->cra_blocksize;
|
||||
rcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
|
||||
|
|
@ -103,10 +101,10 @@ static int crypto_report_one(struct crypto_alg *alg,
|
|||
if (nla_put_u32(skb, CRYPTOCFGA_PRIORITY_VAL, alg->cra_priority))
|
||||
goto nla_put_failure;
|
||||
if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
|
||||
struct crypto_report_larval rl;
|
||||
struct crypto_report_larval rl = {
|
||||
.type = "larval",
|
||||
};
|
||||
|
||||
memset(&rl, 0, sizeof(rl));
|
||||
strscpy(rl.type, "larval", sizeof(rl.type));
|
||||
if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL, sizeof(rl), &rl))
|
||||
goto nla_put_failure;
|
||||
goto out;
|
||||
|
|
|
|||
|
|
@ -20,11 +20,9 @@
|
|||
static int __maybe_unused crypto_kpp_report(
|
||||
struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct crypto_report_kpp rkpp;
|
||||
|
||||
memset(&rkpp, 0, sizeof(rkpp));
|
||||
|
||||
strscpy(rkpp.type, "kpp", sizeof(rkpp.type));
|
||||
struct crypto_report_kpp rkpp = {
|
||||
.type = "kpp",
|
||||
};
|
||||
|
||||
return nla_put(skb, CRYPTOCFGA_REPORT_KPP, sizeof(rkpp), &rkpp);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -264,12 +264,10 @@ static int __maybe_unused crypto_lskcipher_report(
|
|||
struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct lskcipher_alg *skcipher = __crypto_lskcipher_alg(alg);
|
||||
struct crypto_report_blkcipher rblkcipher;
|
||||
|
||||
memset(&rblkcipher, 0, sizeof(rblkcipher));
|
||||
|
||||
strscpy(rblkcipher.type, "lskcipher", sizeof(rblkcipher.type));
|
||||
strscpy(rblkcipher.geniv, "<none>", sizeof(rblkcipher.geniv));
|
||||
struct crypto_report_blkcipher rblkcipher = {
|
||||
.type = "lskcipher",
|
||||
.geniv = "<none>",
|
||||
};
|
||||
|
||||
rblkcipher.blocksize = alg->cra_blocksize;
|
||||
rblkcipher.min_keysize = skcipher->co.min_keysize;
|
||||
|
|
|
|||
|
|
@ -65,11 +65,9 @@ static unsigned int seedsize(struct crypto_alg *alg)
|
|||
static int __maybe_unused crypto_rng_report(
|
||||
struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct crypto_report_rng rrng;
|
||||
|
||||
memset(&rrng, 0, sizeof(rrng));
|
||||
|
||||
strscpy(rrng.type, "rng", sizeof(rrng.type));
|
||||
struct crypto_report_rng rrng = {
|
||||
.type = "rng",
|
||||
};
|
||||
|
||||
rrng.seedsize = seedsize(alg);
|
||||
|
||||
|
|
|
|||
|
|
@ -48,11 +48,9 @@ static DECLARE_WORK(scomp_scratch_work, scomp_scratch_workfn);
|
|||
static int __maybe_unused crypto_scomp_report(
|
||||
struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct crypto_report_comp rscomp;
|
||||
|
||||
memset(&rscomp, 0, sizeof(rscomp));
|
||||
|
||||
strscpy(rscomp.type, "scomp", sizeof(rscomp.type));
|
||||
struct crypto_report_comp rscomp = {
|
||||
.type = "scomp",
|
||||
};
|
||||
|
||||
return nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
|
||||
sizeof(rscomp), &rscomp);
|
||||
|
|
|
|||
|
|
@ -333,12 +333,10 @@ static void crypto_shash_free_instance(struct crypto_instance *inst)
|
|||
static int __maybe_unused crypto_shash_report(
|
||||
struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct crypto_report_hash rhash;
|
||||
struct shash_alg *salg = __crypto_shash_alg(alg);
|
||||
|
||||
memset(&rhash, 0, sizeof(rhash));
|
||||
|
||||
strscpy(rhash.type, "shash", sizeof(rhash.type));
|
||||
struct crypto_report_hash rhash = {
|
||||
.type = "shash",
|
||||
};
|
||||
|
||||
rhash.blocksize = alg->cra_blocksize;
|
||||
rhash.digestsize = salg->digestsize;
|
||||
|
|
|
|||
|
|
@ -53,9 +53,9 @@ static void __maybe_unused crypto_sig_show(struct seq_file *m,
|
|||
static int __maybe_unused crypto_sig_report(struct sk_buff *skb,
|
||||
struct crypto_alg *alg)
|
||||
{
|
||||
struct crypto_report_sig rsig = {};
|
||||
|
||||
strscpy(rsig.type, "sig", sizeof(rsig.type));
|
||||
struct crypto_report_sig rsig = {
|
||||
.type = "sig",
|
||||
};
|
||||
|
||||
return nla_put(skb, CRYPTOCFGA_REPORT_SIG, sizeof(rsig), &rsig);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -591,12 +591,10 @@ static int __maybe_unused crypto_skcipher_report(
|
|||
struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct skcipher_alg *skcipher = __crypto_skcipher_alg(alg);
|
||||
struct crypto_report_blkcipher rblkcipher;
|
||||
|
||||
memset(&rblkcipher, 0, sizeof(rblkcipher));
|
||||
|
||||
strscpy(rblkcipher.type, "skcipher", sizeof(rblkcipher.type));
|
||||
strscpy(rblkcipher.geniv, "<none>", sizeof(rblkcipher.geniv));
|
||||
struct crypto_report_blkcipher rblkcipher = {
|
||||
.type = "skcipher",
|
||||
.geniv = "<none>",
|
||||
};
|
||||
|
||||
rblkcipher.blocksize = alg->cra_blocksize;
|
||||
rblkcipher.min_keysize = skcipher->min_keysize;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user