[PATCH] crypto: sun8i-ss - avoid hash and rng references
Arnd Bergmann
arnd at arndb.de
Thu Apr 23 03:26:23 PDT 2026
On Thu, Apr 23, 2026, at 11:27, Herbert Xu wrote:
> On Thu, Apr 23, 2026 at 11:25:19AM +0200, Arnd Bergmann wrote:
>>
>> Yes, I can rework the patch that way. I had considered this originally
>> but decided this would end up less readable in this case because
>> of the extra indentation level. The drivers already has a lot of
>> #ifdef checks, so adding more of those felt more in line with the
>> style used here.
>
> If we're adding new code I prefer doing it inline instead of as
> an ifdef so that we maximise compiler coverage.
Sure, but I'm not adding new code here, I only reported a regression
from Eric's (otherwise very nice) cleanup and tried to come up
with a better workaround than adding another 'select'.
I've tried to rework one driver to use IS_ENABLED() checks now
instead of the #ifdef, and also replace the for()/switch()
loop with three separate loops for simplicity. See below for
what I ended up with compared with my first patch.
I'm still not entirely happy with that version either, especially
since this is getting beyond a purely mechanical cleanup.
If you think this is better, I can do it for all three drivers,
otherwise I'd just send the oneline change to work around the
third driver link failure the same way that Eric did for the
other two, and let the sunxi maintainters worry about cleaning
it up.
Arnd
diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c
index 813c4bc6312a..330a1ed7eb03 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c
@@ -31,7 +31,7 @@ static const struct ss_variant ss_a33_variant = {
.sha1_in_be = true,
};
-static struct sun4i_ss_alg_template ss_algs[] = {
+static struct sun4i_ss_alg_template ss_ahash_algs[] = {
{ .type = CRYPTO_ALG_TYPE_AHASH,
.mode = SS_OP_MD5,
.alg.hash = {
@@ -84,6 +84,9 @@ static struct sun4i_ss_alg_template ss_algs[] = {
}
}
},
+};
+
+static struct sun4i_ss_alg_template ss_skcipher_algs[] = {
{ .type = CRYPTO_ALG_TYPE_SKCIPHER,
.alg.crypto = {
.setkey = sun4i_ss_aes_setkey,
@@ -213,7 +216,9 @@ static struct sun4i_ss_alg_template ss_algs[] = {
}
}
},
-#ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG
+};
+
+static struct sun4i_ss_alg_template ss_rng_algs[] = {
{
.type = CRYPTO_ALG_TYPE_RNG,
.alg.rng = {
@@ -229,40 +234,46 @@ static struct sun4i_ss_alg_template ss_algs[] = {
.seedsize = SS_SEED_LEN / BITS_PER_BYTE,
}
},
-#endif
};
static int sun4i_ss_debugfs_show(struct seq_file *seq, void *v)
{
unsigned int i;
- for (i = 0; i < ARRAY_SIZE(ss_algs); i++) {
- if (!ss_algs[i].ss)
+ for (i = 0; i < ARRAY_SIZE(ss_skcipher_algs); i++) {
+ if (!ss_skcipher_algs[i].ss)
continue;
- switch (ss_algs[i].type) {
- case CRYPTO_ALG_TYPE_SKCIPHER:
- seq_printf(seq, "%s %s reqs=%lu opti=%lu fallback=%lu tsize=%lu\n",
- ss_algs[i].alg.crypto.base.cra_driver_name,
- ss_algs[i].alg.crypto.base.cra_name,
- ss_algs[i].stat_req, ss_algs[i].stat_opti, ss_algs[i].stat_fb,
- ss_algs[i].stat_bytes);
- break;
-#ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG
- case CRYPTO_ALG_TYPE_RNG:
- seq_printf(seq, "%s %s reqs=%lu tsize=%lu\n",
- ss_algs[i].alg.rng.base.cra_driver_name,
- ss_algs[i].alg.rng.base.cra_name,
- ss_algs[i].stat_req, ss_algs[i].stat_bytes);
- break;
-#endif
- case CRYPTO_ALG_TYPE_AHASH:
- seq_printf(seq, "%s %s reqs=%lu\n",
- ss_algs[i].alg.hash.halg.base.cra_driver_name,
- ss_algs[i].alg.hash.halg.base.cra_name,
- ss_algs[i].stat_req);
- break;
- }
+ seq_printf(seq, "%s %s reqs=%lu opti=%lu fallback=%lu tsize=%lu\n",
+ ss_skcipher_algs[i].alg.crypto.base.cra_driver_name,
+ ss_skcipher_algs[i].alg.crypto.base.cra_name,
+ ss_skcipher_algs[i].stat_req,
+ ss_skcipher_algs[i].stat_opti,
+ ss_skcipher_algs[i].stat_fb,
+ ss_skcipher_algs[i].stat_bytes);
}
+
+ for (i = 0; i < ARRAY_SIZE(ss_ahash_algs); i++) {
+ if (!ss_ahash_algs[i].ss)
+ continue;
+
+ seq_printf(seq, "%s %s reqs=%lu tsize=%lu\n",
+ ss_ahash_algs[i].alg.rng.base.cra_driver_name,
+ ss_ahash_algs[i].alg.rng.base.cra_name,
+ ss_ahash_algs[i].stat_req,
+ ss_ahash_algs[i].stat_bytes);
+ }
+
+ for (i = 0; i < ARRAY_SIZE(ss_rng_algs); i++) {
+ if (!IS_ENABLED(CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG) ||
+ !ss_rng_algs[i].ss)
+ continue;
+
+ seq_printf(seq, "%s %s reqs=%lu\n",
+ ss_rng_algs[i].alg.hash.halg.base.cra_driver_name,
+ ss_rng_algs[i].alg.hash.halg.base.cra_name,
+ ss_rng_algs[i].stat_req);
+ }
+
return 0;
}
DEFINE_SHOW_ATTRIBUTE(sun4i_ss_debugfs);
@@ -454,34 +465,36 @@ static int sun4i_ss_probe(struct platform_device *pdev)
pm_runtime_put_sync(ss->dev);
- for (i = 0; i < ARRAY_SIZE(ss_algs); i++) {
- ss_algs[i].ss = ss;
- switch (ss_algs[i].type) {
- case CRYPTO_ALG_TYPE_SKCIPHER:
- err = crypto_register_skcipher(&ss_algs[i].alg.crypto);
- if (err) {
- dev_err(ss->dev, "Fail to register %s\n",
- ss_algs[i].alg.crypto.base.cra_name);
- goto error_alg;
- }
- break;
- case CRYPTO_ALG_TYPE_AHASH:
- err = crypto_register_ahash(&ss_algs[i].alg.hash);
- if (err) {
- dev_err(ss->dev, "Fail to register %s\n",
- ss_algs[i].alg.hash.halg.base.cra_name);
- goto error_alg;
- }
- break;
-#ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG
- case CRYPTO_ALG_TYPE_RNG:
- err = crypto_register_rng(&ss_algs[i].alg.rng);
- if (err) {
- dev_err(ss->dev, "Fail to register %s\n",
- ss_algs[i].alg.rng.base.cra_name);
- }
+ for (i = 0; i < ARRAY_SIZE(ss_skcipher_algs); i++) {
+ ss_skcipher_algs[i].ss = ss;
+ err = crypto_register_skcipher(&ss_skcipher_algs[i].alg.crypto);
+ if (err) {
+ dev_err(ss->dev, "Fail to register %s\n",
+ ss_skcipher_algs[i].alg.crypto.base.cra_name);
+ goto error_skcipher_alg;
+ }
+ }
+
+ for (i = 0; i < ARRAY_SIZE(ss_ahash_algs); i++) {
+ ss_ahash_algs[i].ss = ss;
+ err = crypto_register_ahash(&ss_ahash_algs[i].alg.hash);
+ if (err) {
+ dev_err(ss->dev, "Fail to register %s\n",
+ ss_ahash_algs[i].alg.hash.halg.base.cra_name);
+ goto error_ahash_alg;
+ }
+ }
+
+ for (i = 0; i < ARRAY_SIZE(ss_rng_algs); i++) {
+ if (!IS_ENABLED(CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG))
break;
-#endif
+
+ ss_rng_algs[i].ss = ss;
+ err = crypto_register_rng(&ss_rng_algs[i].alg.rng);
+ if (err) {
+ dev_err(ss->dev, "Fail to register %s\n",
+ ss_rng_algs[i].alg.rng.base.cra_name);
+ goto error_rng_alg;
}
}
@@ -491,23 +504,20 @@ static int sun4i_ss_probe(struct platform_device *pdev)
&sun4i_ss_debugfs_fops);
return 0;
-error_alg:
- i--;
- for (; i >= 0; i--) {
- switch (ss_algs[i].type) {
- case CRYPTO_ALG_TYPE_SKCIPHER:
- crypto_unregister_skcipher(&ss_algs[i].alg.crypto);
- break;
- case CRYPTO_ALG_TYPE_AHASH:
- crypto_unregister_ahash(&ss_algs[i].alg.hash);
- break;
-#ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG
- case CRYPTO_ALG_TYPE_RNG:
- crypto_unregister_rng(&ss_algs[i].alg.rng);
- break;
-#endif
- }
+
+error_rng_alg:
+ if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG)) {
+ for (i--; i >= 0; i--)
+ crypto_unregister_rng(&ss_rng_algs[i].alg.rng);
}
+ i = ARRAY_SIZE(ss_ahash_algs);
+error_ahash_alg:
+ for (i--; i >= 0; i--)
+ crypto_unregister_ahash(&ss_ahash_algs[i].alg.hash);
+ i = ARRAY_SIZE(ss_skcipher_algs);
+error_skcipher_alg:
+ for (i--; i >= 0; i--)
+ crypto_unregister_skcipher(&ss_skcipher_algs[i].alg.crypto);
error_pm:
sun4i_ss_pm_exit(ss);
return err;
@@ -518,21 +528,14 @@ static void sun4i_ss_remove(struct platform_device *pdev)
int i;
struct sun4i_ss_ctx *ss = platform_get_drvdata(pdev);
- for (i = 0; i < ARRAY_SIZE(ss_algs); i++) {
- switch (ss_algs[i].type) {
- case CRYPTO_ALG_TYPE_SKCIPHER:
- crypto_unregister_skcipher(&ss_algs[i].alg.crypto);
- break;
- case CRYPTO_ALG_TYPE_AHASH:
- crypto_unregister_ahash(&ss_algs[i].alg.hash);
- break;
-#ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG
- case CRYPTO_ALG_TYPE_RNG:
- crypto_unregister_rng(&ss_algs[i].alg.rng);
- break;
-#endif
- }
+ if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG)) {
+ for (i = ARRAY_SIZE(ss_rng_algs); i >= 0; i--)
+ crypto_unregister_rng(&ss_rng_algs[i].alg.rng);
}
+ for (i = ARRAY_SIZE(ss_ahash_algs); i >= 0; i--)
+ crypto_unregister_ahash(&ss_ahash_algs[i].alg.hash);
+ for (i = ARRAY_SIZE(ss_skcipher_algs) - 1; i >= 0; i--)
+ crypto_unregister_skcipher(&ss_skcipher_algs[i].alg.crypto);
sun4i_ss_pm_exit(ss);
}
More information about the linux-arm-kernel
mailing list