1 From d2f4f99db3e9ec8b063cf2e45704e2bb95428317 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime.ripard@free-electrons.com>
3 Date: Mon, 17 Nov 2014 14:41:58 +0100
4 Subject: [PATCH] dmaengine: Rework dma_chan_get
6 dma_chan_get uses a rather interesting error handling and code path.
8 Change it to something more usual in the kernel.
10 Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
11 Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
12 Signed-off-by: Vinod Koul <vinod.koul@intel.com>
14 drivers/dma/dmaengine.c | 36 +++++++++++++++++++-----------------
15 1 file changed, 19 insertions(+), 17 deletions(-)
17 --- a/drivers/dma/dmaengine.c
18 +++ b/drivers/dma/dmaengine.c
19 @@ -222,31 +222,33 @@ static void balance_ref_count(struct dma
21 static int dma_chan_get(struct dma_chan *chan)
24 struct module *owner = dma_chan_to_owner(chan);
27 + /* The channel is already in use, update client count */
28 if (chan->client_count) {
31 - } else if (try_module_get(owner))
37 - chan->client_count++;
38 + if (!try_module_get(owner))
41 /* allocate upon first client reference */
42 - if (chan->client_count == 1 && err == 0) {
43 - int desc_cnt = chan->device->device_alloc_chan_resources(chan);
47 - chan->client_count = 0;
49 - } else if (!dma_has_cap(DMA_PRIVATE, chan->device->cap_mask))
50 - balance_ref_count(chan);
54 + ret = chan->device->device_alloc_chan_resources(chan);
58 + if (!dma_has_cap(DMA_PRIVATE, chan->device->cap_mask))
59 + balance_ref_count(chan);
62 + chan->client_count++;