From c2657f48961d73311fa2245ba20916a88e523f52 Mon Sep 17 00:00:00 2001 From: Johannes Stezenbach Date: Sun, 19 Dec 2004 17:52:15 +0000 Subject: Fat removal in init_dma_queue - no path allows adapter->dmaq{1/2}.buffer to be != NULL when init_dma_queue() is called; - unneeded memset: pci_alloc_consistent() already zeroes pages; - init_dma_queue_one() avoids some code duplication. Signed-off-by: Francois Romieu --- linux/drivers/media/dvb/b2c2/skystar2.c | 80 ++++++++++++++------------------- 1 file changed, 33 insertions(+), 47 deletions(-) (limited to 'linux/drivers/media/dvb') diff --git a/linux/drivers/media/dvb/b2c2/skystar2.c b/linux/drivers/media/dvb/b2c2/skystar2.c index 418d6e353..775b3a37a 100644 --- a/linux/drivers/media/dvb/b2c2/skystar2.c +++ b/linux/drivers/media/dvb/b2c2/skystar2.c @@ -1680,61 +1680,49 @@ static irqreturn_t isr(int irq, void *dev_id, struct pt_regs *regs) return IRQ_HANDLED; } -static void init_dma_queue(struct adapter *adapter) +static int init_dma_queue_one(struct adapter *adapter, struct dmaq *dmaq, + int size, int dmaq_offset) { + struct pci_dev *pdev = adapter->pdev; dma_addr_t dma_addr; - if (adapter->dmaq1.buffer != 0) - return; - - adapter->dmaq1.head = 0; - adapter->dmaq1.tail = 0; - adapter->dmaq1.buffer = NULL; - - adapter->dmaq1.buffer = pci_alloc_consistent(adapter->pdev, SIZE_OF_BUF_DMA1 + 0x80, &dma_addr); - - if (adapter->dmaq1.buffer != 0) { - memset(adapter->dmaq1.buffer, 0, SIZE_OF_BUF_DMA1); - - adapter->dmaq1.bus_addr = dma_addr; - adapter->dmaq1.buffer_size = SIZE_OF_BUF_DMA1; - - dma_init_dma(adapter, 0); - - adapter->dma_status = adapter->dma_status | 0x10000000; - - ddprintk("%s: allocated dma buffer at 0x%p, length=%d\n", __FUNCTION__, adapter->dmaq1.buffer, SIZE_OF_BUF_DMA1); - - } else { - - adapter->dma_status = adapter->dma_status & ~0x10000000; - } + dmaq->head = 0; + dmaq->tail = 0; - if (adapter->dmaq2.buffer != 0) - return; - - adapter->dmaq2.head = 0; - adapter->dmaq2.tail = 0; - adapter->dmaq2.buffer = NULL; - - adapter->dmaq2.buffer = pci_alloc_consistent(adapter->pdev, SIZE_OF_BUF_DMA2 + 0x80, &dma_addr); - - if (adapter->dmaq2.buffer != 0) { - memset(adapter->dmaq2.buffer, 0, SIZE_OF_BUF_DMA2); + dmaq->buffer = pci_alloc_consistent(pdev, size + 0x80, &dma_addr); + if (!dmaq->buffer) + return -ENOMEM; - adapter->dmaq2.bus_addr = dma_addr; - adapter->dmaq2.buffer_size = SIZE_OF_BUF_DMA2; + dmaq->bus_addr = dma_addr; + dmaq->buffer_size = size; - dma_init_dma(adapter, 1); + dma_init_dma(adapter, dmaq_offset); - adapter->dma_status = adapter->dma_status | 0x20000000; + ddprintk("%s: allocated dma buffer at 0x%p, length=%d\n", + __FUNCTION__, dmaq->buffer, size); - ddprintk("%s: allocated dma buffer at 0x%p, length=%d\n", __FUNCTION__, adapter->dmaq2.buffer, (int) SIZE_OF_BUF_DMA2); + return 0; +} - } else { +static int init_dma_queue(struct adapter *adapter) +{ + struct { + struct dmaq *dmaq; + u32 dma_status; + int size; + } dmaq_desc[] = { + { &adapter->dmaq1, SIZE_OF_BUF_DMA1, 0x10000000 }, + { &adapter->dmaq2, SIZE_OF_BUF_DMA2, 0x20000000 } + }, *p = dmaq_desc; + int i; - adapter->dma_status = adapter->dma_status & ~0x20000000; + for (i = 0; i < 2; i++, p++) { + if (init_dma_queue_one(adapter, p->dmaq, p->size, i) < 0) + adapter->dma_status &= ~p->dma_status; + else + adapter->dma_status |= p->dma_status; } + return (adapter->dma_status & 0x30000000) ? 0 : -ENOMEM; } static void free_dma_queue(struct adapter *adapter) @@ -1920,9 +1908,7 @@ static int driver_initialize(struct pci_dev *pdev) write_reg_dw(adapter, 0x210, 0xb2ff); write_reg_dw(adapter, 0x208, 0x40); - init_dma_queue(adapter); - - if ((adapter->dma_status & 0x30000000) == 0) { + if (init_dma_queue(adapter) < 0) { free_adapter_object(adapter); return -ENODEV; -- cgit v1.2.3