Skip to content

Commit 2bc2902

Browse files
HiassofTpopcornmix
authored andcommitted
bcm2835-dma: Fix up convert to DMA pool
1 parent fdedc02 commit 2bc2902

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

drivers/dma/bcm2835-dma.c

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,17 @@ static struct dma_async_tx_descriptor *bcm2835_dma_prep_dma_cyclic(
491491
c->cyclic = true;
492492

493493
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;
494505
}
495506

496507
static struct dma_async_tx_descriptor *
@@ -537,6 +548,7 @@ bcm2835_dma_prep_slave_sg(struct dma_chan *chan,
537548
if (!d)
538549
return NULL;
539550

551+
d->c = c;
540552
d->dir = direction;
541553

542554
if (c->ch >= 8) /* LITE channel */
@@ -556,15 +568,21 @@ bcm2835_dma_prep_slave_sg(struct dma_chan *chan,
556568
d->frames += len / max_size + 1;
557569
}
558570

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) {
565573
kfree(d);
566574
return NULL;
567575
}
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+
}
568586

569587
/*
570588
* Iterate over all SG entries, create a control block
@@ -582,7 +600,7 @@ bcm2835_dma_prep_slave_sg(struct dma_chan *chan,
582600
for (j = 0; j < len; j += max_size) {
583601
u32 waits;
584602
struct bcm2835_dma_cb *control_block =
585-
&d->control_block_base[i + split_cnt];
603+
d->cb_list[i + split_cnt].cb;
586604

587605
/* Setup addresses */
588606
if (d->dir == DMA_DEV_TO_MEM) {
@@ -626,9 +644,7 @@ bcm2835_dma_prep_slave_sg(struct dma_chan *chan,
626644
if (i < sg_len - 1 || len - j > max_size) {
627645
/* Next block is the next frame. */
628646
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;
632648
} else {
633649
/* Next block is empty. */
634650
control_block->next = 0;

0 commit comments

Comments
 (0)