Browse Source

USB: host: Use zeroing memory allocator rather than allocator/memset

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>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Acked-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Himanshu Jha 7 years ago
parent
commit
2b80a29bf8
2 changed files with 3 additions and 7 deletions
  1. 1 2
      drivers/usb/host/uhci-hcd.c
  2. 2 5
      drivers/usb/host/xhci-mem.c

+ 1 - 2
drivers/usb/host/uhci-hcd.c

@@ -600,7 +600,7 @@ static int uhci_start(struct usb_hcd *hcd)
 	uhci->dentry = dentry;
 	uhci->dentry = dentry;
 #endif
 #endif
 
 
-	uhci->frame = dma_alloc_coherent(uhci_dev(uhci),
+	uhci->frame = dma_zalloc_coherent(uhci_dev(uhci),
 			UHCI_NUMFRAMES * sizeof(*uhci->frame),
 			UHCI_NUMFRAMES * sizeof(*uhci->frame),
 			&uhci->frame_dma_handle, GFP_KERNEL);
 			&uhci->frame_dma_handle, GFP_KERNEL);
 	if (!uhci->frame) {
 	if (!uhci->frame) {
@@ -608,7 +608,6 @@ static int uhci_start(struct usb_hcd *hcd)
 			"unable to allocate consistent memory for frame list\n");
 			"unable to allocate consistent memory for frame list\n");
 		goto err_alloc_frame;
 		goto err_alloc_frame;
 	}
 	}
-	memset(uhci->frame, 0, UHCI_NUMFRAMES * sizeof(*uhci->frame));
 
 
 	uhci->frame_cpu = kcalloc(UHCI_NUMFRAMES, sizeof(*uhci->frame_cpu),
 	uhci->frame_cpu = kcalloc(UHCI_NUMFRAMES, sizeof(*uhci->frame_cpu),
 			GFP_KERNEL);
 			GFP_KERNEL);

+ 2 - 5
drivers/usb/host/xhci-mem.c

@@ -1782,14 +1782,11 @@ int xhci_alloc_erst(struct xhci_hcd *xhci,
 	struct xhci_erst_entry *entry;
 	struct xhci_erst_entry *entry;
 
 
 	size = sizeof(struct xhci_erst_entry) * evt_ring->num_segs;
 	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)
 	if (!erst->entries)
 		return -ENOMEM;
 		return -ENOMEM;
 
 
-	memset(erst->entries, 0, size);
 	erst->num_entries = evt_ring->num_segs;
 	erst->num_entries = evt_ring->num_segs;
 
 
 	seg = evt_ring->first_seg;
 	seg = evt_ring->first_seg;