From 6a0f99de1ef44ba8dba77372c5ff42b90d2bfd91 Mon Sep 17 00:00:00 2001
From: "Luis Claudio R. Goncalves" <lgoncalv@redhat.com>
Date: Tue, 25 Feb 2025 18:04:53 -0300
Subject: [PATCH 325/327] rt: fix build issue in at_hdmac

The problem described here is specific to v5.10-rt.

The functions atc_advance_work() and atc_issue_pending(), defined at
drivers/dma/at_hdmac.c, both have a similar statement:

    return spin_unlock_irqrestore(&atchan->lock, flags);

That results in a macro expansion error during build.

This problem is unique to v5.10-rt because of the way spin_unlock_irqrestore()
is defined as a macro at include/linux/spinlock_rt.h.

Newer versions of the PREEMPT_RT patch (v5.15-rt and newer) have
spin_unlock_irqrestore() defined as a function.

Kernels such as v4.19-rt and older are also not affected because they don't
have the two commits below, which implement the statements that trigger the
compiler error:

  1582cc3b4805 dmaengine: at_hdmac: Fix concurrency problems by removing atc_complete_all()
  7078e935b410 dmaengine: at_hdmac: Fix premature completion of desc in issue_pending

It  makes more sense, at the current point in v5.10-rt life cycle, decoupling
the return and spin_unlock_irqrestore() statements instead of backporting
the new definition of spin_unlock_irqrestore() and related bits.

Signed-off-by: Luis Claudio R. Goncalves <lgoncalv@redhat.com>
---
 drivers/dma/at_hdmac.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
index 6a4f9697b574..bdbd85adeea9 100644
--- a/drivers/dma/at_hdmac.c
+++ b/drivers/dma/at_hdmac.c
@@ -483,8 +483,10 @@ static void atc_advance_work(struct at_dma_chan *atchan)
 	dev_vdbg(chan2dev(&atchan->chan_common), "advance_work\n");
 
 	spin_lock_irqsave(&atchan->lock, flags);
-	if (atc_chan_is_enabled(atchan) || list_empty(&atchan->active_list))
-		return spin_unlock_irqrestore(&atchan->lock, flags);
+	if (atc_chan_is_enabled(atchan) || list_empty(&atchan->active_list)) {
+		spin_unlock_irqrestore(&atchan->lock, flags);
+		return;
+	}
 
 	desc = atc_first_active(atchan);
 	/* Remove the transfer node from the active list. */
@@ -1477,8 +1479,10 @@ static void atc_issue_pending(struct dma_chan *chan)
 	dev_vdbg(chan2dev(chan), "issue_pending\n");
 
 	spin_lock_irqsave(&atchan->lock, flags);
-	if (atc_chan_is_enabled(atchan) || list_empty(&atchan->queue))
-		return spin_unlock_irqrestore(&atchan->lock, flags);
+	if (atc_chan_is_enabled(atchan) || list_empty(&atchan->queue)) {
+		spin_unlock_irqrestore(&atchan->lock, flags);
+		return;
+	}
 
 	desc = atc_first_queued(atchan);
 	list_move_tail(&desc->desc_node, &atchan->active_list);
-- 
2.49.0

