diff mbox series

[v1,1/1] ARM: omap2: Switch to use kmemdup_array()

Message ID 20240606165104.3031737-1-andriy.shevchenko@linux.intel.com (mailing list archive)
State New
Headers show
Series [v1,1/1] ARM: omap2: Switch to use kmemdup_array() | expand

Commit Message

Andy Shevchenko June 6, 2024, 4:51 p.m. UTC
Let the kememdup_array() take care about multiplication and possible
overflows.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 arch/arm/mach-omap2/omap_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Aaro Koskinen June 6, 2024, 7:32 p.m. UTC | #1
Hi,

On Thu, Jun 06, 2024 at 07:51:04PM +0300, Andy Shevchenko wrote:
> Let the kememdup_array() take care about multiplication and possible

          ^^^^^
          Typo.

> overflows.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  arch/arm/mach-omap2/omap_device.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
> index fca7869c8075..800980057373 100644
> --- a/arch/arm/mach-omap2/omap_device.c
> +++ b/arch/arm/mach-omap2/omap_device.c
> @@ -315,7 +315,7 @@ static struct omap_device *omap_device_alloc(struct platform_device *pdev,
>  
>  	od->hwmods_cnt = oh_cnt;
>  
> -	hwmods = kmemdup(ohs, sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
> +	hwmods = kmemdup_array(ohs, oh_cnt, sizeof(*hwmods), GFP_KERNEL);

Maybe same result, but I guess the 3rd parameter should be count?

A.
Andy Shevchenko June 6, 2024, 7:43 p.m. UTC | #2
On Thu, Jun 06, 2024 at 10:32:02PM +0300, Aaro Koskinen wrote:
> On Thu, Jun 06, 2024 at 07:51:04PM +0300, Andy Shevchenko wrote:
> > Let the kememdup_array() take care about multiplication and possible
> 
>           ^^^^^
>           Typo.

Aha, thanks!

> > overflows.

...

> > -	hwmods = kmemdup(ohs, sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
> > +	hwmods = kmemdup_array(ohs, oh_cnt, sizeof(*hwmods), GFP_KERNEL);
> 
> Maybe same result, but I guess the 3rd parameter should be count?

Actually it is going to be changed to follow kcalloc().
https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?id=0ee14725471c
Aaro Koskinen June 6, 2024, 7:47 p.m. UTC | #3
On Thu, Jun 06, 2024 at 10:43:07PM +0300, Andy Shevchenko wrote:
> On Thu, Jun 06, 2024 at 10:32:02PM +0300, Aaro Koskinen wrote:
> > On Thu, Jun 06, 2024 at 07:51:04PM +0300, Andy Shevchenko wrote:
> > > Let the kememdup_array() take care about multiplication and possible
> > 
> >           ^^^^^
> >           Typo.
> 
> Aha, thanks!
> 
> > > overflows.
> 
> ...
> 
> > > -	hwmods = kmemdup(ohs, sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
> > > +	hwmods = kmemdup_array(ohs, oh_cnt, sizeof(*hwmods), GFP_KERNEL);
> > 
> > Maybe same result, but I guess the 3rd parameter should be count?
> 
> Actually it is going to be changed to follow kcalloc().
> https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?id=0ee14725471c

OK, good, you can add:

Reviewed-by: Aaro Koskinen <aaro.koskinen@iki.fi>

A.
diff mbox series

Patch

diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
index fca7869c8075..800980057373 100644
--- a/arch/arm/mach-omap2/omap_device.c
+++ b/arch/arm/mach-omap2/omap_device.c
@@ -315,7 +315,7 @@  static struct omap_device *omap_device_alloc(struct platform_device *pdev,
 
 	od->hwmods_cnt = oh_cnt;
 
-	hwmods = kmemdup(ohs, sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
+	hwmods = kmemdup_array(ohs, oh_cnt, sizeof(*hwmods), GFP_KERNEL);
 	if (!hwmods)
 		goto oda_exit2;