diff options
author | Maxime Ripard <maxime.ripard@free-electrons.com> | 2014-11-17 14:41:58 +0100 |
---|---|---|
committer | Vinod Koul <vinod.koul@intel.com> | 2014-12-22 07:58:55 +0100 |
commit | d2f4f99db3e9ec8b063cf2e45704e2bb95428317 (patch) | |
tree | 9977bcb2e3f8eacfd1f1417a2aa2ced074734661 /drivers/dma/dmaengine.c | |
parent | dmaengine: Make the destination abbreviation coherent (diff) | |
download | linux-d2f4f99db3e9ec8b063cf2e45704e2bb95428317.tar.xz linux-d2f4f99db3e9ec8b063cf2e45704e2bb95428317.zip |
dmaengine: Rework dma_chan_get
dma_chan_get uses a rather interesting error handling and code path.
Change it to something more usual in the kernel.
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Diffstat (limited to 'drivers/dma/dmaengine.c')
-rw-r--r-- | drivers/dma/dmaengine.c | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c index e057935e3023..a5da0e147560 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c @@ -222,31 +222,33 @@ static void balance_ref_count(struct dma_chan *chan) */ static int dma_chan_get(struct dma_chan *chan) { - int err = -ENODEV; struct module *owner = dma_chan_to_owner(chan); + int ret; + /* The channel is already in use, update client count */ if (chan->client_count) { __module_get(owner); - err = 0; - } else if (try_module_get(owner)) - err = 0; + goto out; + } - if (err == 0) - chan->client_count++; + if (!try_module_get(owner)) + return -ENODEV; /* allocate upon first client reference */ - if (chan->client_count == 1 && err == 0) { - int desc_cnt = chan->device->device_alloc_chan_resources(chan); - - if (desc_cnt < 0) { - err = desc_cnt; - chan->client_count = 0; - module_put(owner); - } else if (!dma_has_cap(DMA_PRIVATE, chan->device->cap_mask)) - balance_ref_count(chan); - } + ret = chan->device->device_alloc_chan_resources(chan); + if (ret < 0) + goto err_out; - return err; + if (!dma_has_cap(DMA_PRIVATE, chan->device->cap_mask)) + balance_ref_count(chan); + +out: + chan->client_count++; + return 0; + +err_out: + module_put(owner); + return ret; } /** |