dmatest: properly handle duplicate DMA channels
PATCH 1/1 dmatest: properly handle duplicate DMA channels
Update the the dmatest driver so that it handles duplicate DMA channels properly.
When a DMA client is notified of an available DMA channel, it must check if it has already allocated resources for that channel. If so, it should return DMA_DUP. This can happen, for example, if a DMA driver calls dma_async_device_register() more than once.
--- drivers/dma/dmatest.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
drivers/dma/dmatest.c +6 -1
@@ -321,10 +321,15 @@ static void dmatest_cleanup_channel(struct dmatest_chan *dtc)static enum dma_state_client dmatest_add_channel (struct dma_chan *chan) { -struct dmatest_chan *dtc; +struct dmatest_chan *dtc, *_dtc;struct dmatest_thread *thread;unsigned int i; +/* Have we already been told about this channel? */ +list_for_each_entry_safe (dtc, _dtc, &dmatest_channels, node) +if (dtc->chan == chan) +return DMA_DUP ; + dtc =kmalloc (sizeof (struct dmatest_chan ),GFP_ATOMIC );if (!dtc) {pr_warning ("dmatest: No memory for %s\n" , chan->dev.bus_id);
Signature · 1 line
1.5.5
Quoted 9 lines · Timur Tabi
Update the the dmatest driver so that it handles duplicate DMA channels properly.
When a DMA client is notified of an available DMA channel, it must check if it has already allocated resources for that channel. If so, it should return
DMA_DUP. This can happen, for example, if a DMA driver callsdma_async_device_register()more than once.Signed-off-by Timur Tabi <[email protected]>
...though I don't really see why you have to uselist_for_entry_safe()...
Thanks a lot!
Haavard
Quoted 2 lines · Haavard Skinnemoen
...though I don't really see why you have to use
list_for_entry_safe()...
You use it in dmatest_remove_channel(), so I figured I'd do the same thing.
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Quoted 6 lines · Timur Tabi
Quoted 2 lines · Haavard Skinnemoen
...though I don't really see why you have to use
list_for_entry_safe()...You use it in
dmatest_remove_channel(), so I figured I'd do the same thing.
dmatest_remove_channel() may call list_del() on the current entry, so it has to. As long as you're not altering the list, the _safe() variant shouldn't be necessary.
Haavard
Quoted 9 lines · On Thu, 18 Sep 2008 10:21:19 -0500 Timur Tabi <[email protected]> wrote:
drivers/dma/dmatest.c +1
-1@@ -321,10 +321,15 @@ static void dmatest_cleanup_channel(struct dmatest_chan *dtc)static enum dma_state_client dmatest_add_channel (struct dma_chan *chan) { -struct dmatest_chan *dtc; +struct dmatest_chan *dtc, *_dtc;struct dmatest_thread *thread;
drivers/dma/dmatest.c static void dmatest_cleanup_channel(struct dmatest_chan *dtc) · line 335
Quoted 10 lines
drivers/dma/dmatest.c +5
-0unsigned int i; +/* Have we already been told about this channel? */ +list_for_each_entry_safe (dtc, _dtc, &dmatest_channels, node) +if (dtc->chan == chan) +return DMA_DUP ; + dtc =kmalloc (sizeof (struct dmatest_chan ),GFP_ATOMIC );if (!dtc) {pr_warning ("dmatest: No memory for %s\n" , chan->dev.bus_id);
hm. A few lines after that GFP_ATOMIC the driver does a GFP_KERNEL allocation.
One of them is incorrect. The interface is undocumented (natch), but I assume that GFP_KERNEL is the one to use here.
drivers/dma/dmatest.c renamed from drivers/dma/dmatest.c~a +1 -1
@@ -330,7 +330,7 @@ static enum dma_state_client dmatest_addif (dtc->chan == chan)return DMA_DUP ; - dtc =kmalloc (sizeof (struct dmatest_chan ),GFP_ATOMIC ); + dtc =kmalloc (sizeof (struct dmatest_chan ),GFP_KERNEL );if (!dtc) {pr_warning ("dmatest: No memory for %s\n" , chan->dev.bus_id);return DMA_NAK ;
_
Quoted 2 lines · Andrew Morton
One of them is incorrect. The interface is undocumented (natch), but I assume that
GFP_KERNELis the one to use here.
You're right -- there's no reason to use GFP_ATOMIC there. I messed around with various kinds of locks before I realized that it was already protected by a mutex.
Haavard
Quoted 26 lines · Andrew Morton
Quoted 9 lines · On Thu, 18 Sep 2008 10:21:19 -0500 Timur Tabi <[email protected]> wrote:
drivers/dma/dmatest.c +1
-1@@ -321,10 +321,15 @@ static void dmatest_cleanup_channel(struct dmatest_chan *dtc)static enum dma_state_client dmatest_add_channel (struct dma_chan *chan) { -struct dmatest_chan *dtc; +struct dmatest_chan *dtc, *_dtc;struct dmatest_thread *thread;drivers/dma/dmatest.c static void dmatest_cleanup_channel(struct dmatest_chan *dtc) · line 335
Quoted 10 lines
drivers/dma/dmatest.c +5
-0unsigned int i; +/* Have we already been told about this channel? */ +list_for_each_entry_safe (dtc, _dtc, &dmatest_channels, node) +if (dtc->chan == chan) +return DMA_DUP ; + dtc =kmalloc (sizeof (struct dmatest_chan ),GFP_ATOMIC );if (!dtc) {pr_warning ("dmatest: No memory for %s\n" , chan->dev.bus_id);hm. A few lines after that
GFP_ATOMICthe driver does aGFP_KERNELallocation.
Quoted 3 lines
One of them is incorrect. The interface is undocumented (natch), but I assume that
GFP_KERNELis the one to use here.
The interface is documented, although not the locking (natch), at include/linux/dmaengine.h:229. When I fix this up is there a canonical location to document a callback interface rather than at the callback's typedef?
Thanks,
Dan
Quoted 3 lines · On Sat, 20 Sep 2008 14:40:40 -0700 "Dan Williams" <[email protected]>…
When I fix this up is there a
canonical location to document a callback interface rather than at the callback's typedef?
Personally I like to see at at the definition site, so that's within the struct which contains the function pointer. eg:
struct address_space_operations {
int (*writepage)(struct page *page, struct writeback_control *wbc);
int (*readpage)(struct file *, struct page *);
void (*sync_page)(struct page *);
/* Write back some dirty pages from this mapping. */
int (*writepages)(struct address_space *, struct writeback_control *);
/* Set a page dirty. Return true if this dirtied it */
int (*set_page_dirty)(struct page *page);(sadly incomplete, but we tried)