Skip to contentSkip to conversation

dmaengine: A little cleanup and refactoring

PATCH Applied Andy Shevchenko 3 participants 10 messages Nov 10, 2025 – Feb 25 dmaengine

v2 of 3 Applied Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover dmaengine: A little cleanup and refactoring

This just a set of small almost ad-hoc cleanups and refactoring. Nothing special and nothing that changes behaviour.

Changelog v2:
- dropped not very good (and not compilable) change (LKP)

Andy Shevchenko (3):
dmaengine: Refactor devm_dma_request_chan() for readability
dmaengine: Use device_match_of_node() helper
dmaengine: Sort headers alphabetically

 drivers/dma/dmaengine.c | 50 +++++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 24 deletions(-)
Signature · 1 line
2.50.1
#1 lore raw

PATCH v2 1/3 dmaengine: Refactor devm_dma_request_chan() for readability

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().

---
 drivers/dma/dmaengine.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/dma/dmaengine.c +6 -4
index ca13cd39330b..eb27a72cd4c5 100644
@@ -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);
 
Signature · 1 line
2.50.1
#2 lore raw

PATCH v2 2/3 dmaengine: Use device_match_of_node() helper

In reply to Andy Shevchenko

Instead of open coding, use device_match_of_node() helper.

---
 drivers/dma/dmaengine.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/dmaengine.c +1 -1
index eb27a72cd4c5..e89280587d5d 100644
@@ -765,7 +765,7 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
 	mutex_lock(&dma_list_mutex);
 	list_for_each_entry_safe(device, _d, &dma_device_list, global_node) {
 		/* Finds a DMA controller with matching device node */
-		if (np && device->dev->of_node && np != device->dev->of_node)
+		if (np && !device_match_of_node(device->dev, np))
 			continue;
 
 		chan = find_candidate(device, mask, fn, fn_param);
Signature · 1 line
2.50.1
#3 lore raw

Re: [PATCH v2 2/3] dmaengine: Use device_match_of_node() helper

Quoted 12 lines · Andy Shevchenko

Instead of open coding, use device_match_of_node() helper.

---
 drivers/dma/dmaengine.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/dmaengine.c +0 -0
index eb27a72cd4c5..e89280587d5d 100644

drivers/dma/dmaengine.c struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask, · line 768

Quoted 5 lines
drivers/dma/dmaengine.c +1 -1
@@ -765,7 +765,7 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
 	mutex_lock(&dma_list_mutex);
 	list_for_each_entry_safe(device, _d, &dma_device_list, global_node) {
 		/* Finds a DMA controller with matching device node */
-		if (np && device->dev->of_node && np != device->dev->of_node)
+		if (np && !device_match_of_node(device->dev, np))

I see a difference in what device_match_of_node does vs what was happening in the previous check. And, we have an unwanted double check of np.

int device_match_of_node(struct device *dev, const void *np)

{
        return np && dev->of_node == np;
}

Instead, I would recommend,

        if (device->dev->of_node && !device_match_of_node(device->dev, np))
                continue;

Regards,
Praveen Kumar.

Quoted 6 lines
drivers/dma/dmaengine.c +0 -0
 			continue;
 
 		chan = find_candidate(device, mask, fn, fn_param);
Signature · 1 line
2.50.1
#4 lore raw

Re: [PATCH v2 2/3] dmaengine: Use device_match_of_node() helper

Quoted 2 lines · Praveen Kumar
Quoted 1 line · Andy Shevchenko

Instead of open coding, use device_match_of_node() helper.

...

Quoted 6 lines

drivers/dma/dmaengine.c struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask, · line 768

Quoted 2 lines
drivers/dma/dmaengine.c +1 -1
-		if (np && device->dev->of_node && np != device->dev->of_node)
+		if (np && !device_match_of_node(device->dev, np))

I see a difference in what device_match_of_node does vs what was happening in the previous check. And, we have an unwanted double check of np.

Nope.

Quoted 9 lines

int device_match_of_node(struct device *dev, const void *np)

{
        return np && dev->of_node == np;
}

Instead, I would recommend,

        if (device->dev->of_node && !device_match_of_node(device->dev, np))
                continue;

This will be the wrong check. Think about it, yeah, it's not so trivial check and hence the change.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

PATCH v2 3/3 dmaengine: Sort headers alphabetically

In reply to Andy Shevchenko

For better maintenance sort headers alphabetically.

---
 drivers/dma/dmaengine.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)
drivers/dma/dmaengine.c +19 -19
index e89280587d5d..5bc38424398b 100644
@@ -31,29 +31,29 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
-#include <linux/platform_device.h>
-#include <linux/dma-mapping.h>
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/mm.h>
-#include <linux/device.h>
-#include <linux/dmaengine.h>
-#include <linux/hardirq.h>
-#include <linux/spinlock.h>
-#include <linux/of.h>
-#include <linux/property.h>
-#include <linux/percpu.h>
-#include <linux/rcupdate.h>
-#include <linux/mutex.h>
-#include <linux/jiffies.h>
-#include <linux/rculist.h>
-#include <linux/idr.h>
-#include <linux/slab.h>
 #include <linux/acpi.h>
 #include <linux/acpi_dma.h>
-#include <linux/of_dma.h>
+#include <linux/device.h>
+#include <linux/dma-mapping.h>
+#include <linux/dmaengine.h>
+#include <linux/hardirq.h>
+#include <linux/idr.h>
+#include <linux/init.h>
+#include <linux/jiffies.h>
 #include <linux/mempool.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/numa.h>
+#include <linux/of.h>
+#include <linux/of_dma.h>
+#include <linux/percpu.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/rculist.h>
+#include <linux/rcupdate.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
 
 #include "dmaengine.h"
 
Signature · 1 line
2.50.1
#6 lore raw
In reply to Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

This just a set of small almost ad-hoc cleanups and refactoring. Nothing special and nothing that changes behaviour.

Any comments on this series?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#7 lore raw
Quoted 5 lines · Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

This just a set of small almost ad-hoc cleanups and refactoring. Nothing special and nothing that changes behaviour.

Any comments on this series?

Looks good mostly, seems to have a small checkpatch error, pls fix that and update

Signature · 1 line
~Vinod
#8 lore raw
Quoted 9 lines · Vinod Koul
Quoted 5 lines · Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

This just a set of small almost ad-hoc cleanups and refactoring. Nothing special and nothing that changes behaviour.

Any comments on this series?

Looks good mostly, seems to have a small checkpatch error, pls fix that and update

Thanks. v3 has just been sent.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Applied
#9 lore raw
In reply to Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

This just a set of small almost ad-hoc cleanups and refactoring. Nothing special and nothing that changes behaviour.

Changelog v2:
- dropped not very good (and not compilable) change (LKP)

Quoted 6 lines

Andy Shevchenko (3):
dmaengine: Refactor devm_dma_request_chan() for readability
dmaengine: Use device_match_of_node() helper
dmaengine: Sort headers alphabetically

[...]

Applied, thanks!

[1/3] dmaengine: Refactor devm_dma_request_chan() for readability

      commit: 4dd56ef8a26190f1735de9dddb854f175adbc6cd
[2/3] dmaengine: Use device_match_of_node() helper
      commit: db4709e19ba3d50ceeba9e01db373f672698ff1f
[3/3] dmaengine: Sort headers alphabetically
      commit: 9a07b4bb2c6019a8c585f48ee9b87fc843840e6e

Best regards,

Signature · 1 line
~Vinod