public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb : replace dma_pool_alloc and memset with dma_pool_zalloc
@ 2015-10-28  7:14 Saurabh Sengar
  2015-10-28  9:14 ` Peter Chen
  0 siblings, 1 reply; 3+ messages in thread
From: Saurabh Sengar @ 2015-10-28  7:14 UTC (permalink / raw)
  To: gregkh, linux-usb, linux-kernel; +Cc: Saurabh Sengar

replace dma_pool_alloc and memset with a single call to dma_pool_zalloc

Signed-off-by: Saurabh Sengar <saurabh.truth@gmail.com>
---
 drivers/usb/chipidea/udc.c      | 3 +--
 drivers/usb/gadget/udc/gr_udc.c | 3 +--
 drivers/usb/host/uhci-q.c       | 3 +--
 drivers/usb/host/whci/qset.c    | 3 +--
 drivers/usb/host/xhci-mem.c     | 6 ++----
 5 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index 8223fe7..235b948f 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -349,14 +349,13 @@ static int add_td_to_list(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq,
 	if (node == NULL)
 		return -ENOMEM;
 
-	node->ptr = dma_pool_alloc(hwep->td_pool, GFP_ATOMIC,
+	node->ptr = dma_pool_zalloc(hwep->td_pool, GFP_ATOMIC,
 				   &node->dma);
 	if (node->ptr == NULL) {
 		kfree(node);
 		return -ENOMEM;
 	}
 
-	memset(node->ptr, 0, sizeof(struct ci_hw_td));
 	node->ptr->token = cpu_to_le32(length << __ffs(TD_TOTAL_BYTES));
 	node->ptr->token &= cpu_to_le32(TD_TOTAL_BYTES);
 	node->ptr->token |= cpu_to_le32(TD_STATUS_ACTIVE);
diff --git a/drivers/usb/gadget/udc/gr_udc.c b/drivers/usb/gadget/udc/gr_udc.c
index b9429bc..39b7136 100644
--- a/drivers/usb/gadget/udc/gr_udc.c
+++ b/drivers/usb/gadget/udc/gr_udc.c
@@ -253,13 +253,12 @@ static struct gr_dma_desc *gr_alloc_dma_desc(struct gr_ep *ep, gfp_t gfp_flags)
 	dma_addr_t paddr;
 	struct gr_dma_desc *dma_desc;
 
-	dma_desc = dma_pool_alloc(ep->dev->desc_pool, gfp_flags, &paddr);
+	dma_desc = dma_pool_zalloc(ep->dev->desc_pool, gfp_flags, &paddr);
 	if (!dma_desc) {
 		dev_err(ep->dev->dev, "Could not allocate from DMA pool\n");
 		return NULL;
 	}
 
-	memset(dma_desc, 0, sizeof(*dma_desc));
 	dma_desc->paddr = paddr;
 
 	return dma_desc;
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index da6f56d..c17ea15 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -248,11 +248,10 @@ static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci,
 	dma_addr_t dma_handle;
 	struct uhci_qh *qh;
 
-	qh = dma_pool_alloc(uhci->qh_pool, GFP_ATOMIC, &dma_handle);
+	qh = dma_pool_zalloc(uhci->qh_pool, GFP_ATOMIC, &dma_handle);
 	if (!qh)
 		return NULL;
 
-	memset(qh, 0, sizeof(*qh));
 	qh->dma_handle = dma_handle;
 
 	qh->element = UHCI_PTR_TERM(uhci);
diff --git a/drivers/usb/host/whci/qset.c b/drivers/usb/host/whci/qset.c
index dc31c42..3297473 100644
--- a/drivers/usb/host/whci/qset.c
+++ b/drivers/usb/host/whci/qset.c
@@ -30,10 +30,9 @@ struct whc_qset *qset_alloc(struct whc *whc, gfp_t mem_flags)
 	struct whc_qset *qset;
 	dma_addr_t dma;
 
-	qset = dma_pool_alloc(whc->qset_pool, mem_flags, &dma);
+	qset = dma_pool_zalloc(whc->qset_pool, mem_flags, &dma);
 	if (qset == NULL)
 		return NULL;
-	memset(qset, 0, sizeof(struct whc_qset));
 
 	qset->qset_dma = dma;
 	qset->whc = whc;
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 41f841f..060c20c 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -47,13 +47,12 @@ static struct xhci_segment *xhci_segment_alloc(struct xhci_hcd *xhci,
 	if (!seg)
 		return NULL;
 
-	seg->trbs = dma_pool_alloc(xhci->segment_pool, flags, &dma);
+	seg->trbs = dma_pool_zalloc(xhci->segment_pool, flags, &dma);
 	if (!seg->trbs) {
 		kfree(seg);
 		return NULL;
 	}
 
-	memset(seg->trbs, 0, TRB_SEGMENT_SIZE);
 	/* If the cycle state is 0, set the cycle bit to 1 for all the TRBs */
 	if (cycle_state == 0) {
 		for (i = 0; i < TRBS_PER_SEGMENT; i++)
@@ -517,12 +516,11 @@ static struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci
 	if (type == XHCI_CTX_TYPE_INPUT)
 		ctx->size += CTX_SIZE(xhci->hcc_params);
 
-	ctx->bytes = dma_pool_alloc(xhci->device_pool, flags, &ctx->dma);
+	ctx->bytes = dma_pool_zalloc(xhci->device_pool, flags, &ctx->dma);
 	if (!ctx->bytes) {
 		kfree(ctx);
 		return NULL;
 	}
-	memset(ctx->bytes, 0, ctx->size);
 	return ctx;
 }
 
-- 
1.9.1


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

* Re: [PATCH] usb : replace dma_pool_alloc and memset with dma_pool_zalloc
  2015-10-28  7:14 [PATCH] usb : replace dma_pool_alloc and memset with dma_pool_zalloc Saurabh Sengar
@ 2015-10-28  9:14 ` Peter Chen
  2015-11-25  3:19   ` Saurabh Sengar
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Chen @ 2015-10-28  9:14 UTC (permalink / raw)
  To: Saurabh Sengar; +Cc: gregkh, linux-usb, linux-kernel

On Wed, Oct 28, 2015 at 12:44:35PM +0530, Saurabh Sengar wrote:
> replace dma_pool_alloc and memset with a single call to dma_pool_zalloc
> 
> Signed-off-by: Saurabh Sengar <saurabh.truth@gmail.com>
> ---
>  drivers/usb/chipidea/udc.c      | 3 +--
>  drivers/usb/gadget/udc/gr_udc.c | 3 +--
>  drivers/usb/host/uhci-q.c       | 3 +--
>  drivers/usb/host/whci/qset.c    | 3 +--
>  drivers/usb/host/xhci-mem.c     | 6 ++----
>  5 files changed, 6 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
> index 8223fe7..235b948f 100644
> --- a/drivers/usb/chipidea/udc.c
> +++ b/drivers/usb/chipidea/udc.c
> @@ -349,14 +349,13 @@ static int add_td_to_list(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq,
>  	if (node == NULL)
>  		return -ENOMEM;
>  
> -	node->ptr = dma_pool_alloc(hwep->td_pool, GFP_ATOMIC,
> +	node->ptr = dma_pool_zalloc(hwep->td_pool, GFP_ATOMIC,
>  				   &node->dma);
>  	if (node->ptr == NULL) {
>  		kfree(node);
>  		return -ENOMEM;
>  	}
>  
> -	memset(node->ptr, 0, sizeof(struct ci_hw_td));
>  	node->ptr->token = cpu_to_le32(length << __ffs(TD_TOTAL_BYTES));
>  	node->ptr->token &= cpu_to_le32(TD_TOTAL_BYTES);
>  	node->ptr->token |= cpu_to_le32(TD_STATUS_ACTIVE);
> diff --git a/drivers/usb/gadget/udc/gr_udc.c b/drivers/usb/gadget/udc/gr_udc.c
> index b9429bc..39b7136 100644
> --- a/drivers/usb/gadget/udc/gr_udc.c
> +++ b/drivers/usb/gadget/udc/gr_udc.c
> @@ -253,13 +253,12 @@ static struct gr_dma_desc *gr_alloc_dma_desc(struct gr_ep *ep, gfp_t gfp_flags)
>  	dma_addr_t paddr;
>  	struct gr_dma_desc *dma_desc;
>  
> -	dma_desc = dma_pool_alloc(ep->dev->desc_pool, gfp_flags, &paddr);
> +	dma_desc = dma_pool_zalloc(ep->dev->desc_pool, gfp_flags, &paddr);
>  	if (!dma_desc) {
>  		dev_err(ep->dev->dev, "Could not allocate from DMA pool\n");
>  		return NULL;
>  	}
>  
> -	memset(dma_desc, 0, sizeof(*dma_desc));
>  	dma_desc->paddr = paddr;
>  
>  	return dma_desc;
> diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
> index da6f56d..c17ea15 100644
> --- a/drivers/usb/host/uhci-q.c
> +++ b/drivers/usb/host/uhci-q.c
> @@ -248,11 +248,10 @@ static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci,
>  	dma_addr_t dma_handle;
>  	struct uhci_qh *qh;
>  
> -	qh = dma_pool_alloc(uhci->qh_pool, GFP_ATOMIC, &dma_handle);
> +	qh = dma_pool_zalloc(uhci->qh_pool, GFP_ATOMIC, &dma_handle);
>  	if (!qh)
>  		return NULL;
>  
> -	memset(qh, 0, sizeof(*qh));
>  	qh->dma_handle = dma_handle;
>  
>  	qh->element = UHCI_PTR_TERM(uhci);
> diff --git a/drivers/usb/host/whci/qset.c b/drivers/usb/host/whci/qset.c
> index dc31c42..3297473 100644
> --- a/drivers/usb/host/whci/qset.c
> +++ b/drivers/usb/host/whci/qset.c
> @@ -30,10 +30,9 @@ struct whc_qset *qset_alloc(struct whc *whc, gfp_t mem_flags)
>  	struct whc_qset *qset;
>  	dma_addr_t dma;
>  
> -	qset = dma_pool_alloc(whc->qset_pool, mem_flags, &dma);
> +	qset = dma_pool_zalloc(whc->qset_pool, mem_flags, &dma);
>  	if (qset == NULL)
>  		return NULL;
> -	memset(qset, 0, sizeof(struct whc_qset));
>  
>  	qset->qset_dma = dma;
>  	qset->whc = whc;
> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
> index 41f841f..060c20c 100644
> --- a/drivers/usb/host/xhci-mem.c
> +++ b/drivers/usb/host/xhci-mem.c
> @@ -47,13 +47,12 @@ static struct xhci_segment *xhci_segment_alloc(struct xhci_hcd *xhci,
>  	if (!seg)
>  		return NULL;
>  
> -	seg->trbs = dma_pool_alloc(xhci->segment_pool, flags, &dma);
> +	seg->trbs = dma_pool_zalloc(xhci->segment_pool, flags, &dma);
>  	if (!seg->trbs) {
>  		kfree(seg);
>  		return NULL;
>  	}
>  
> -	memset(seg->trbs, 0, TRB_SEGMENT_SIZE);
>  	/* If the cycle state is 0, set the cycle bit to 1 for all the TRBs */
>  	if (cycle_state == 0) {
>  		for (i = 0; i < TRBS_PER_SEGMENT; i++)
> @@ -517,12 +516,11 @@ static struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci
>  	if (type == XHCI_CTX_TYPE_INPUT)
>  		ctx->size += CTX_SIZE(xhci->hcc_params);
>  
> -	ctx->bytes = dma_pool_alloc(xhci->device_pool, flags, &ctx->dma);
> +	ctx->bytes = dma_pool_zalloc(xhci->device_pool, flags, &ctx->dma);
>  	if (!ctx->bytes) {
>  		kfree(ctx);
>  		return NULL;
>  	}
> -	memset(ctx->bytes, 0, ctx->size);
>  	return ctx;
>  }
>  
> -- 

For chipidea changes:
Acked-by: Peter Chen <peter.chen@freescale.com>

-- 

Best Regards,
Peter Chen

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

* Re: [PATCH] usb : replace dma_pool_alloc and memset with dma_pool_zalloc
  2015-10-28  9:14 ` Peter Chen
