@@ -582,6 +582,33 @@ static void usb6fire_pcm_init_urb(struct pcm_urb *urb,
582
582
urb -> instance .number_of_packets = PCM_N_PACKETS_PER_URB ;
583
583
}
584
584
585
+ static int usb6fire_pcm_buffers_init (struct pcm_runtime * rt )
586
+ {
587
+ int i ;
588
+
589
+ for (i = 0 ; i < PCM_N_URBS ; i ++ ) {
590
+ rt -> out_urbs [i ].buffer = kzalloc (PCM_N_PACKETS_PER_URB
591
+ * PCM_MAX_PACKET_SIZE , GFP_KERNEL );
592
+ if (!rt -> out_urbs [i ].buffer )
593
+ return - ENOMEM ;
594
+ rt -> in_urbs [i ].buffer = kzalloc (PCM_N_PACKETS_PER_URB
595
+ * PCM_MAX_PACKET_SIZE , GFP_KERNEL );
596
+ if (!rt -> in_urbs [i ].buffer )
597
+ return - ENOMEM ;
598
+ }
599
+ return 0 ;
600
+ }
601
+
602
+ static void usb6fire_pcm_buffers_destroy (struct pcm_runtime * rt )
603
+ {
604
+ int i ;
605
+
606
+ for (i = 0 ; i < PCM_N_URBS ; i ++ ) {
607
+ kfree (rt -> out_urbs [i ].buffer );
608
+ kfree (rt -> in_urbs [i ].buffer );
609
+ }
610
+ }
611
+
585
612
int usb6fire_pcm_init (struct sfire_chip * chip )
586
613
{
587
614
int i ;
@@ -593,6 +620,13 @@ int usb6fire_pcm_init(struct sfire_chip *chip)
593
620
if (!rt )
594
621
return - ENOMEM ;
595
622
623
+ ret = usb6fire_pcm_buffers_init (rt );
624
+ if (ret ) {
625
+ usb6fire_pcm_buffers_destroy (rt );
626
+ kfree (rt );
627
+ return ret ;
628
+ }
629
+
596
630
rt -> chip = chip ;
597
631
rt -> stream_state = STREAM_DISABLED ;
598
632
rt -> rate = ARRAY_SIZE (rates );
@@ -614,6 +648,7 @@ int usb6fire_pcm_init(struct sfire_chip *chip)
614
648
615
649
ret = snd_pcm_new (chip -> card , "DMX6FireUSB" , 0 , 1 , 1 , & pcm );
616
650
if (ret < 0 ) {
651
+ usb6fire_pcm_buffers_destroy (rt );
617
652
kfree (rt );
618
653
snd_printk (KERN_ERR PREFIX "cannot create pcm instance.\n" );
619
654
return ret ;
@@ -625,6 +660,7 @@ int usb6fire_pcm_init(struct sfire_chip *chip)
625
660
snd_pcm_set_ops (pcm , SNDRV_PCM_STREAM_CAPTURE , & pcm_ops );
626
661
627
662
if (ret ) {
663
+ usb6fire_pcm_buffers_destroy (rt );
628
664
kfree (rt );
629
665
snd_printk (KERN_ERR PREFIX
630
666
"error preallocating pcm buffers.\n" );
@@ -669,6 +705,9 @@ void usb6fire_pcm_abort(struct sfire_chip *chip)
669
705
670
706
void usb6fire_pcm_destroy (struct sfire_chip * chip )
671
707
{
672
- kfree (chip -> pcm );
708
+ struct pcm_runtime * rt = chip -> pcm ;
709
+
710
+ usb6fire_pcm_buffers_destroy (rt );
711
+ kfree (rt );
673
712
chip -> pcm = NULL ;
674
713
}
0 commit comments