linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] pinctrl: nomadik: Use kmemdup_array instead of kmemdup for multiple allocation
@ 2024-08-21  6:49 Yu Jiaoliang
  2024-08-23 15:27 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Yu Jiaoliang @ 2024-08-21  6:49 UTC (permalink / raw)
  To: Linus Walleij, linux-arm-kernel, linux-gpio, linux-kernel
  Cc: opensource.kernel

Let the kememdup_array() take care about multiplication and possible
overflows.

Signed-off-by: Yu Jiaoliang <yujiaoliang@vivo.com>
---
 drivers/pinctrl/nomadik/pinctrl-abx500.c  | 4 ++--
 drivers/pinctrl/nomadik/pinctrl-nomadik.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/pinctrl/nomadik/pinctrl-abx500.c b/drivers/pinctrl/nomadik/pinctrl-abx500.c
index 47f62c89955a..586ed303916e 100644
--- a/drivers/pinctrl/nomadik/pinctrl-abx500.c
+++ b/drivers/pinctrl/nomadik/pinctrl-abx500.c
@@ -716,8 +716,8 @@ static int abx500_dt_add_map_configs(struct pinctrl_map **map,
 	if (*num_maps == *reserved_maps)
 		return -ENOSPC;
 
-	dup_configs = kmemdup(configs, num_configs * sizeof(*dup_configs),
-			      GFP_KERNEL);
+	dup_configs = kmemdup_array(configs, num_configs, sizeof(*dup_configs),
+				    GFP_KERNEL);
 	if (!dup_configs)
 		return -ENOMEM;
 
diff --git a/drivers/pinctrl/nomadik/pinctrl-nomadik.c b/drivers/pinctrl/nomadik/pinctrl-nomadik.c
index fa78d5ecc685..800eba550cfd 100644
--- a/drivers/pinctrl/nomadik/pinctrl-nomadik.c
+++ b/drivers/pinctrl/nomadik/pinctrl-nomadik.c
@@ -601,8 +601,8 @@ static int nmk_dt_add_map_configs(struct pinctrl_map **map,
 	if (*num_maps == *reserved_maps)
 		return -ENOSPC;
 
-	dup_configs = kmemdup(configs, num_configs * sizeof(*dup_configs),
-			      GFP_KERNEL);
+	dup_configs = kmemdup_array(configs, num_configs, sizeof(*dup_configs),
+				    GFP_KERNEL);
 	if (!dup_configs)
 		return -ENOMEM;
 
-- 
2.34.1


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

* Re: [PATCH v1] pinctrl: nomadik: Use kmemdup_array instead of kmemdup for multiple allocation
  2024-08-21  6:49 [PATCH v1] pinctrl: nomadik: Use kmemdup_array instead of kmemdup for multiple allocation Yu Jiaoliang
@ 2024-08-23 15:27 ` Andy Shevchenko
  2024-08-26  7:42   ` 于佼良
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2024-08-23 15:27 UTC (permalink / raw)
  To: Yu Jiaoliang
  Cc: Linus Walleij, linux-arm-kernel, linux-gpio, linux-kernel,
	opensource.kernel

On Wed, Aug 21, 2024 at 02:49:58PM +0800, Yu Jiaoliang wrote:
> Let the kememdup_array() take care about multiplication and possible

kmemdup_array()

> overflows.

...

> +	dup_configs = kmemdup_array(configs, num_configs, sizeof(*dup_configs),
> +				    GFP_KERNEL);

I would even make this a single line.

...

> +	dup_configs = kmemdup_array(configs, num_configs, sizeof(*dup_configs),
> +				    GFP_KERNEL);


Ditto.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v1] pinctrl: nomadik: Use kmemdup_array instead of kmemdup for multiple allocation
  2024-08-23 15:27 ` Andy Shevchenko
@ 2024-08-26  7:42   ` 于佼良
  0 siblings, 0 replies; 3+ messages in thread
From: 于佼良 @ 2024-08-26  7:42 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Linus Walleij, linux-arm-kernel@lists.infradead.org,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	opensource.kernel

在 2024/8/23 23:27, Andy Shevchenko 写道:
> [Some people who received this message don't often get email from andriy.shevchenko@intel.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> On Wed, Aug 21, 2024 at 02:49:58PM +0800, Yu Jiaoliang wrote:
>> Let the kememdup_array() take care about multiplication and possible
> kmemdup_array()
>
>> overflows.
> ...
>
>> +     dup_configs = kmemdup_array(configs, num_configs, sizeof(*dup_configs),
>> +                                 GFP_KERNEL);
> I would even make this a single line.
>
> ...
>
>> +     dup_configs = kmemdup_array(configs, num_configs, sizeof(*dup_configs),
>> +                                 GFP_KERNEL);
>
> Ditto.
>
> --
> With Best Regards,
> Andy Shevchenko
>
>
Hi Andy,

I have reformatted the code and submitted patch v2. Thank you.

Best Regards,

Yu


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

end of thread, other threads:[~2024-08-26  7:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-21  6:49 [PATCH v1] pinctrl: nomadik: Use kmemdup_array instead of kmemdup for multiple allocation Yu Jiaoliang
2024-08-23 15:27 ` Andy Shevchenko
2024-08-26  7:42   ` 于佼良

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).