[PATCH 2/2] irqchip/pruss-intc: Use scoped lock guard and devm_mutex_init

From: Andrew Davis

Date: Thu Sep 03 2026 - 14:54:22 EST


Scoped locking simplifies the return path in a spot, and removes
a couple lines in another couple spots. The devm mutex init will
call mutex_destroy() for us on remove, which only really matters
when CONFIG_DEBUG_MUTEXES is set, but it is nice to do anyway.

Signed-off-by: Andrew Davis <afd@xxxxxx>
---
drivers/irqchip/irq-pruss-intc.c | 25 +++++++++----------------
1 file changed, 9 insertions(+), 16 deletions(-)

diff --git a/drivers/irqchip/irq-pruss-intc.c b/drivers/irqchip/irq-pruss-intc.c
index cc3a7c21c2904..5a3e9e5bccbea 100644
--- a/drivers/irqchip/irq-pruss-intc.c
+++ b/drivers/irqchip/irq-pruss-intc.c
@@ -181,7 +181,7 @@ static void pruss_intc_map(struct pruss_intc *intc, unsigned long hwirq)
u8 ch, host, reg_idx;
u32 val;

- mutex_lock(&intc->lock);
+ guard(mutex)(&intc->lock);

intc->event_channel[hwirq].ref_count++;

@@ -206,8 +206,6 @@ static void pruss_intc_map(struct pruss_intc *intc, unsigned long hwirq)

dev_dbg(dev, "mapped system_event = %lu channel = %d host = %d",
hwirq, ch, host);
-
- mutex_unlock(&intc->lock);
}

/**
@@ -224,7 +222,7 @@ static void pruss_intc_unmap(struct pruss_intc *intc, unsigned long hwirq)
u8 ch, host, reg_idx;
u32 val;

- mutex_lock(&intc->lock);
+ guard(mutex)(&intc->lock);

ch = intc->event_channel[hwirq].value;
host = intc->channel_host[ch].value;
@@ -251,8 +249,6 @@ static void pruss_intc_unmap(struct pruss_intc *intc, unsigned long hwirq)

dev_dbg(intc->dev, "unmapped system_event = %lu channel = %d host = %d\n",
hwirq, ch, host);
-
- mutex_unlock(&intc->lock);
}

static void pruss_intc_init(struct pruss_intc *intc)
@@ -376,17 +372,15 @@ static int pruss_intc_validate_mapping(struct pruss_intc *intc, int event,
int channel, int host)
{
struct device *dev = intc->dev;
- int ret = 0;

- mutex_lock(&intc->lock);
+ guard(mutex)(&intc->lock);

/* check if sysevent already assigned */
if (intc->event_channel[event].ref_count > 0 &&
intc->event_channel[event].value != channel) {
dev_err(dev, "event %d (req. ch %d) already assigned to channel %d\n",
event, channel, intc->event_channel[event].value);
- ret = -EBUSY;
- goto unlock;
+ return -EBUSY;
}

/* check if channel already assigned */
@@ -394,16 +388,13 @@ static int pruss_intc_validate_mapping(struct pruss_intc *intc, int event,
intc->channel_host[channel].value != host) {
dev_err(dev, "channel %d (req. host %d) already assigned to host %d\n",
channel, host, intc->channel_host[channel].value);
- ret = -EBUSY;
- goto unlock;
+ return -EBUSY;
}

intc->event_channel[event].value = channel;
intc->channel_host[channel].value = host;

-unlock:
- mutex_unlock(&intc->lock);
- return ret;
+ return 0;
}

static int
@@ -550,7 +541,9 @@ static int pruss_intc_probe(struct platform_device *pdev)

pruss_intc_init(intc);

- mutex_init(&intc->lock);
+ ret = devm_mutex_init(dev, &intc->lock);
+ if (ret)
+ return ret;

intc->domain = irq_domain_create_linear(dev_fwnode(dev), max_system_events,
&pruss_intc_irq_domain_ops, intc);
--
2.39.2