@@ -491,6 +491,17 @@ static struct dma_async_tx_descriptor *bcm2835_dma_prep_dma_cyclic(
491
491
c -> cyclic = true;
492
492
493
493
return vchan_tx_prep (& c -> vc , & d -> vd , flags );
494
+ error_cb :
495
+ i -- ;
496
+ for (; i >= 0 ; i -- ) {
497
+ struct bcm2835_cb_entry * cb_entry = & d -> cb_list [i ];
498
+
499
+ dma_pool_free (c -> cb_pool , cb_entry -> cb , cb_entry -> paddr );
500
+ }
501
+
502
+ kfree (d -> cb_list );
503
+ kfree (d );
504
+ return NULL ;
494
505
}
495
506
496
507
static struct dma_async_tx_descriptor *
@@ -537,6 +548,7 @@ bcm2835_dma_prep_slave_sg(struct dma_chan *chan,
537
548
if (!d )
538
549
return NULL ;
539
550
551
+ d -> c = c ;
540
552
d -> dir = direction ;
541
553
542
554
if (c -> ch >= 8 ) /* LITE channel */
@@ -556,15 +568,21 @@ bcm2835_dma_prep_slave_sg(struct dma_chan *chan,
556
568
d -> frames += len / max_size + 1 ;
557
569
}
558
570
559
- /* Allocate memory for control blocks */
560
- d -> control_block_size = d -> frames * sizeof (struct bcm2835_dma_cb );
561
- d -> control_block_base = dma_zalloc_coherent (chan -> device -> dev ,
562
- d -> control_block_size , & d -> control_block_base_phys ,
563
- GFP_NOWAIT );
564
- if (!d -> control_block_base ) {
571
+ d -> cb_list = kcalloc (d -> frames , sizeof (* d -> cb_list ), GFP_KERNEL );
572
+ if (!d -> cb_list ) {
565
573
kfree (d );
566
574
return NULL ;
567
575
}
576
+ /* Allocate memory for control blocks */
577
+ for (i = 0 ; i < d -> frames ; i ++ ) {
578
+ struct bcm2835_cb_entry * cb_entry = & d -> cb_list [i ];
579
+
580
+ cb_entry -> cb = dma_pool_zalloc (c -> cb_pool , GFP_ATOMIC ,
581
+ & cb_entry -> paddr );
582
+
583
+ if (!cb_entry -> cb )
584
+ goto error_cb ;
585
+ }
568
586
569
587
/*
570
588
* Iterate over all SG entries, create a control block
@@ -582,7 +600,7 @@ bcm2835_dma_prep_slave_sg(struct dma_chan *chan,
582
600
for (j = 0 ; j < len ; j += max_size ) {
583
601
u32 waits ;
584
602
struct bcm2835_dma_cb * control_block =
585
- & d -> control_block_base [i + split_cnt ];
603
+ d -> cb_list [i + split_cnt ]. cb ;
586
604
587
605
/* Setup addresses */
588
606
if (d -> dir == DMA_DEV_TO_MEM ) {
@@ -626,9 +644,7 @@ bcm2835_dma_prep_slave_sg(struct dma_chan *chan,
626
644
if (i < sg_len - 1 || len - j > max_size ) {
627
645
/* Next block is the next frame. */
628
646
control_block -> next =
629
- d -> control_block_base_phys +
630
- sizeof (struct bcm2835_dma_cb ) *
631
- (i + split_cnt + 1 );
647
+ d -> cb_list [i + split_cnt + 1 ].paddr ;
632
648
} else {
633
649
/* Next block is empty. */
634
650
control_block -> next = 0 ;
0 commit comments