ipq806x: assert AHB PCIe reset during init
[openwrt/openwrt.git] / target / linux / ipq806x / patches-3.18 / 150-dmaengine-Rework-dma_chan_get.patch
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
5
6 dma_chan_get uses a rather interesting error handling and code path.
7
8 Change it to something more usual in the kernel.
9
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>
13 ---
14 drivers/dma/dmaengine.c | 36 +++++++++++++++++++-----------------
15 1 file changed, 19 insertions(+), 17 deletions(-)
16
17 --- a/drivers/dma/dmaengine.c
18 +++ b/drivers/dma/dmaengine.c
19 @@ -222,31 +222,33 @@ static void balance_ref_count(struct dma
20 */
21 static int dma_chan_get(struct dma_chan *chan)
22 {
23 - int err = -ENODEV;
24 struct module *owner = dma_chan_to_owner(chan);
25 + int ret;
26
27 + /* The channel is already in use, update client count */
28 if (chan->client_count) {
29 __module_get(owner);
30 - err = 0;
31 - } else if (try_module_get(owner))
32 - err = 0;
33 + goto out;
34 + }
35
36 - if (err == 0)
37 - chan->client_count++;
38 + if (!try_module_get(owner))
39 + return -ENODEV;
40
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);
44 -
45 - if (desc_cnt < 0) {
46 - err = desc_cnt;
47 - chan->client_count = 0;
48 - module_put(owner);
49 - } else if (!dma_has_cap(DMA_PRIVATE, chan->device->cap_mask))
50 - balance_ref_count(chan);
51 - }
52 -
53 - return err;
54 + ret = chan->device->device_alloc_chan_resources(chan);
55 + if (ret < 0)
56 + goto err_out;
57 +
58 + if (!dma_has_cap(DMA_PRIVATE, chan->device->cap_mask))
59 + balance_ref_count(chan);
60 +
61 +out:
62 + chan->client_count++;
63 + return 0;
64 +
65 +err_out:
66 + module_put(owner);
67 + return ret;
68 }
69
70 /**