Skip to contentSkip to conversation

dmaengine; A little cleanup and refactoring

PATCH Superseded Andy Shevchenko 2 participants 8 messages Nov 9, 2025 – Nov 10, 2025 dmaengine

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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.

Andy Shevchenko (4):
dmaengine: Use dma_request_channel() instead of

    __dma_request_channel()

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

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

PATCH 1/4 dmaengine: Use dma_request_channel() instead of __dma_request_channel()

Reduce use of internal __dma_request_channel() function.

---
 drivers/dma/dmaengine.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/dmaengine.c +1 -1
index ca13cd39330b..cd1c0744bfc0 100644
@@ -886,7 +886,7 @@ struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask)
 	if (!mask)
 		return ERR_PTR(-ENODEV);
 
-	chan = __dma_request_channel(mask, NULL, NULL, NULL);
+	chan = dma_request_channel(mask, NULL, NULL);
 	if (!chan) {
 		mutex_lock(&dma_list_mutex);
 		if (list_empty(&dma_device_list))
Signature · 1 line
2.50.1
#2 lore raw

Re: [PATCH v1 1/4] dmaengine: Use dma_request_channel() instead of __dma_request_channel()

kernel test robot noticed the following build errors:

Hi Andy,

kernel test robot noticed the following build errors:

[auto build test ERROR on vkoul-dmaengine/next]
[also build test ERROR on linus/master v6.18-rc5 next-20251107] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/dmaengine-Use-dma_request_channel-instead-of-__dma_request_channel/20251110-063117
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vkoul/dmaengine.git next
patch link:    https://lore.kernel.org/r/20251109222944.3222436-2-andriy.shevchenko%40linux.intel.com
patch subject: [PATCH v1 1/4] dmaengine: Use dma_request_channel() instead of __dma_request_channel()
config: s390-randconfig-001-20251110 (https://download.01.org/0day-ci/archive/20251110/[email protected]/config)
compiler: s390-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251110/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from drivers/dma/dmaengine.c:40:
drivers/dma/dmaengine.c: In function 'dma_request_chan_by_mask':

>> include/linux/dmaengine.h:1627:24: error: passing argument 1 of '__dma_request_channel' from incompatible pointer type [-Werror=incompatible-pointer-types]
     __dma_request_channel(&(mask), x, y, NULL)
                           ^~~~~~~
   drivers/dma/dmaengine.c:889:9: note: in expansion of macro 'dma_request_channel'
     chan = dma_request_channel(mask, NULL, NULL);
            ^~~~~~~~~~~~~~~~~~~

drivers/dma/dmaengine.c:757:62: note: expected 'const dma_cap_mask_t *' {aka 'const struct <anonymous> *'} but argument is of type 'const dma_cap_mask_t **' {aka 'const struct <anonymous> **'}
struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
~~~~~~~~~~~~~~~~~~~~~~^~~~
cc1: some warnings being treated as errors

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for OF_GPIO
Depends on [n]: GPIOLIB [=y] && OF [=y] && HAS_IOMEM [=n]
Selected by [y]:
- REGULATOR_RT5133 [=y] && REGULATOR [=y] && I2C [=y] && GPIOLIB [=y] && OF [=y]

vim +/__dma_request_channel +1627 include/linux/dmaengine.h

c13c8260da3155 Chris Leech     2006-05-23  1616  
c13c8260da3155 Chris Leech     2006-05-23  1617  int dma_async_device_register(struct dma_device *device);
f39b948dbeaf9d Huang Shijie    2018-07-26  1618  int dmaenginem_async_device_register(struct dma_device *device);
c13c8260da3155 Chris Leech     2006-05-23  1619  void dma_async_device_unregister(struct dma_device *device);
e81274cd6b5264 Dave Jiang      2020-01-21  1620  int dma_async_device_channel_register(struct dma_device *device,
10b8e0fd3f7234 Amelie Delaunay 2024-05-31  1621  				      struct dma_chan *chan,
10b8e0fd3f7234 Amelie Delaunay 2024-05-31  1622  				      const char *name);
e81274cd6b5264 Dave Jiang      2020-01-21  1623  void dma_async_device_channel_unregister(struct dma_device *device,
e81274cd6b5264 Dave Jiang      2020-01-21  1624  					 struct dma_chan *chan);
07f2211e4fbce6 Dan Williams    2009-01-05  1625  void dma_run_dependencies(struct dma_async_tx_descriptor *tx);
f5151311c3f37f Baolin Wang     2019-05-20  1626  #define dma_request_channel(mask, x, y) \

f5151311c3f37f Baolin Wang 2019-05-20 @1627 __dma_request_channel(&(mask), x, y, NULL)
864ef69b2d9b34 Matt Porter 2013-02-01 1628

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw

Re: [PATCH v1 1/4] dmaengine: Use dma_request_channel() instead of __dma_request_channel()

Quoted 18 lines · kernel test robot

Hi Andy,

kernel test robot noticed the following build errors:

[auto build test ERROR on vkoul-dmaengine/next]
[also build test ERROR on linus/master v6.18-rc5 next-20251107] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/dmaengine-Use-dma_request_channel-instead-of-__dma_request_channel/20251110-063117
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vkoul/dmaengine.git next
patch link:    https://lore.kernel.org/r/20251109222944.3222436-2-andriy.shevchenko%40linux.intel.com
patch subject: [PATCH v1 1/4] dmaengine: Use dma_request_channel() instead of __dma_request_channel()
config: s390-randconfig-001-20251110 (https://download.01.org/0day-ci/archive/20251110/[email protected]/config)
compiler: s390-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251110/[email protected]/reproduce)
Quoted 6 lines

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

Wow, what did I have compile? Seems something different. I will fix this in v2.

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

Re: [PATCH v1 1/4] dmaengine: Use dma_request_channel() instead of __dma_request_channel()

In reply to Andy Shevchenko
kernel test robot noticed the following build errors:

Hi Andy,

kernel test robot noticed the following build errors:

[auto build test ERROR on vkoul-dmaengine/next]
[also build test ERROR on linus/master v6.18-rc5 next-20251110] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/dmaengine-Use-dma_request_channel-instead-of-__dma_request_channel/20251110-063117
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vkoul/dmaengine.git next
patch link:    https://lore.kernel.org/r/20251109222944.3222436-2-andriy.shevchenko%40linux.intel.com
patch subject: [PATCH v1 1/4] dmaengine: Use dma_request_channel() instead of __dma_request_channel()
config: powerpc-randconfig-002-20251111 (https://download.01.org/0day-ci/archive/20251111/[email protected]/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 996639d6ebb86ff15a8c99b67f1c2e2117636ae7)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251111/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/dma/dmaengine.c:889:9: error: incompatible pointer types passing 'const dma_cap_mask_t **' to parameter of type 'const dma_cap_mask_t *'; remove & [-Wincompatible-pointer-types]
     889 |         chan = dma_request_channel(mask, NULL, NULL);
         |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/dmaengine.h:1627:24: note: expanded from macro 'dma_request_channel'
    1627 |         __dma_request_channel(&(mask), x, y, NULL)
         |                               ^~~~~~~
   drivers/dma/dmaengine.c:786:19: note: passing argument to parameter here
     786 | EXPORT_SYMBOL_GPL(__dma_request_channel);
         |                   ^

1 error generated.

vim +889 drivers/dma/dmaengine.c

875
876 /**
877 * dma_request_chan_by_mask - allocate a channel satisfying certain capabilities
878 * @mask: capabilities that the channel must satisfy
879 *
880 * Returns pointer to appropriate DMA channel on success or an error pointer.
881 */
882 struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask)
883 {
884 struct dma_chan *chan;
885
886 if (!mask)
887 return ERR_PTR(-ENODEV);
888

 > 889		chan = dma_request_channel(mask, NULL, NULL);

890 if (!chan) {
891 mutex_lock(&dma_list_mutex);
892 if (list_empty(&dma_device_list))
893 chan = ERR_PTR(-EPROBE_DEFER);
894 else
895 chan = ERR_PTR(-ENODEV);
896 mutex_unlock(&dma_list_mutex);
897 }
898
899 return chan;
900 }
901 EXPORT_SYMBOL_GPL(dma_request_chan_by_mask);
902

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw

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

In reply to Andy Shevchenko

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 cd1c0744bfc0..620c5bcff3bf 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
#6 lore raw

PATCH 3/4 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 620c5bcff3bf..9e2ce7054e8a 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
#7 lore raw

PATCH 4/4 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 9e2ce7054e8a..6d940c4c0c4e 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