diff mbox series

[1/2] crypto: caam - Use struct_size()

Message ID 0fc02b533bd3c3422bec5856bc65bbb66ebf7b58.1690037578.git.christophe.jaillet@wanadoo.fr
State Accepted
Commit 6df04505f3b285f3bcfe81cf0461339b0f4ed41d
Headers show
Series [1/2] crypto: caam - Use struct_size() | expand

Commit Message

Christophe JAILLET July 22, 2023, 2:53 p.m. UTC
Use struct_size() instead of hand-writing it, when allocating a structure
with a flex array.

This is less verbose, more robust and more informative.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/crypto/caam/caamhash.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Gaurav Jain July 26, 2023, 6:43 a.m. UTC | #1
Reviewed-by: Gaurav Jain <gaurav.jain@nxp.com>

> -----Original Message-----
> From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> Sent: Saturday, July 22, 2023 8:24 PM
> To: Horia Geanta <horia.geanta@nxp.com>; Pankaj Gupta
> <pankaj.gupta@nxp.com>; Gaurav Jain <gaurav.jain@nxp.com>; Herbert Xu
> <herbert@gondor.apana.org.au>; David S. Miller <davem@davemloft.net>
> Cc: linux-kernel@vger.kernel.org; kernel-janitors@vger.kernel.org; Christophe
> JAILLET <christophe.jaillet@wanadoo.fr>; linux-crypto@vger.kernel.org
> Subject: [EXT] [PATCH 1/2] crypto: caam - Use struct_size()
> 
> Caution: This is an external email. Please take care when clicking links or
> opening attachments. When in doubt, report the message using the 'Report this
> email' button
> 
> 
> Use struct_size() instead of hand-writing it, when allocating a structure with a
> flex array.
> 
> This is less verbose, more robust and more informative.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  drivers/crypto/caam/caamhash.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
> index 80deb003f0a5..9e5924e24f2e 100644
> --- a/drivers/crypto/caam/caamhash.c
> +++ b/drivers/crypto/caam/caamhash.c
> @@ -708,9 +708,8 @@ static struct ahash_edesc *ahash_edesc_alloc(struct
> ahash_request *req,
>         gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
>                        GFP_KERNEL : GFP_ATOMIC;
>         struct ahash_edesc *edesc;
> -       unsigned int sg_size = sg_num * sizeof(struct sec4_sg_entry);
> 
> -       edesc = kzalloc(sizeof(*edesc) + sg_size, flags);
> +       edesc = kzalloc(struct_size(edesc, sec4_sg, sg_num), flags);
>         if (!edesc) {
>                 dev_err(ctx->jrdev, "could not allocate extended descriptor\n");
>                 return NULL;
> --
> 2.34.1
Herbert Xu July 28, 2023, 10:23 a.m. UTC | #2
On Sat, Jul 22, 2023 at 04:53:58PM +0200, Christophe JAILLET wrote:
> Use struct_size() instead of hand-writing it, when allocating a structure
> with a flex array.
> 
> This is less verbose, more robust and more informative.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  drivers/crypto/caam/caamhash.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)

All applied.  Thanks.
diff mbox series

Patch

diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index 80deb003f0a5..9e5924e24f2e 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -708,9 +708,8 @@  static struct ahash_edesc *ahash_edesc_alloc(struct ahash_request *req,
 	gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
 		       GFP_KERNEL : GFP_ATOMIC;
 	struct ahash_edesc *edesc;
-	unsigned int sg_size = sg_num * sizeof(struct sec4_sg_entry);
 
-	edesc = kzalloc(sizeof(*edesc) + sg_size, flags);
+	edesc = kzalloc(struct_size(edesc, sec4_sg, sg_num), flags);
 	if (!edesc) {
 		dev_err(ctx->jrdev, "could not allocate extended descriptor\n");
 		return NULL;