From: "Arnd Bergmann" <arnd@arndb.de>
To: "Herbert Xu" <herbert@gondor.apana.org.au>
Cc: "Arnd Bergmann" <arnd@kernel.org>,
"Corentin Labbe" <clabbe.montjoie@gmail.com>,
"David S . Miller" <davem@davemloft.net>,
"Chen-Yu Tsai" <wens@kernel.org>,
"Jernej Skrabec" <jernej.skrabec@gmail.com>,
"Samuel Holland" <samuel@sholland.org>,
"Eric Biggers" <ebiggers@kernel.org>,
"Ovidiu Panait" <ovidiu.panait.oss@gmail.com>,
linux-crypto@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] crypto: sun8i-ss - avoid hash and rng references
Date: Thu, 23 Apr 2026 12:26:23 +0200 [thread overview]
Message-ID: <3948e39f-dd20-44e2-b264-dc2a0a88f5b5@app.fastmail.com> (raw)
In-Reply-To: <aenmEQNhhw9bnxEa@gondor.apana.org.au>
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);
}
next prev parent reply other threads:[~2026-04-23 10:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-23 6:55 [PATCH] crypto: sun8i-ss - avoid hash and rng references Arnd Bergmann
2026-04-23 9:00 ` Herbert Xu
2026-04-23 9:25 ` Arnd Bergmann
2026-04-23 9:27 ` Herbert Xu
2026-04-23 10:26 ` Arnd Bergmann [this message]
2026-04-23 11:09 ` 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=3948e39f-dd20-44e2-b264-dc2a0a88f5b5@app.fastmail.com \
--to=arnd@arndb.de \
--cc=arnd@kernel.org \
--cc=clabbe.montjoie@gmail.com \
--cc=davem@davemloft.net \
--cc=ebiggers@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=jernej.skrabec@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=ovidiu.panait.oss@gmail.com \
--cc=samuel@sholland.org \
--cc=wens@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