@ 2015-11-25  3:19   ` Saurabh Sengar
  0 siblings, 0 replies; 3+ messages in thread
From: Saurabh Sengar @ 2015-11-25  3:19 UTC (permalink / raw)
  To: Peter Chen; +Cc: Greg KH, linux-kernel, linux-usb

any conclusion for this patch ?
any feedback ?

On Oct 28, 2015 2:46 PM, "Peter Chen" <peter.chen@freescale.com> wrote:
>
> On Wed, Oct 28, 2015 at 12:44:35PM +0530, Saurabh Sengar wrote:
> > replace dma_pool_alloc and memset with a single call to dma_pool_zalloc
> >
> > Signed-off-by: Saurabh Sengar <saurabh.truth@gmail.com>
> > ---
> >  drivers/usb/chipidea/udc.c      | 3 +--
> >  drivers/usb/gadget/udc/gr_udc.c | 3 +--
> >  drivers/usb/host/uhci-q.c       | 3 +--
> >  drivers/usb/host/whci/qset.c    | 3 +--
> >  drivers/usb/host/xhci-mem.c     | 6 ++----
> >  5 files changed, 6 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
> > index 8223fe7..235b948f 100644
> > --- a/drivers/usb/chipidea/udc.c
> > +++ b/drivers/usb/chipidea/udc.c
> > @@ -349,14 +349,13 @@ static int add_td_to_list(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq,
> >       if (node == NULL)
> >               return -ENOMEM;
> >
> > -     node->ptr = dma_pool_alloc(hwep->td_pool, GFP_ATOMIC,
> > +     node->ptr = dma_pool_zalloc(hwep->td_pool, GFP_ATOMIC,
> >                                  &node->dma);
> >       if (node->ptr == NULL) {
> >               kfree(node);
> >               return -ENOMEM;
> >       }
> >
> > -     memset(node->ptr, 0, sizeof(struct ci_hw_td));
> >       node->ptr->token = cpu_to_le32(length << __ffs(TD_TOTAL_BYTES));
> >       node->ptr->token &= cpu_to_le32(TD_TOTAL_BYTES);
> >       node->ptr->token |= cpu_to_le32(TD_STATUS_ACTIVE);
> > diff --git a/drivers/usb/gadget/udc/gr_udc.c b/drivers/usb/gadget/udc/gr_udc.c
> > index b9429bc..39b7136 100644
> > --- a/drivers/usb/gadget/udc/gr_udc.c
> > +++ b/drivers/usb/gadget/udc/gr_udc.c
> > @@ -253,13 +253,12 @@ static struct gr_dma_desc *gr_alloc_dma_desc(struct gr_ep *ep, gfp_t gfp_flags)
> >       dma_addr_t paddr;
> >       struct gr_dma_desc *dma_desc;
> >
> > -     dma_desc = dma_pool_alloc(ep->dev->desc_pool, gfp_flags, &paddr);
> > +     dma_desc = dma_pool_zalloc(ep->dev->desc_pool, gfp_flags, &paddr);
> >       if (!dma_desc) {
> >               dev_err(ep->dev->dev, "Could not allocate from DMA pool\n");
> >               return NULL;
> >       }
> >
> > -     memset(dma_desc, 0, sizeof(*dma_desc));
> >       dma_desc->paddr = paddr;
> >
> >       return dma_desc;
> > diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
> > index da6f56d..c17ea15 100644
> > --- a/drivers/usb/host/uhci-q.c
> > +++ b/drivers/usb/host/uhci-q.c
> > @@ -248,11 +248,10 @@ static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci,
> >       dma_addr_t dma_handle;
> >       struct uhci_qh *qh;
> >
> > -     qh = dma_pool_alloc(uhci->qh_pool, GFP_ATOMIC, &dma_handle);
> > +     qh = dma_pool_zalloc(uhci->qh_pool, GFP_ATOMIC, &dma_handle);
> >       if (!qh)
> >               return NULL;
> >
> > -     memset(qh, 0, sizeof(*qh));
> >       qh->dma_handle = dma_handle;
> >
> >       qh->element = UHCI_PTR_TERM(uhci);
> > diff --git a/drivers/usb/host/whci/qset.c b/drivers/usb/host/whci/qset.c
> > index dc31c42..3297473 100644
> > --- a/drivers/usb/host/whci/qset.c
> > +++ b/drivers/usb/host/whci/qset.c
> > @@ -30,10 +30,9 @@ struct whc_qset *qset_alloc(struct whc *whc, gfp_t mem_flags)
> >       struct whc_qset *qset;
> >       dma_addr_t dma;
> >
> > -     qset = dma_pool_alloc(whc->qset_pool, mem_flags, &dma);
> > +     qset = dma_pool_zalloc(whc->qset_pool, mem_flags, &dma);
> >       if (qset == NULL)
> >               return NULL;
> > -     memset(qset, 0, sizeof(struct whc_qset));
> >
> >       qset->qset_dma = dma;
> >       qset->whc = whc;
> > diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
> > index 41f841f..060c20c 100644
> > --- a/drivers/usb/host/xhci-mem.c
> > +++ b/drivers/usb/host/xhci-mem.c
> > @@ -47,13 +47,12 @@ static struct xhci_segment *xhci_segment_alloc(struct xhci_hcd *xhci,
> >       if (!seg)
> >               return NULL;
> >
> > -     seg->trbs = dma_pool_alloc(xhci->segment_pool, flags, &dma);
> > +     seg->trbs = dma_pool_zalloc(xhci->segment_pool, flags, &dma);
> >       if (!seg->trbs) {
> >               kfree(seg);
> >               return NULL;
> >       }
> >
> > -     memset(seg->trbs, 0, TRB_SEGMENT_SIZE);
> >       /* If the cycle state is 0, set the cycle bit to 1 for all the TRBs */
> >       if (cycle_state == 0) {
> >               for (i = 0; i < TRBS_PER_SEGMENT; i++)
> > @@ -517,12 +516,11 @@ static struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci
> >       if (type == XHCI_CTX_TYPE_INPUT)
> >               ctx->size += CTX_SIZE(xhci->hcc_params);
> >
> > -     ctx->bytes = dma_pool_alloc(xhci->device_pool, flags, &ctx->dma);
> > +     ctx->bytes = dma_pool_zalloc(xhci->device_pool, flags, &ctx->dma);
> >       if (!ctx->bytes) {
> >               kfree(ctx);
> >               return NULL;
> >       }
> > -     memset(ctx->bytes, 0, ctx->size);
> >       return ctx;
> >  }
> >
> > --
>
> For chipidea changes:
> Acked-by: Peter Chen <peter.chen@freescale.com>
>
> --
>
> Best Regards,
> Peter Chen

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

end of thread, other threads:[~2015-11-25  3:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-28  7:14 [PATCH] usb : replace dma_pool_alloc and memset with dma_pool_zalloc Saurabh Sengar
2015-10-28  9:14 ` Peter Chen
2015-11-25  3:19   ` Saurabh Sengar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox