[1/3] media/ttusb-budget: remove pci_zalloc_coherent abuse

Message ID 20180109203939.5930-2-hch@lst.de (mailing list archive)
State Superseded, archived
Headers

Commit Message

Christoph Hellwig Jan. 9, 2018, 8:39 p.m. UTC
  Switch to a plain kzalloc instea of pci_zalloc_coherent to allocate
memory for the USB DMA.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
  

Comments

Joe Perches Jan. 9, 2018, 8:49 p.m. UTC | #1
On Tue, 2018-01-09 at 21:39 +0100, Christoph Hellwig wrote:
> Switch to a plain kzalloc instea of pci_zalloc_coherent to allocate
> memory for the USB DMA.
[]
> diff --git a/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
[]
> @@ -792,21 +791,15 @@ static void ttusb_free_iso_urbs(struct ttusb *ttusb)
> []
>  static int ttusb_alloc_iso_urbs(struct ttusb *ttusb)
>  {
>  	int i;
>  
> -	ttusb->iso_buffer = pci_zalloc_consistent(NULL,
> -						  ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF * ISO_BUF_COUNT,
> -						  &ttusb->iso_dma_handle);
> -
> +	ttusb->iso_buffer = kzalloc(ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF *
> +			ISO_BUF_COUNT, GFP_KERNEL);
>  	if (!ttusb->iso_buffer) {
>  		dprintk("%s: pci_alloc_consistent - not enough memory\n",
>  			__func__);

This message doesn't make sense anymore and it might as well
be deleted.

And it might be better to use kcalloc

	ttusb->iso_buffer = kcalloc(FRAMES_PER_ISO_BUF * ISO_BUF_COUNT,
				    ISO_FRAME_SIZE, GFP_KERNEL);
  
Bjorn Helgaas Jan. 9, 2018, 11:45 p.m. UTC | #2
On Tue, Jan 09, 2018 at 09:39:37PM +0100, Christoph Hellwig wrote:
> Switch to a plain kzalloc instea of pci_zalloc_coherent to allocate
> memory for the USB DMA.

s/instea/instead/

> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c | 13 +++----------
>  1 file changed, 3 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
> index a142b9dc0feb..b8619fb23351 100644
> --- a/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
> +++ b/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
> @@ -102,7 +102,6 @@ struct ttusb {
>  	unsigned int isoc_in_pipe;
>  
>  	void *iso_buffer;
> -	dma_addr_t iso_dma_handle;
>  
>  	struct urb *iso_urb[ISO_BUF_COUNT];
>  
> @@ -792,21 +791,15 @@ static void ttusb_free_iso_urbs(struct ttusb *ttusb)
>  
>  	for (i = 0; i < ISO_BUF_COUNT; i++)
>  		usb_free_urb(ttusb->iso_urb[i]);
> -
> -	pci_free_consistent(NULL,
> -			    ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF *
> -			    ISO_BUF_COUNT, ttusb->iso_buffer,
> -			    ttusb->iso_dma_handle);
> +	kfree(ttusb->iso_buffer);
>  }
>  
>  static int ttusb_alloc_iso_urbs(struct ttusb *ttusb)
>  {
>  	int i;
>  
> -	ttusb->iso_buffer = pci_zalloc_consistent(NULL,
> -						  ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF * ISO_BUF_COUNT,
> -						  &ttusb->iso_dma_handle);
> -
> +	ttusb->iso_buffer = kzalloc(ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF *
> +			ISO_BUF_COUNT, GFP_KERNEL);
>  	if (!ttusb->iso_buffer) {
>  		dprintk("%s: pci_alloc_consistent - not enough memory\n",
>  			__func__);
> -- 
> 2.14.2
>
  
Christoph Hellwig Jan. 10, 2018, 8:17 a.m. UTC | #3
On Tue, Jan 09, 2018 at 12:49:26PM -0800, Joe Perches wrote:
> This message doesn't make sense anymore and it might as well
> be deleted.
> 
> And it might be better to use kcalloc
> 
> 	ttusb->iso_buffer = kcalloc(FRAMES_PER_ISO_BUF * ISO_BUF_COUNT,
> 				    ISO_FRAME_SIZE, GFP_KERNEL);

Sure.
  

Patch

diff --git a/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
index a142b9dc0feb..b8619fb23351 100644
--- a/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
+++ b/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
@@ -102,7 +102,6 @@  struct ttusb {
 	unsigned int isoc_in_pipe;
 
 	void *iso_buffer;
-	dma_addr_t iso_dma_handle;
 
 	struct urb *iso_urb[ISO_BUF_COUNT];
 
@@ -792,21 +791,15 @@  static void ttusb_free_iso_urbs(struct ttusb *ttusb)
 
 	for (i = 0; i < ISO_BUF_COUNT; i++)
 		usb_free_urb(ttusb->iso_urb[i]);
-
-	pci_free_consistent(NULL,
-			    ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF *
-			    ISO_BUF_COUNT, ttusb->iso_buffer,
-			    ttusb->iso_dma_handle);
+	kfree(ttusb->iso_buffer);
 }
 
 static int ttusb_alloc_iso_urbs(struct ttusb *ttusb)
 {
 	int i;
 
-	ttusb->iso_buffer = pci_zalloc_consistent(NULL,
-						  ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF * ISO_BUF_COUNT,
-						  &ttusb->iso_dma_handle);
-
+	ttusb->iso_buffer = kzalloc(ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF *
+			ISO_BUF_COUNT, GFP_KERNEL);
 	if (!ttusb->iso_buffer) {
 		dprintk("%s: pci_alloc_consistent - not enough memory\n",
 			__func__);