[PATCH v1 2/4] dmaengine: Refactor devm_dma_request_chan() for readability

Andy Shevchenko
2025-11-09T22:29:47Z

Yes, while it's a bit longer in terms of LoCs, it's more readable
when we use the usual patter to check for errors, and not for
a success). This eliminates unneeded assignment and moves the
needed one closer to its user which is better programming pattern
because it allows avoiding potential errors in case the variable
is getting reused. Also note that the same pattern have been used
already in dmaenginem_async_device_register().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/dma/dmaengine.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index cd1c0744bfc0..620c5bcff3bf 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -943,12 +943,14 @@ static void dmaenginem_release_channel(void *chan)

struct dma_chan *devm_dma_request_chan(struct device *dev, const char *name)
{
- struct dma_chan *chan = dma_request_chan(dev, name);
- int ret = 0;
+ struct dma_chan *chan;
+ int ret;

- if (!IS_ERR(chan))
- ret = devm_add_action_or_reset(dev, dmaenginem_release_channel, chan);
+ chan = dma_request_chan(dev, name);
+ if (IS_ERR(chan))
+ return chan;

+ ret = devm_add_action_or_reset(dev, dmaenginem_release_channel, chan);
if (ret)
return ERR_PTR(ret);

--
2.50.1