From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Vinod Koul <vkoul@kernel.org>
Subject: [PATCH v1 2/4] dmaengine: Refactor devm_dma_request_chan() for readability
Date: Sun, 9 Nov 2025 23:28:35 +0100 [thread overview]
Message-ID: <20251109222944.3222436-3-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20251109222944.3222436-1-andriy.shevchenko@linux.intel.com>
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
next prev parent reply other threads:[~2025-11-09 22:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-09 22:28 [PATCH v1 0/4] dmaengine; A little cleanup and refactoring Andy Shevchenko
2025-11-09 22:28 ` [PATCH v1 1/4] dmaengine: Use dma_request_channel() instead of __dma_request_channel() Andy Shevchenko
2025-11-09 22:28 ` Andy Shevchenko [this message]
2025-11-09 22:28 ` [PATCH v1 3/4] dmaengine: Use device_match_of_node() helper Andy Shevchenko
2025-11-09 22:28 ` [PATCH v1 4/4] dmaengine: Sort headers alphabetically Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251109222944.3222436-3-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=dmaengine@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox