From: Sanjay Chitroda <sanjayembeddedse@gmail.com>
To: Maxwell Doose <m32285159@gmail.com>,
salih.erim@amd.com, conall.ogriofa@amd.com, jic23@kernel.org,
michal.simek@amd.com
Cc: "David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] iio: adc: xilinx-ams: Replace spin_lock() and unlock() calls with guard(spinlock*)()
Date: Sat, 09 May 2026 00:19:46 +0530 [thread overview]
Message-ID: <F98D1BE6-7B28-4A36-A372-2431EA151E1E@gmail.com> (raw)
In-Reply-To: <20260508124513.17752-1-m32285159@gmail.com>
On 8 May 2026 6:15:13 pm IST, Maxwell Doose <m32285159@gmail.com> wrote:
>Include linux/cleanup.h to take advantage of RAII macros.
>
>Replace spin_lock() and unlock() calls with their RAII macro
>counterparts, which modernizes the code and increases readability.
>
>Remove "flags" variables where spin_lock_irqsave() has been replaced
>with guard(spinlock_irqsave)().
>
>Signed-off-by: Maxwell Doose <m32285159@gmail.com>
>---
> v2:
> - Replace guard(spinlock_irq)() in ams_unmask_worker() with
> scoped_guard() per Jonathan's suggestion.
>
> drivers/iio/adc/xilinx-ams.c | 20 +++++++-------------
> 1 file changed, 7 insertions(+), 13 deletions(-)
>
>diff --git a/drivers/iio/adc/xilinx-ams.c b/drivers/iio/adc/xilinx-ams.c
>index 124470c92529..05bf1444ca7d 100644
>--- a/drivers/iio/adc/xilinx-ams.c
>+++ b/drivers/iio/adc/xilinx-ams.c
>@@ -10,6 +10,7 @@
>
> #include <linux/bits.h>
> #include <linux/bitfield.h>
>+#include <linux/cleanup.h>
> #include <linux/clk.h>
> #include <linux/delay.h>
> #include <linux/devm-helpers.h>
>@@ -414,18 +415,16 @@ static void ams_unmask(struct ams *ams)
>
> static void ams_update_alarm(struct ams *ams, unsigned long alarm_mask)
> {
>- unsigned long flags;
>-
> if (ams->ps_base)
> ams_update_ps_alarm(ams, alarm_mask);
>
> if (ams->pl_base)
> ams_update_pl_alarm(ams, alarm_mask);
>
>- spin_lock_irqsave(&ams->intr_lock, flags);
>+ guard(spinlock_irqsave)(&ams->intr_lock);
>+
> ams_update_intrmask(ams, AMS_ISR0_ALARM_MASK, ~alarm_mask);
> ams_unmask(ams);
>- spin_unlock_irqrestore(&ams->intr_lock, flags);
> }
>
> static void ams_enable_channel_sequence(struct iio_dev *indio_dev)
>@@ -1060,9 +1059,8 @@ static void ams_unmask_worker(struct work_struct *work)
> {
> struct ams *ams = container_of(work, struct ams, ams_unmask_work.work);
>
>- spin_lock_irq(&ams->intr_lock);
>- ams_unmask(ams);
>- spin_unlock_irq(&ams->intr_lock);
>+ scoped_guard(spinlock_irq, &ams->intr_lock)
>+ ams_unmask(ams);
>
> /* If still pending some alarm re-trigger the timer */
> if (ams->current_masked_alarm)
>@@ -1076,16 +1074,14 @@ static irqreturn_t ams_irq(int irq, void *data)
> struct ams *ams = iio_priv(indio_dev);
> u32 isr0;
>
>- spin_lock(&ams->intr_lock);
>+ guard(spinlock)(&ams->intr_lock);
>
> isr0 = readl(ams->base + AMS_ISR_0);
>
> /* Only process alarms that are not masked */
> isr0 &= ~((ams->intr_mask & AMS_ISR0_ALARM_MASK) | ams->current_masked_alarm);
>- if (!isr0) {
>- spin_unlock(&ams->intr_lock);
>+ if (!isr0)
> return IRQ_NONE;
>- }
>
> /* Clear interrupt */
> writel(isr0, ams->base + AMS_ISR_0);
>@@ -1099,8 +1095,6 @@ static irqreturn_t ams_irq(int irq, void *data)
> schedule_delayed_work(&ams->ams_unmask_work,
> msecs_to_jiffies(AMS_UNMASK_TIMEOUT_MS));
>
>- spin_unlock(&ams->intr_lock);
>-
> return IRQ_HANDLED;
>
Hi Maxwell,
Thanks for the resource cleanup change.
Overall looks good.
Also, there is opportunity for guard(mutex)().
Thanks,
Sanjay Chitroda
>
next prev parent reply other threads:[~2026-05-08 18:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 12:45 [PATCH v2] iio: adc: xilinx-ams: Replace spin_lock() and unlock() calls with guard(spinlock*)() Maxwell Doose
2026-05-08 18:49 ` Sanjay Chitroda [this message]
2026-05-08 18:53 ` Maxwell Doose
2026-05-10 9:24 ` Andy Shevchenko
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=F98D1BE6-7B28-4A36-A372-2431EA151E1E@gmail.com \
--to=sanjayembeddedse@gmail.com \
--cc=andy@kernel.org \
--cc=conall.ogriofa@amd.com \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m32285159@gmail.com \
--cc=michal.simek@amd.com \
--cc=nuno.sa@analog.com \
--cc=salih.erim@amd.com \
/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