dmaengine.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] dmaengine: A little cleanup and refactoring
@ 2025-11-10  8:47 Andy Shevchenko
  2025-11-10  8:47 ` [PATCH v2 1/3] dmaengine: Refactor devm_dma_request_chan() for readability Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Andy Shevchenko @ 2025-11-10  8:47 UTC (permalink / raw)
  To: Andy Shevchenko, dmaengine, linux-kernel; +Cc: Vinod Koul

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

-- 
2.50.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/3] dmaengine: Refactor devm_dma_request_chan() for readability
  2025-11-10  8:47 [PATCH v2 0/3] dmaengine: A little cleanup and refactoring Andy Shevchenko
@ 2025-11-10  8:47 ` Andy Shevchenko
  2025-11-10  8:47 ` [PATCH v2 2/3] dmaengine: Use device_match_of_node() helper Andy Shevchenko
  2025-11-10  8:47 ` [PATCH v2 3/3] dmaengine: Sort headers alphabetically Andy Shevchenko
  2 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2025-11-10  8:47 UTC (permalink / raw)
  To: Andy Shevchenko, dmaengine, linux-kernel; +Cc: Vinod Koul

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 ca13cd39330b..eb27a72cd4c5 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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/3] dmaengine: Use device_match_of_node() helper
  2025-11-10  8:47 [PATCH v2 0/3] dmaengine: A little cleanup and refactoring Andy Shevchenko
  2025-11-10  8:47 ` [PATCH v2 1/3] dmaengine: Refactor devm_dma_request_chan() for readability Andy Shevchenko
@ 2025-11-10  8:47 ` Andy Shevchenko
  2025-11-10 10:20   ` Praveen Kumar
  2025-11-10  8:47 ` [PATCH v2 3/3] dmaengine: Sort headers alphabetically Andy Shevchenko
  2 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2025-11-10  8:47 UTC (permalink / raw)
  To: Andy Shevchenko, dmaengine, linux-kernel; +Cc: Vinod Koul

Instead of open coding, use device_match_of_node() helper.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/dma/dmaengine.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index eb27a72cd4c5..e89280587d5d 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -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);
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 3/3] dmaengine: Sort headers alphabetically
  2025-11-10  8:47 [PATCH v2 0/3] dmaengine: A little cleanup and refactoring Andy Shevchenko
  2025-11-10  8:47 ` [PATCH v2 1/3] dmaengine: Refactor devm_dma_request_chan() for readability Andy Shevchenko
  2025-11-10  8:47 ` [PATCH v2 2/3] dmaengine: Use device_match_of_node() helper Andy Shevchenko
@ 2025-11-10  8:47 ` Andy Shevchenko
  2 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2025-11-10  8:47 UTC (permalink / raw)
  To: Andy Shevchenko, dmaengine, linux-kernel; +Cc: Vinod Koul

For better maintenance sort headers alphabetically.

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

diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index e89280587d5d..5bc38424398b 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -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"
 
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/3] dmaengine: Use device_match_of_node() helper
  2025-11-10  8:47 ` [PATCH v2 2/3] dmaengine: Use device_match_of_node() helper Andy Shevchenko
@ 2025-11-10 10:20   ` Praveen Kumar
  2025-11-10 10:43     ` Andy Shevchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Praveen Kumar @ 2025-11-10 10:20 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: dmaengine, linux-kernel, Vinod Koul

On Mon, Nov 10, 2025 at 09:47:44AM +0100, Andy Shevchenko wrote:
> Instead of open coding, use device_match_of_node() helper.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/dma/dmaengine.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index eb27a72cd4c5..e89280587d5d 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -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.

>  			continue;
>  
>  		chan = find_candidate(device, mask, fn, fn_param);
> -- 
> 2.50.1
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/3] dmaengine: Use device_match_of_node() helper
  2025-11-10 10:20   ` Praveen Kumar
@ 2025-11-10 10:43     ` Andy Shevchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2025-11-10 10:43 UTC (permalink / raw)
  To: Praveen Kumar; +Cc: dmaengine, linux-kernel, Vinod Koul

On Mon, Nov 10, 2025 at 11:20:33AM +0100, Praveen Kumar wrote:
> On Mon, Nov 10, 2025 at 09:47:44AM +0100, Andy Shevchenko wrote:
> > Instead of open coding, use device_match_of_node() helper.

...

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

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

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-11-10 10:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-10  8:47 [PATCH v2 0/3] dmaengine: A little cleanup and refactoring Andy Shevchenko
2025-11-10  8:47 ` [PATCH v2 1/3] dmaengine: Refactor devm_dma_request_chan() for readability Andy Shevchenko
2025-11-10  8:47 ` [PATCH v2 2/3] dmaengine: Use device_match_of_node() helper Andy Shevchenko
2025-11-10 10:20   ` Praveen Kumar
2025-11-10 10:43     ` Andy Shevchenko
2025-11-10  8:47 ` [PATCH v2 3/3] dmaengine: Sort headers alphabetically Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).