diff mbox series

[v1,2/7] xhci: mem: Use __GFP_ZERO instead of explicit memset() call

Message ID 20230206161049.13972-3-andriy.shevchenko@linux.intel.com (mailing list archive)
State Superseded
Headers show
Series xhci: mem: Short cleanup series | expand

Commit Message

Andy Shevchenko Feb. 6, 2023, 4:10 p.m. UTC
Use __GFP_ZERO instead of explicit memset() call in
xhci_alloc_stream_ctx().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/host/xhci-mem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Mathias Nyman Feb. 7, 2023, 3:11 p.m. UTC | #1
On 6.2.2023 18.10, Andy Shevchenko wrote:
> Use __GFP_ZERO instead of explicit memset() call in
> xhci_alloc_stream_ctx().
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>   drivers/usb/host/xhci-mem.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
> index c385513ad00b..768adcb544a7 100644
> --- a/drivers/usb/host/xhci-mem.c
> +++ b/drivers/usb/host/xhci-mem.c
> @@ -571,6 +571,8 @@ static struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci,
>   	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
>   	size_t size = size_mul(sizeof(struct xhci_stream_ctx), num_stream_ctxs);
>   
> +	mem_flags |= __GFP_ZERO;
> +

How about calling dma_pool_zalloc() instead of setting __GFP_ZERO flag?
Memory returned by dma_alloc_coherent() should already be zeroed if I remember correctly

-Mathias
Andy Shevchenko Feb. 7, 2023, 10:49 p.m. UTC | #2
On Tue, Feb 07, 2023 at 05:11:23PM +0200, Mathias Nyman wrote:
> On 6.2.2023 18.10, Andy Shevchenko wrote:
> > Use __GFP_ZERO instead of explicit memset() call in
> > xhci_alloc_stream_ctx().

...

> > +	mem_flags |= __GFP_ZERO;
> 
> How about calling dma_pool_zalloc() instead of setting __GFP_ZERO flag?
> Memory returned by dma_alloc_coherent() should already be zeroed if I remember correctly

That will work too.
diff mbox series

Patch

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index c385513ad00b..768adcb544a7 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -571,6 +571,8 @@  static struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci,
 	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
 	size_t size = size_mul(sizeof(struct xhci_stream_ctx), num_stream_ctxs);
 
+	mem_flags |= __GFP_ZERO;
+
 	if (size > MEDIUM_STREAM_ARRAY_SIZE)
 		return dma_alloc_coherent(dev, size,
 				dma, mem_flags);
@@ -643,8 +645,6 @@  struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci,
 			mem_flags);
 	if (!stream_info->stream_ctx_array)
 		goto cleanup_ring_array;
-	memset(stream_info->stream_ctx_array, 0,
-			sizeof(struct xhci_stream_ctx)*num_stream_ctxs);
 
 	/* Allocate everything needed to free the stream rings later */
 	stream_info->free_streams_command =