diff mbox series

[v1,13/13] ntb: idt: use devm_kmemdup_array()

Message ID 20250221165333.2780888-14-raag.jadav@intel.com (mailing list archive)
State New
Headers show
Series Convert to use devm_kmemdup_array() | expand

Commit Message

Raag Jadav Feb. 21, 2025, 4:53 p.m. UTC
Convert to use devm_kmemdup_array() which is more robust.

Signed-off-by: Raag Jadav <raag.jadav@intel.com>
---
 drivers/ntb/hw/idt/ntb_hw_idt.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

Comments

Dave Jiang Feb. 21, 2025, 5:05 p.m. UTC | #1
On 2/21/25 9:53 AM, Raag Jadav wrote:
> Convert to use devm_kmemdup_array() which is more robust.
> 
> Signed-off-by: Raag Jadav <raag.jadav@intel.com>

I think this patch [1] from earlier today makes this change unnecessary now.

[1]: https://lore.kernel.org/ntb/20250221085748.2298463-1-arnd@kernel.org/

> ---
>  drivers/ntb/hw/idt/ntb_hw_idt.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/ntb/hw/idt/ntb_hw_idt.c b/drivers/ntb/hw/idt/ntb_hw_idt.c
> index 544d8a4d2af5..dbfc53d0ef0c 100644
> --- a/drivers/ntb/hw/idt/ntb_hw_idt.c
> +++ b/drivers/ntb/hw/idt/ntb_hw_idt.c
> @@ -1103,16 +1103,11 @@ static struct idt_mw_cfg *idt_scan_mws(struct idt_ntb_dev *ndev, int port,
>  		}
>  	}
>  
> -	/* Allocate memory for memory window descriptors */
> -	ret_mws = devm_kcalloc(&ndev->ntb.pdev->dev, *mw_cnt, sizeof(*ret_mws),
> -			       GFP_KERNEL);
> -	if (!ret_mws)
> -		return ERR_PTR(-ENOMEM);
> -
>  	/* Copy the info of detected memory windows */
> -	memcpy(ret_mws, mws, (*mw_cnt)*sizeof(*ret_mws));
> +	ret_mws = devm_kmemdup_array(&ndev->ntb.pdev->dev, mws, *mw_cnt,
> +				     sizeof(mws[0]), GFP_KERNEL);
>  
> -	return ret_mws;
> +	return ret_mws ?: ERR_PTR(-ENOMEM);
>  }
>  
>  /*
Raag Jadav Feb. 22, 2025, 9:27 a.m. UTC | #2
Cc: Arnd

On Fri, Feb 21, 2025 at 10:05:09AM -0700, Dave Jiang wrote:
> On 2/21/25 9:53 AM, Raag Jadav wrote:
> > Convert to use devm_kmemdup_array() which is more robust.
> > 
> > Signed-off-by: Raag Jadav <raag.jadav@intel.com>
> 
> I think this patch [1] from earlier today makes this change unnecessary now.
> 
> [1]: https://lore.kernel.org/ntb/20250221085748.2298463-1-arnd@kernel.org/

Sure, in that case we can drop this one. Thanks for noticing.

Raag

> > ---
> >  drivers/ntb/hw/idt/ntb_hw_idt.c | 11 +++--------
> >  1 file changed, 3 insertions(+), 8 deletions(-)
> > 
> > diff --git a/drivers/ntb/hw/idt/ntb_hw_idt.c b/drivers/ntb/hw/idt/ntb_hw_idt.c
> > index 544d8a4d2af5..dbfc53d0ef0c 100644
> > --- a/drivers/ntb/hw/idt/ntb_hw_idt.c
> > +++ b/drivers/ntb/hw/idt/ntb_hw_idt.c
> > @@ -1103,16 +1103,11 @@ static struct idt_mw_cfg *idt_scan_mws(struct idt_ntb_dev *ndev, int port,
> >  		}
> >  	}
> >  
> > -	/* Allocate memory for memory window descriptors */
> > -	ret_mws = devm_kcalloc(&ndev->ntb.pdev->dev, *mw_cnt, sizeof(*ret_mws),
> > -			       GFP_KERNEL);
> > -	if (!ret_mws)
> > -		return ERR_PTR(-ENOMEM);
> > -
> >  	/* Copy the info of detected memory windows */
> > -	memcpy(ret_mws, mws, (*mw_cnt)*sizeof(*ret_mws));
> > +	ret_mws = devm_kmemdup_array(&ndev->ntb.pdev->dev, mws, *mw_cnt,
> > +				     sizeof(mws[0]), GFP_KERNEL);
> >  
> > -	return ret_mws;
> > +	return ret_mws ?: ERR_PTR(-ENOMEM);
> >  }
> >  
> >  /*
>
diff mbox series

Patch

diff --git a/drivers/ntb/hw/idt/ntb_hw_idt.c b/drivers/ntb/hw/idt/ntb_hw_idt.c
index 544d8a4d2af5..dbfc53d0ef0c 100644
--- a/drivers/ntb/hw/idt/ntb_hw_idt.c
+++ b/drivers/ntb/hw/idt/ntb_hw_idt.c
@@ -1103,16 +1103,11 @@  static struct idt_mw_cfg *idt_scan_mws(struct idt_ntb_dev *ndev, int port,
 		}
 	}
 
-	/* Allocate memory for memory window descriptors */
-	ret_mws = devm_kcalloc(&ndev->ntb.pdev->dev, *mw_cnt, sizeof(*ret_mws),
-			       GFP_KERNEL);
-	if (!ret_mws)
-		return ERR_PTR(-ENOMEM);
-
 	/* Copy the info of detected memory windows */
-	memcpy(ret_mws, mws, (*mw_cnt)*sizeof(*ret_mws));
+	ret_mws = devm_kmemdup_array(&ndev->ntb.pdev->dev, mws, *mw_cnt,
+				     sizeof(mws[0]), GFP_KERNEL);
 
-	return ret_mws;
+	return ret_mws ?: ERR_PTR(-ENOMEM);
 }
 
 /*