150-dmaengine-Rework-dma_chan_get.patch 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. dma_chan_get uses a rather interesting error handling and code path.
  6. Change it to something more usual in the kernel.
  7. Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
  8. Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  9. Signed-off-by: Vinod Koul <vinod.koul@intel.com>
  10. ---
  11. drivers/dma/dmaengine.c | 36 +++++++++++++++++++-----------------
  12. 1 file changed, 19 insertions(+), 17 deletions(-)
  13. --- a/drivers/dma/dmaengine.c
  14. +++ b/drivers/dma/dmaengine.c
  15. @@ -222,31 +222,33 @@ static void balance_ref_count(struct dma
  16. */
  17. static int dma_chan_get(struct dma_chan *chan)
  18. {
  19. - int err = -ENODEV;
  20. struct module *owner = dma_chan_to_owner(chan);
  21. + int ret;
  22. + /* The channel is already in use, update client count */
  23. if (chan->client_count) {
  24. __module_get(owner);
  25. - err = 0;
  26. - } else if (try_module_get(owner))
  27. - err = 0;
  28. + goto out;
  29. + }
  30. - if (err == 0)
  31. - chan->client_count++;
  32. + if (!try_module_get(owner))
  33. + return -ENODEV;
  34. /* allocate upon first client reference */
  35. - if (chan->client_count == 1 && err == 0) {
  36. - int desc_cnt = chan->device->device_alloc_chan_resources(chan);
  37. -
  38. - if (desc_cnt < 0) {
  39. - err = desc_cnt;
  40. - chan->client_count = 0;
  41. - module_put(owner);
  42. - } else if (!dma_has_cap(DMA_PRIVATE, chan->device->cap_mask))
  43. - balance_ref_count(chan);
  44. - }
  45. -
  46. - return err;
  47. + ret = chan->device->device_alloc_chan_resources(chan);
  48. + if (ret < 0)
  49. + goto err_out;
  50. +
  51. + if (!dma_has_cap(DMA_PRIVATE, chan->device->cap_mask))
  52. + balance_ref_count(chan);
  53. +
  54. +out:
  55. + chan->client_count++;
  56. + return 0;
  57. +
  58. +err_out:
  59. + module_put(owner);
  60. + return ret;
  61. }
  62. /**