linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [v2] USB: host: Use zeroing memory allocator rather than allocator/memset
@ 2017-12-30 20:03 Himanshu Jha
  0 siblings, 0 replies; 6+ messages in thread
From: Himanshu Jha @ 2017-12-30 20:03 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>
---
v2:
   -align argumenst as they were before applying the SmPL rule.

 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;

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

* [v2] USB: host: Use zeroing memory allocator rather than allocator/memset
@ 2017-12-31 21:20 Alan Stern
  0 siblings, 0 replies; 6+ messages in thread
From: Alan Stern @ 2017-12-31 21:20 UTC (permalink / raw)
  To: Himanshu Jha; +Cc: gregkh, mathias.nyman, linux-usb, linux-kernel, mcgrof

On Sun, 31 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>
> ---
> v2:
>    -align argumenst as they were before applying the SmPL rule.

For the UHCI portion:

Acked-by: Alan Stern <stern@rowland.harvard.edu>

But there is something pecular about the patch...

>  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);

The second and third "changed" lines here actually are identical.  What 
program would produce a diff file showing that they were changed?

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;
>
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [v2] USB: host: Use zeroing memory allocator rather than allocator/memset
@ 2018-01-01 13:51 Himanshu Jha
  0 siblings, 0 replies; 6+ messages in thread
From: Himanshu Jha @ 2018-01-01 13:51 UTC (permalink / raw)
  To: Alan Stern; +Cc: gregkh, mathias.nyman, linux-usb, linux-kernel, mcgrof

On Sun, Dec 31, 2017 at 04:20:45PM -0500, Alan Stern wrote:
> On Sun, 31 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>
> > ---
> > v2:
> >    -align argumenst as they were before applying the SmPL rule.
> 
> For the UHCI portion:
> 
> Acked-by: Alan Stern <stern@rowland.harvard.edu>
> 
> But there is something pecular about the patch...
> 
> >  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);
> 
> The second and third "changed" lines here actually are identical.  What 
> program would produce a diff file showing that they were changed?

I'm sorry, I can't understand the problem.
The patch was generated by cocci script specified above and then you
told me to change the whitespace scheme as it was before. It is also
0-day tested as specified above. It's also free from warnings reported by
checkpatch.

If are still confused please take a look at the rule :
https://lkml.org/lkml/2017/12/26/205
which will be soon merged to the linux-next tree.

Thanks
Himanshu Jha
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [v2] USB: host: Use zeroing memory allocator rather than allocator/memset
@ 2018-01-01 15:53 Alan Stern
  0 siblings, 0 replies; 6+ messages in thread
From: Alan Stern @ 2018-01-01 15:53 UTC (permalink / raw)
  To: Himanshu Jha; +Cc: gregkh, mathias.nyman, linux-usb, linux-kernel, mcgrof

On Mon, 1 Jan 2018, Himanshu Jha wrote:

> On Sun, Dec 31, 2017 at 04:20:45PM -0500, Alan Stern wrote:
> > On Sun, 31 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>
> > > ---
> > > v2:
> > >    -align argumenst as they were before applying the SmPL rule.
> > 
> > For the UHCI portion:
> > 
> > Acked-by: Alan Stern <stern@rowland.harvard.edu>
> > 
> > But there is something pecular about the patch...
> > 
> > >  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);
> > 
> > The second and third "changed" lines here actually are identical.  What 
> > program would produce a diff file showing that they were changed?
> 
> I'm sorry, I can't understand the problem.

There is no problem.  I merely asked a question.

> The patch was generated by cocci script specified above and then you
> told me to change the whitespace scheme as it was before.

Yes, I know.  But did you change the cocci script to make it produce
this new patch, or did you make the patch by manually editing the old
version?  In other words, how was this patch generated?

>  It is also
> 0-day tested as specified above. It's also free from warnings reported by
> checkpatch.

I never said there was anything wrong with the patch.  It's just
peculiar.  For example, you could never get diff (or git diff) to
produce that patch.

Alan Stern

> If are still confused please take a look at the rule :
> https://lkml.org/lkml/2017/12/26/205
> which will be soon merged to the linux-next tree.
> 
> Thanks
> Himanshu Jha
>
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [v2] USB: host: Use zeroing memory allocator rather than allocator/memset
@ 2018-01-01 15:59 Himanshu Jha
  0 siblings, 0 replies; 6+ messages in thread
From: Himanshu Jha @ 2018-01-01 15:59 UTC (permalink / raw)
  To: Alan Stern; +Cc: gregkh, mathias.nyman, linux-usb, linux-kernel, mcgrof

On Mon, Jan 01, 2018 at 10:53:07AM -0500, Alan Stern wrote:
> On Mon, 1 Jan 2018, Himanshu Jha wrote:
> 
> > On Sun, Dec 31, 2017 at 04:20:45PM -0500, Alan Stern wrote:
> > > On Sun, 31 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>
> > > > ---
> > > > v2:
> > > >    -align argumenst as they were before applying the SmPL rule.
> > > 
> > > For the UHCI portion:
> > > 
> > > Acked-by: Alan Stern <stern@rowland.harvard.edu>
> > > 
> > > But there is something pecular about the patch...
> > > 
> > > >  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);
> > > 
> > > The second and third "changed" lines here actually are identical.  What 
> > > program would produce a diff file showing that they were changed?
> > 
> > I'm sorry, I can't understand the problem.
> 
> There is no problem.  I merely asked a question.
> 
> > The patch was generated by cocci script specified above and then you
> > told me to change the whitespace scheme as it was before.
> 
> Yes, I know.  But did you change the cocci script to make it produce
> this new patch, or did you make the patch by manually editing the old
> version?  In other words, how was this patch generated?

I did that manually, no change in cocci script.

Thanks
Himanshu Jha
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [v2] USB: host: Use zeroing memory allocator rather than allocator/memset
@ 2018-01-02 10:13 Mathias Nyman
  0 siblings, 0 replies; 6+ messages in thread
From: Mathias Nyman @ 2018-01-02 10:13 UTC (permalink / raw)
  To: Himanshu Jha, gregkh
  Cc: stern, mathias.nyman, linux-usb, linux-kernel, mcgrof

On 30.12.2017 22:03, 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>
> ---
> v2:
>     -align argumenst as they were before applying the SmPL rule.
> 
>   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;

For the xhci part:
Acked-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2018-01-02 10:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-02 10:13 [v2] USB: host: Use zeroing memory allocator rather than allocator/memset Mathias Nyman
  -- strict thread matches above, loose matches on Subject: below --
2018-01-01 15:59 Himanshu Jha
2018-01-01 15:53 Alan Stern
2018-01-01 13:51 Himanshu Jha
2017-12-31 21:20 Alan Stern
2017-12-30 20:03 Himanshu Jha

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).