mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] USB: host: Use zeroing memory allocator rather than allocator/memset
@ 2017-12-30 15:42 Himanshu Jha
  2017-12-30 16:41 ` Alan Stern
  0 siblings, 1 reply; 4+ messages in thread
From: Himanshu Jha @ 2017-12-30 15:42 UTC (permalink / raw)
  To: gregkh
  Cc: stern, mathias.nyman, linux-usb, linux-kernel, mcgrof, Himanshu Jha

Use dma_zalloc_coherent for allocating zeroed
memory and remove unnecessary memset function.

Done using Coccinelle.
Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
0-day tested with no failures.

Suggested-by: Luis R. Rodriguez <mcgrof@kernel.org>
Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
---
 drivers/usb/host/uhci-hcd.c | 7 +++----
 drivers/usb/host/xhci-mem.c | 7 ++-----
 2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index f5c9021..ac53398 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -600,15 +600,14 @@ static int uhci_start(struct usb_hcd *hcd)
 	uhci->dentry = dentry;
 #endif
 
-	uhci->frame = dma_alloc_coherent(uhci_dev(uhci),
-			UHCI_NUMFRAMES * sizeof(*uhci->frame),
-			&uhci->frame_dma_handle, GFP_KERNEL);
+	uhci->frame = dma_zalloc_coherent(uhci_dev(uhci),
+					  UHCI_NUMFRAMES * sizeof(*uhci->frame),
+					  &uhci->frame_dma_handle, GFP_KERNEL);
 	if (!uhci->frame) {
 		dev_err(uhci_dev(uhci),
 			"unable to allocate consistent memory for frame list\n");
 		goto err_alloc_frame;
 	}
-	memset(uhci->frame, 0, UHCI_NUMFRAMES * sizeof(*uhci->frame));
 
 	uhci->frame_cpu = kcalloc(UHCI_NUMFRAMES, sizeof(*uhci->frame_cpu),
 			GFP_KERNEL);
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 554a8a5..332420d 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1782,14 +1782,11 @@ int xhci_alloc_erst(struct xhci_hcd *xhci,
 	struct xhci_erst_entry *entry;
 
 	size = sizeof(struct xhci_erst_entry) * evt_ring->num_segs;
-	erst->entries = dma_alloc_coherent(xhci_to_hcd(xhci)->self.sysdev,
-					   size,
-					   &erst->erst_dma_addr,
-					   flags);
+	erst->entries = dma_zalloc_coherent(xhci_to_hcd(xhci)->self.sysdev,
+					    size, &erst->erst_dma_addr, flags);
 	if (!erst->entries)
 		return -ENOMEM;
 
-	memset(erst->entries, 0, size);
 	erst->num_entries = evt_ring->num_segs;
 
 	seg = evt_ring->first_seg;
-- 
2.7.4

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

* Re: [PATCH] USB: host: Use zeroing memory allocator rather than allocator/memset
  2017-12-30 15:42 [PATCH] USB: host: Use zeroing memory allocator rather than allocator/memset Himanshu Jha
@ 2017-12-30 16:41 ` Alan Stern
  2017-12-30 18:25   ` Himanshu Jha
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Stern @ 2017-12-30 16:41 UTC (permalink / raw)
  To: Himanshu Jha; +Cc: gregkh, mathias.nyman, linux-usb, linux-kernel, mcgrof

On Sat, 30 Dec 2017, Himanshu Jha wrote:

> Use dma_zalloc_coherent for allocating zeroed
> memory and remove unnecessary memset function.
> 
> Done using Coccinelle.
> Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
> 0-day tested with no failures.
> 
> Suggested-by: Luis R. Rodriguez <mcgrof@kernel.org>
> Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
> ---
>  drivers/usb/host/uhci-hcd.c | 7 +++----
>  drivers/usb/host/xhci-mem.c | 7 ++-----
>  2 files changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
> index f5c9021..ac53398 100644
> --- a/drivers/usb/host/uhci-hcd.c
> +++ b/drivers/usb/host/uhci-hcd.c
> @@ -600,15 +600,14 @@ static int uhci_start(struct usb_hcd *hcd)
>  	uhci->dentry = dentry;
>  #endif
>  
> -	uhci->frame = dma_alloc_coherent(uhci_dev(uhci),
> -			UHCI_NUMFRAMES * sizeof(*uhci->frame),
> -			&uhci->frame_dma_handle, GFP_KERNEL);
> +	uhci->frame = dma_zalloc_coherent(uhci_dev(uhci),
> +					  UHCI_NUMFRAMES * sizeof(*uhci->frame),
> +					  &uhci->frame_dma_handle, GFP_KERNEL);

Please don't change the existing whitespace scheme when you make 
changes like this one.

Alan Stern

>  	if (!uhci->frame) {
>  		dev_err(uhci_dev(uhci),
>  			"unable to allocate consistent memory for frame list\n");
>  		goto err_alloc_frame;
>  	}
> -	memset(uhci->frame, 0, UHCI_NUMFRAMES * sizeof(*uhci->frame));
>  
>  	uhci->frame_cpu = kcalloc(UHCI_NUMFRAMES, sizeof(*uhci->frame_cpu),
>  			GFP_KERNEL);
> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
> index 554a8a5..332420d 100644
> --- a/drivers/usb/host/xhci-mem.c
> +++ b/drivers/usb/host/xhci-mem.c
> @@ -1782,14 +1782,11 @@ int xhci_alloc_erst(struct xhci_hcd *xhci,
>  	struct xhci_erst_entry *entry;
>  
>  	size = sizeof(struct xhci_erst_entry) * evt_ring->num_segs;
> -	erst->entries = dma_alloc_coherent(xhci_to_hcd(xhci)->self.sysdev,
> -					   size,
> -					   &erst->erst_dma_addr,
> -					   flags);
> +	erst->entries = dma_zalloc_coherent(xhci_to_hcd(xhci)->self.sysdev,
> +					    size, &erst->erst_dma_addr, flags);
>  	if (!erst->entries)
>  		return -ENOMEM;
>  
> -	memset(erst->entries, 0, size);
>  	erst->num_entries = evt_ring->num_segs;
>  
>  	seg = evt_ring->first_seg;
> 

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

* Re: [PATCH] USB: host: Use zeroing memory allocator rather than allocator/memset
  2017-12-30 16:41 ` Alan Stern
