mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] crypto: caam - switch to use devm_kmemdup_array()
@ 2025-07-19  8:34 zhang.enpei
  2025-07-19 13:00 ` Christophe JAILLET
  0 siblings, 1 reply; 4+ messages in thread
From: zhang.enpei @ 2025-07-19  8:34 UTC (permalink / raw)
  To: horia.geanta
  Cc: pankaj.gupta, gaurav.jain, herbert, davem, linux-crypto, linux-kernel

From: Zhang Enpei <zhang.enpei@zte.com.cn>
Use devm_kmemdup_array() to avoid multiplication or possible overflows.

Signed-off-by: Zhang Enpei <zhang.enpei@zte.com.cn>
---
 drivers/crypto/caam/ctrl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index ce7b99019537..2250dce9c344 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -592,9 +592,9 @@ static int init_clocks(struct device *dev, const struct caam_imx_data *data)
        int ret;

        ctrlpriv->num_clks = data->num_clks;
-       ctrlpriv->clks = devm_kmemdup(dev, data->clks,
-                                     data->num_clks * sizeof(data->clks[0]),
-                                     GFP_KERNEL);
+       ctrlpriv->clks = devm_kmemdup_array(dev, data->clks,
+                                           data->num_clks, sizeof(data->clks[0]),
+                                           GFP_KERNEL);
        if (!ctrlpriv->clks)
                return -ENOMEM;

-- 
2.25.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] crypto: caam - switch to use devm_kmemdup_array()
  2025-07-19  8:34 [PATCH] crypto: caam - switch to use devm_kmemdup_array() zhang.enpei
@ 2025-07-19 13:00 ` Christophe JAILLET
  2025-07-21  2:06   ` zhang.enpei
  0 siblings, 1 reply; 4+ messages in thread
From: Christophe JAILLET @ 2025-07-19 13:00 UTC (permalink / raw)
  To: zhang.enpei, horia.geanta
  Cc: pankaj.gupta, gaurav.jain, herbert, davem, linux-crypto, linux-kernel

Le 19/07/2025 à 10:34, zhang.enpei@zte.com.cn a écrit :
> From: Zhang Enpei <zhang.enpei@zte.com.cn>
> Use devm_kmemdup_array() to avoid multiplication or possible overflows.
> 
> Signed-off-by: Zhang Enpei <zhang.enpei@zte.com.cn>
> ---
>   drivers/crypto/caam/ctrl.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
> index ce7b99019537..2250dce9c344 100644
> --- a/drivers/crypto/caam/ctrl.c
> +++ b/drivers/crypto/caam/ctrl.c
> @@ -592,9 +592,9 @@ static int init_clocks(struct device *dev, const struct caam_imx_data *data)
>          int ret;
> 
>          ctrlpriv->num_clks = data->num_clks;
> -       ctrlpriv->clks = devm_kmemdup(dev, data->clks,
> -                                     data->num_clks * sizeof(data->clks[0]),
> -                                     GFP_KERNEL);
> +       ctrlpriv->clks = devm_kmemdup_array(dev, data->clks,
> +                                           data->num_clks, sizeof(data->clks[0]),

sizeof(*data->clks) maybe?

> +                                           GFP_KERNEL);
>          if (!ctrlpriv->clks)
>                  return -ENOMEM;
> 

Just my 2c,

CJ

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] crypto: caam - switch to use devm_kmemdup_array()
  2025-07-19 13:00 ` Christophe JAILLET
@ 2025-07-21  2:06   ` zhang.enpei
  2025-07-22 17:03     ` Christophe JAILLET
  0 siblings, 1 reply; 4+ messages in thread
From: zhang.enpei @ 2025-07-21  2:06 UTC (permalink / raw)
  To: christophe.jaillet
  Cc: horia.geanta, pankaj.gupta, gaurav.jain, herbert, davem,
	linux-crypto, linux-kernel

Thanks for the review!
devm_kmemdup_array() will call size_mul() to combine its third and fourth parameters into
length for devm_kmemdup(). So keep the same value sizeof(data->clks[0]) here as before.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] crypto: caam - switch to use devm_kmemdup_array()
  2025-07-21  2:06   ` zhang.enpei
@ 2025-07-22 17:03     ` Christophe JAILLET
  0 siblings, 0 replies; 4+ messages in thread
From: Christophe JAILLET @ 2025-07-22 17:03 UTC (permalink / raw)
  To: zhang.enpei
  Cc: horia.geanta, pankaj.gupta, gaurav.jain, herbert, davem,
	linux-crypto, linux-kernel

Le 21/07/2025 à 04:06, zhang.enpei@zte.com.cn a écrit :
> Thanks for the review!
> devm_kmemdup_array() will call size_mul() to combine its third and fourth parameters into
> length for devm_kmemdup(). So keep the same value sizeof(data->clks[0]) here as before.
> 
> 

sizeof(data->clks[0]) and sizeof(*data->clks) are the same.

But the second version is the preferred style. See [1].

So while touching these lines of code, updating the style looked a good 
idea to me.

CJ


[1]: 
https://docs.kernel.org/6.15/process/coding-style.html#allocating-memory

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-07-22 17:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-19  8:34 [PATCH] crypto: caam - switch to use devm_kmemdup_array() zhang.enpei
2025-07-19 13:00 ` Christophe JAILLET
2025-07-21  2:06   ` zhang.enpei
2025-07-22 17:03     ` Christophe JAILLET

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®