From: Rosen Penev <rosenp@gmail.com>
To: linux-crypto@vger.kernel.org
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-kernel@vger.kernel.org (open list),
linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not
covered by other areas):Keyword:\b__counted_by(_le|_be)?\b)
Subject: [PATCH] talitos: allocate channels with main struct
Date: Wed, 6 May 2026 01:56:53 -0700 [thread overview]
Message-ID: <20260506085653.1211263-1-rosenp@gmail.com> (raw)
Use a flexible array member to combine allocations.
Add __counted_by for extra runtime analysis.
Error in case of no channels as they are required.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
v2: error when no channels
drivers/crypto/talitos.c | 19 +++++++------------
drivers/crypto/talitos.h | 5 +++--
2 files changed, 10 insertions(+), 14 deletions(-)
diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index bc61d0fe3514..bd4cc06ee13c 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -3409,14 +3409,20 @@ static int talitos_probe(struct platform_device *ofdev)
struct device *dev = &ofdev->dev;
struct device_node *np = ofdev->dev.of_node;
struct talitos_private *priv;
+ unsigned int num_channels;
int i, err;
int stride;
struct resource *res;
- priv = devm_kzalloc(dev, sizeof(struct talitos_private), GFP_KERNEL);
+ if (of_property_read_u32(np, "fsl,num-channels", &num_channels))
+ return -EINVAL;
+
+ priv = devm_kzalloc(dev, struct_size(priv, chan, num_channels), GFP_KERNEL);
if (!priv)
return -ENOMEM;
+ priv->num_channels = num_channels;
+
INIT_LIST_HEAD(&priv->alg_list);
dev_set_drvdata(dev, priv);
@@ -3436,7 +3442,6 @@ static int talitos_probe(struct platform_device *ofdev)
}
/* get SEC version capabilities from device tree */
- of_property_read_u32(np, "fsl,num-channels", &priv->num_channels);
of_property_read_u32(np, "fsl,channel-fifo-len", &priv->chfifo_len);
of_property_read_u32(np, "fsl,exec-units-mask", &priv->exec_units);
of_property_read_u32(np, "fsl,descriptor-types-mask",
@@ -3511,16 +3516,6 @@ static int talitos_probe(struct platform_device *ofdev)
}
}
- priv->chan = devm_kcalloc(dev,
- priv->num_channels,
- sizeof(struct talitos_channel),
- GFP_KERNEL);
- if (!priv->chan) {
- dev_err(dev, "failed to allocate channel management space\n");
- err = -ENOMEM;
- goto err_out;
- }
-
priv->fifo_len = roundup_pow_of_two(priv->chfifo_len);
for (i = 0; i < priv->num_channels; i++) {
diff --git a/drivers/crypto/talitos.h b/drivers/crypto/talitos.h
index 1a93ee355929..34b0b5fab7e7 100644
--- a/drivers/crypto/talitos.h
+++ b/drivers/crypto/talitos.h
@@ -139,8 +139,6 @@ struct talitos_private {
*/
unsigned int fifo_len;
- struct talitos_channel *chan;
-
/* next channel to be assigned next incoming descriptor */
atomic_t last_chan ____cacheline_aligned;
@@ -153,6 +151,9 @@ struct talitos_private {
/* hwrng device */
struct hwrng rng;
bool rng_registered;
+
+ struct talitos_channel chan[] __counted_by(num_channels);
+
};
/* .features flag */
--
2.54.0
next reply other threads:[~2026-05-06 8:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-06 8:56 Rosen Penev [this message]
2026-05-06 9:25 ` [PATCH] talitos: allocate channels with main struct Paul Louvel
-- strict thread matches above, loose matches on Subject: below --
2026-04-30 21:43 Rosen Penev
2026-05-05 5:50 ` 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=20260506085653.1211263-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=davem@davemloft.net \
--cc=gustavoars@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=kees@kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-hardening@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