@ 2017-12-30 18:25   ` Himanshu Jha
  2017-12-30 19:26     ` Alan Stern
  0 siblings, 1 reply; 4+ messages in thread
From: Himanshu Jha @ 2017-12-30 18:25 UTC (permalink / raw)
  To: Alan Stern; +Cc: gregkh, mathias.nyman, linux-usb, linux-kernel, mcgrof

On Sat, Dec 30, 2017 at 11:41:19AM -0500, Alan Stern wrote:
> On Sat, 30 Dec 2017, Himanshu Jha wrote:
> 
> > Use dma_zalloc_coherent for allocating zeroed
> > memory and remove unnecessary memset function.
> > 
> > Done using Coccinelle.
> > Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
> > 0-day tested with no failures.
> > 
> > Suggested-by: Luis R. Rodriguez <mcgrof@kernel.org>
> > Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
> > ---
> >  drivers/usb/host/uhci-hcd.c | 7 +++----
> >  drivers/usb/host/xhci-mem.c | 7 ++-----
> >  2 files changed, 5 insertions(+), 9 deletions(-)
> > 
> > diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
> > index f5c9021..ac53398 100644
> > --- a/drivers/usb/host/uhci-hcd.c
> > +++ b/drivers/usb/host/uhci-hcd.c
> > @@ -600,15 +600,14 @@ static int uhci_start(struct usb_hcd *hcd)
> >  	uhci->dentry = dentry;
> >  #endif
> >  
> > -	uhci->frame = dma_alloc_coherent(uhci_dev(uhci),
> > -			UHCI_NUMFRAMES * sizeof(*uhci->frame),
> > -			&uhci->frame_dma_handle, GFP_KERNEL);
> > +	uhci->frame = dma_zalloc_coherent(uhci_dev(uhci),
> > +					  UHCI_NUMFRAMES * sizeof(*uhci->frame),
> > +					  &uhci->frame_dma_handle, GFP_KERNEL);
> 
> Please don't change the existing whitespace scheme when you make 
> changes like this one.

Thanks for the feedback!
Do I need to send v2 for this ?

Thanks
Himanshu Jha

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

* Re: [PATCH] USB: host: Use zeroing memory allocator rather than allocator/memset
  2017-12-30 18:25   ` Himanshu Jha
@ 2017-12-30 19:26     ` Alan Stern
  0 siblings, 0 replies; 4+ messages in thread
From: Alan Stern @ 2017-12-30 19:26 UTC (permalink / raw)
  To: Himanshu Jha; +Cc: gregkh, mathias.nyman, linux-usb, linux-kernel, mcgrof

On Sat, 30 Dec 2017, Himanshu Jha wrote:

> On Sat, Dec 30, 2017 at 11:41:19AM -0500, Alan Stern wrote:
> > On Sat, 30 Dec 2017, Himanshu Jha wrote:
> > 
> > > Use dma_zalloc_coherent for allocating zeroed
> > > memory and remove unnecessary memset function.
> > > 
> > > Done using Coccinelle.
> > > Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
> > > 0-day tested with no failures.
> > > 
> > > Suggested-by: Luis R. Rodriguez <mcgrof@kernel.org>
> > > Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
> > > ---
> > >  drivers/usb/host/uhci-hcd.c | 7 +++----
> > >  drivers/usb/host/xhci-mem.c | 7 ++-----
> > >  2 files changed, 5 insertions(+), 9 deletions(-)
> > > 
> > > diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
> > > index f5c9021..ac53398 100644
> > > --- a/drivers/usb/host/uhci-hcd.c
> > > +++ b/drivers/usb/host/uhci-hcd.c
> > > @@ -600,15 +600,14 @@ static int uhci_start(struct usb_hcd *hcd)
> > >  	uhci->dentry = dentry;
> > >  #endif
> > >  
> > > -	uhci->frame = dma_alloc_coherent(uhci_dev(uhci),
> > > -			UHCI_NUMFRAMES * sizeof(*uhci->frame),
> > > -			&uhci->frame_dma_handle, GFP_KERNEL);
> > > +	uhci->frame = dma_zalloc_coherent(uhci_dev(uhci),
> > > +					  UHCI_NUMFRAMES * sizeof(*uhci->frame),
> > > +					  &uhci->frame_dma_handle, GFP_KERNEL);
> > 
> > Please don't change the existing whitespace scheme when you make 
> > changes like this one.
> 
> Thanks for the feedback!
> Do I need to send v2 for this ?

Okay, yes, go ahead.

Alan Stern

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

end of thread, other threads:[~2017-12-30 19:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-30 15:42 [PATCH] USB: host: Use zeroing memory allocator rather than allocator/memset Himanshu Jha
2017-12-30 16:41 ` Alan Stern
2017-12-30 18:25   ` Himanshu Jha
2017-12-30 19:26     ` Alan Stern

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®