[PATCH 1/5] genirq/irqdomain: Clean up for irq_create_fwspec_mapping()

From: Jinjie Ruan
Date: Mon May 06 2024 - 09:03:43 EST


In irq_create_fwspec_mapping(), if the hwirq in domain extracted from
fwspec has virq mapping, check the trigger type if they are consistent,
which is a relatively independent function that can be extracted into a
helper function irq_check_trigger_type(), which will make
irq_create_fwspec_mapping() function more readable.

Signed-off-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>
---
kernel/irq/irqdomain.c | 60 ++++++++++++++++++++++++------------------
1 file changed, 34 insertions(+), 26 deletions(-)

diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index aadc8891cc16..baa53a9e0cd1 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -789,6 +789,38 @@ void of_phandle_args_to_fwspec(struct device_node *np, const u32 *args,
}
EXPORT_SYMBOL_GPL(of_phandle_args_to_fwspec);

+static inline int irq_check_trigger_type(struct irq_fwspec *fwspec,
+ int virq, irq_hw_number_t hwirq,
+ unsigned int type)
+{
+ struct irq_data *irq_data;
+
+ /*
+ * If the trigger type is not specified or matches the
+ * current trigger type then we are done so return the
+ * interrupt number.
+ */
+ if (type == IRQ_TYPE_NONE || type == irq_get_trigger_type(virq))
+ return 0;
+
+ /*
+ * If the trigger type has not been set yet, then set
+ * it now and return the interrupt number.
+ */
+ if (irq_get_trigger_type(virq) == IRQ_TYPE_NONE) {
+ irq_data = irq_get_irq_data(virq);
+ if (!irq_data)
+ return -EINVAL;
+
+ irqd_set_trigger_type(irq_data, type);
+ return 0;
+ }
+
+ pr_warn("type mismatch, failed to map hwirq-%lu for %s!\n",
+ hwirq, of_node_full_name(to_of_node(fwspec->fwnode)));
+ return -EINVAL;
+}
+
unsigned int irq_create_fwspec_mapping(struct irq_fwspec *fwspec)
{
struct irq_domain *domain;
@@ -829,32 +861,8 @@ unsigned int irq_create_fwspec_mapping(struct irq_fwspec *fwspec)
*/
virq = irq_find_mapping(domain, hwirq);
if (virq) {
- /*
- * If the trigger type is not specified or matches the
- * current trigger type then we are done so return the
- * interrupt number.
- */
- if (type == IRQ_TYPE_NONE || type == irq_get_trigger_type(virq))
- goto out;
-
- /*
- * If the trigger type has not been set yet, then set
- * it now and return the interrupt number.
- */
- if (irq_get_trigger_type(virq) == IRQ_TYPE_NONE) {
- irq_data = irq_get_irq_data(virq);
- if (!irq_data) {
- virq = 0;
- goto out;
- }
-
- irqd_set_trigger_type(irq_data, type);
- goto out;
- }
-
- pr_warn("type mismatch, failed to map hwirq-%lu for %s!\n",
- hwirq, of_node_full_name(to_of_node(fwspec->fwnode)));
- virq = 0;
+ if (irq_check_trigger_type(fwspec, virq, hwirq, type))
+ virq = 0;
goto out;
}

--
2.34.1