diff mbox

[v4,20/22,media] em28xx: use usb_alloc_coherent() for audio

Message ID 1388832951-11195-21-git-send-email-m.chehab@samsung.com (mailing list archive)
State New, archived
Headers show

Commit Message

Mauro Carvalho Chehab Jan. 4, 2014, 10:55 a.m. UTC
Instead of allocating transfer buffers with kmalloc() use
usb_alloc_coherent().

That makes it work also with arm CPUs.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
---
 drivers/media/usb/em28xx/em28xx-audio.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

Comments

Frank Schäfer Jan. 5, 2014, 8:57 p.m. UTC | #1
Am 04.01.2014 11:55, schrieb Mauro Carvalho Chehab:
> Instead of allocating transfer buffers with kmalloc() use
> usb_alloc_coherent().
>
> That makes it work also with arm CPUs.
>
> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
> ---
>  drivers/media/usb/em28xx/em28xx-audio.c | 31 ++++++++++++++++++++-----------
>  1 file changed, 20 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/media/usb/em28xx/em28xx-audio.c b/drivers/media/usb/em28xx/em28xx-audio.c
> index a6eef06ffdcd..e5120430ec80 100644
> --- a/drivers/media/usb/em28xx/em28xx-audio.c
> +++ b/drivers/media/usb/em28xx/em28xx-audio.c
> @@ -64,16 +64,22 @@ static int em28xx_deinit_isoc_audio(struct em28xx *dev)
>  
>  	dprintk("Stopping isoc\n");
>  	for (i = 0; i < EM28XX_AUDIO_BUFS; i++) {
> +		struct urb *urb = dev->adev.urb[i];
> +
>  		if (!irqs_disabled())
> -			usb_kill_urb(dev->adev.urb[i]);
> +			usb_kill_urb(urb);
>  		else
> -			usb_unlink_urb(dev->adev.urb[i]);
> +			usb_unlink_urb(urb);
>  
> -		usb_free_urb(dev->adev.urb[i]);
> -		dev->adev.urb[i] = NULL;
> +		usb_free_coherent(dev->udev,
> +				  urb->transfer_buffer_length,
> +				  dev->adev.transfer_buffer[i],
> +				  urb->transfer_dma);
>  
> -		kfree(dev->adev.transfer_buffer[i]);
>  		dev->adev.transfer_buffer[i] = NULL;
> +
> +		usb_free_urb(urb);
> +		dev->adev.urb[i] = NULL;
>  	}
>  
>  	return 0;
> @@ -176,12 +182,8 @@ static int em28xx_init_audio_isoc(struct em28xx *dev)
>  	for (i = 0; i < EM28XX_AUDIO_BUFS; i++) {
>  		struct urb *urb;
>  		int j, k;
> +		void *buf;
>  
> -		dev->adev.transfer_buffer[i] = kmalloc(sb_size, GFP_ATOMIC);
> -		if (!dev->adev.transfer_buffer[i])
> -			return -ENOMEM;
> -
> -		memset(dev->adev.transfer_buffer[i], 0x80, sb_size);
>  		urb = usb_alloc_urb(EM28XX_NUM_AUDIO_PACKETS, GFP_ATOMIC);
>  		if (!urb) {
>  			em28xx_errdev("usb_alloc_urb failed!\n");
> @@ -192,10 +194,17 @@ static int em28xx_init_audio_isoc(struct em28xx *dev)
>  			return -ENOMEM;
>  		}
>  
> +		buf = usb_alloc_coherent(dev->udev, sb_size, GFP_ATOMIC,
> +					 &urb->transfer_dma);
> +		if (!buf)
> +			return -ENOMEM;
> +		dev->adev.transfer_buffer[i] = buf;
> +		memset(buf, 0x80, sb_size);
> +
>  		urb->dev = dev->udev;
>  		urb->context = dev;
>  		urb->pipe = usb_rcvisocpipe(dev->udev, EM28XX_EP_AUDIO);
> -		urb->transfer_flags = URB_ISO_ASAP;
> +		urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
>  		urb->transfer_buffer = dev->adev.transfer_buffer[i];
>  		urb->interval = 1;
>  		urb->complete = em28xx_audio_isocirq;

Reviewed-by: Frank Schäfer <fschaefer.oss@googlemail.com>

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

Patch

diff --git a/drivers/media/usb/em28xx/em28xx-audio.c b/drivers/media/usb/em28xx/em28xx-audio.c
index a6eef06ffdcd..e5120430ec80 100644
--- a/drivers/media/usb/em28xx/em28xx-audio.c
+++ b/drivers/media/usb/em28xx/em28xx-audio.c
@@ -64,16 +64,22 @@  static int em28xx_deinit_isoc_audio(struct em28xx *dev)
 
 	dprintk("Stopping isoc\n");
 	for (i = 0; i < EM28XX_AUDIO_BUFS; i++) {
+		struct urb *urb = dev->adev.urb[i];
+
 		if (!irqs_disabled())
-			usb_kill_urb(dev->adev.urb[i]);
+			usb_kill_urb(urb);
 		else
-			usb_unlink_urb(dev->adev.urb[i]);
+			usb_unlink_urb(urb);
 
-		usb_free_urb(dev->adev.urb[i]);
-		dev->adev.urb[i] = NULL;
+		usb_free_coherent(dev->udev,
+				  urb->transfer_buffer_length,
+				  dev->adev.transfer_buffer[i],
+				  urb->transfer_dma);
 
-		kfree(dev->adev.transfer_buffer[i]);
 		dev->adev.transfer_buffer[i] = NULL;
+
+		usb_free_urb(urb);
+		dev->adev.urb[i] = NULL;
 	}
 
 	return 0;
@@ -176,12 +182,8 @@  static int em28xx_init_audio_isoc(struct em28xx *dev)
 	for (i = 0; i < EM28XX_AUDIO_BUFS; i++) {
 		struct urb *urb;
 		int j, k;
+		void *buf;
 
-		dev->adev.transfer_buffer[i] = kmalloc(sb_size, GFP_ATOMIC);
-		if (!dev->adev.transfer_buffer[i])
-			return -ENOMEM;
-
-		memset(dev->adev.transfer_buffer[i], 0x80, sb_size);
 		urb = usb_alloc_urb(EM28XX_NUM_AUDIO_PACKETS, GFP_ATOMIC);
 		if (!urb) {
 			em28xx_errdev("usb_alloc_urb failed!\n");
@@ -192,10 +194,17 @@  static int em28xx_init_audio_isoc(struct em28xx *dev)
 			return -ENOMEM;
 		}
 
+		buf = usb_alloc_coherent(dev->udev, sb_size, GFP_ATOMIC,
+					 &urb->transfer_dma);
+		if (!buf)
+			return -ENOMEM;
+		dev->adev.transfer_buffer[i] = buf;
+		memset(buf, 0x80, sb_size);
+
 		urb->dev = dev->udev;
 		urb->context = dev;
 		urb->pipe = usb_rcvisocpipe(dev->udev, EM28XX_EP_AUDIO);
-		urb->transfer_flags = URB_ISO_ASAP;
+		urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
 		urb->transfer_buffer = dev->adev.transfer_buffer[i];
 		urb->interval = 1;
 		urb->complete = em28xx_audio_isocirq;