From: Frank Li <Frank.li@nxp.com>
To: Binbin Zhou <zhoubinbin@loongson.cn>
Cc: Binbin Zhou <zhoubb.aaron@gmail.com>,
Huacai Chen <chenhuacai@loongson.cn>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>, Vinod Koul <vkoul@kernel.org>,
Frank Li <Frank.Li@kernel.org>,
dmaengine@vger.kernel.org, Huacai Chen <chenhuacai@kernel.org>,
Xuerui Wang <kernel@xen0n.name>,
loongarch@lists.linux.dev, devicetree@vger.kernel.org,
Keguang Zhang <keguang.zhang@gmail.com>,
linux-mips@vger.kernel.org
Subject: Re: [PATCH v3 4/6] dmaengine: loongson: loongson2-apb: Simplify locking with guard() and scoped_guard()
Date: Wed, 25 Feb 2026 13:06:45 -0500 [thread overview]
Message-ID: <aZ86NVKUpn3TV6Xi@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <004809811f510b067f1a3cda2155386db3b4275e.1771989596.git.zhoubinbin@loongson.cn>
On Wed, Feb 25, 2026 at 03:41:09PM +0800, Binbin Zhou wrote:
> Use guard() and scoped_guard() infrastructure instead of explicitly
> acquiring and releasing spinlocks to simplify the code and ensure that
> all locks are released properly.
>
> Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> drivers/dma/loongson/loongson2-apb-dma.c | 62 +++++++++++-------------
> 1 file changed, 29 insertions(+), 33 deletions(-)
>
> diff --git a/drivers/dma/loongson/loongson2-apb-dma.c b/drivers/dma/loongson/loongson2-apb-dma.c
> index adddfafc2f1c..aceb069e71fc 100644
> --- a/drivers/dma/loongson/loongson2-apb-dma.c
> +++ b/drivers/dma/loongson/loongson2-apb-dma.c
> @@ -461,12 +461,11 @@ static int ls2x_dma_slave_config(struct dma_chan *chan,
> static void ls2x_dma_issue_pending(struct dma_chan *chan)
> {
> struct ls2x_dma_chan *lchan = to_ldma_chan(chan);
> - unsigned long flags;
>
> - spin_lock_irqsave(&lchan->vchan.lock, flags);
> + guard(spinlock_irqsave)(&lchan->vchan.lock);
> +
> if (vchan_issue_pending(&lchan->vchan) && !lchan->desc)
> ls2x_dma_start_transfer(lchan);
> - spin_unlock_irqrestore(&lchan->vchan.lock, flags);
> }
>
> /*
> @@ -478,19 +477,18 @@ static void ls2x_dma_issue_pending(struct dma_chan *chan)
> static int ls2x_dma_terminate_all(struct dma_chan *chan)
> {
> struct ls2x_dma_chan *lchan = to_ldma_chan(chan);
> - unsigned long flags;
> LIST_HEAD(head);
>
> - spin_lock_irqsave(&lchan->vchan.lock, flags);
> - /* Setting stop cmd */
> - ls2x_dma_write_cmd(lchan, LDMA_STOP);
> - if (lchan->desc) {
> - vchan_terminate_vdesc(&lchan->desc->vdesc);
> - lchan->desc = NULL;
> - }
> + scoped_guard(spinlock_irqsave, &lchan->vchan.lock) {
> + /* Setting stop cmd */
> + ls2x_dma_write_cmd(lchan, LDMA_STOP);
> + if (lchan->desc) {
> + vchan_terminate_vdesc(&lchan->desc->vdesc);
> + lchan->desc = NULL;
> + }
>
> - vchan_get_all_descriptors(&lchan->vchan, &head);
> - spin_unlock_irqrestore(&lchan->vchan.lock, flags);
> + vchan_get_all_descriptors(&lchan->vchan, &head);
> + }
>
> vchan_dma_desc_free_list(&lchan->vchan, &head);
> return 0;
> @@ -511,14 +509,13 @@ static void ls2x_dma_synchronize(struct dma_chan *chan)
> static int ls2x_dma_pause(struct dma_chan *chan)
> {
> struct ls2x_dma_chan *lchan = to_ldma_chan(chan);
> - unsigned long flags;
>
> - spin_lock_irqsave(&lchan->vchan.lock, flags);
> + guard(spinlock_irqsave)(&lchan->vchan.lock);
> +
> if (lchan->desc && lchan->desc->status == DMA_IN_PROGRESS) {
> ls2x_dma_write_cmd(lchan, LDMA_STOP);
> lchan->desc->status = DMA_PAUSED;
> }
> - spin_unlock_irqrestore(&lchan->vchan.lock, flags);
>
> return 0;
> }
> @@ -526,14 +523,13 @@ static int ls2x_dma_pause(struct dma_chan *chan)
> static int ls2x_dma_resume(struct dma_chan *chan)
> {
> struct ls2x_dma_chan *lchan = to_ldma_chan(chan);
> - unsigned long flags;
>
> - spin_lock_irqsave(&lchan->vchan.lock, flags);
> + guard(spinlock_irqsave)(&lchan->vchan.lock);
> +
> if (lchan->desc && lchan->desc->status == DMA_PAUSED) {
> lchan->desc->status = DMA_IN_PROGRESS;
> ls2x_dma_write_cmd(lchan, LDMA_START);
> }
> - spin_unlock_irqrestore(&lchan->vchan.lock, flags);
>
> return 0;
> }
> @@ -550,22 +546,22 @@ static irqreturn_t ls2x_dma_isr(int irq, void *dev_id)
> struct ls2x_dma_chan *lchan = dev_id;
> struct ls2x_dma_desc *desc;
>
> - spin_lock(&lchan->vchan.lock);
> - desc = lchan->desc;
> - if (desc) {
> - if (desc->cyclic) {
> - vchan_cyclic_callback(&desc->vdesc);
> - } else {
> - desc->status = DMA_COMPLETE;
> - vchan_cookie_complete(&desc->vdesc);
> - ls2x_dma_start_transfer(lchan);
> + scoped_guard(spinlock, &lchan->vchan.lock) {
> + desc = lchan->desc;
> + if (desc) {
> + if (desc->cyclic) {
> + vchan_cyclic_callback(&desc->vdesc);
> + } else {
> + desc->status = DMA_COMPLETE;
> + vchan_cookie_complete(&desc->vdesc);
> + ls2x_dma_start_transfer(lchan);
> + }
> +
> + /* ls2x_dma_start_transfer() updates lchan->desc */
> + if (!lchan->desc)
> + ls2x_dma_write_cmd(lchan, LDMA_STOP);
> }
> -
> - /* ls2x_dma_start_transfer() updates lchan->desc */
> - if (!lchan->desc)
> - ls2x_dma_write_cmd(lchan, LDMA_STOP);
> }
> - spin_unlock(&lchan->vchan.lock);
>
> return IRQ_HANDLED;
> }
> --
> 2.52.0
>
next prev parent reply other threads:[~2026-02-25 18:06 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-25 7:40 [PATCH v3 0/6] dmaengine: Add Loongson Multi-Channel DMA controller support Binbin Zhou
2026-02-25 7:40 ` [PATCH v3 1/6] dmaengine: loongson: New directory for Loongson DMA controllers drivers Binbin Zhou
2026-02-25 18:04 ` Frank Li
2026-02-25 7:40 ` [PATCH v3 2/6] dmaengine: loongson: loongson2-apb: Convert to dmaenginem_async_device_register() Binbin Zhou
2026-02-25 7:40 ` [PATCH v3 3/6] dmaengine: loongson: loongson2-apb: Convert to devm_clk_get_enabled() Binbin Zhou
2026-02-25 18:05 ` Frank Li
2026-02-25 7:41 ` [PATCH v3 4/6] dmaengine: loongson: loongson2-apb: Simplify locking with guard() and scoped_guard() Binbin Zhou
2026-02-25 18:06 ` Frank Li [this message]
2026-02-25 7:41 ` [PATCH v3 5/6] dt-bindings: dmaengine: Add Loongson Multi-Channel DMA controller Binbin Zhou
2026-03-06 0:52 ` Rob Herring (Arm)
2026-02-25 7:41 ` [PATCH v3 6/6] dmaengine: loongson: New driver for the " Binbin Zhou
2026-02-25 20:00 ` Frank Li
2026-02-26 8:18 ` Huacai Chen
2026-03-09 7:10 ` Vinod Koul
2026-03-09 8:05 ` Binbin Zhou
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=aZ86NVKUpn3TV6Xi@lizhi-Precision-Tower-5810 \
--to=frank.li@nxp.com \
--cc=Frank.Li@kernel.org \
--cc=chenhuacai@kernel.org \
--cc=chenhuacai@loongson.cn \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=keguang.zhang@gmail.com \
--cc=kernel@xen0n.name \
--cc=krzk+dt@kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=robh@kernel.org \
--cc=vkoul@kernel.org \
--cc=zhoubb.aaron@gmail.com \
--cc=zhoubinbin@loongson.cn \
/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