Clean up some irqdomain code to make it more readable.
Jinjie Ruan (5):
genirq/irqdomain: Clean up for irq_create_fwspec_mapping()
genirq/irqdomain: Simplify the checks for irq_default_domain
genirq/irqdomain: Clean code for irq_create_direct_mapping()
genirq/irqdomain: Simplify the checks for irq_domain_push/pop_irq()
genirq/irqdomain: Clean up for irq_domain_xlate_*
kernel/irq/irqdomain.c | 168 +++++++++++++++++++++--------------------
1 file changed, 85 insertions(+), 83 deletions(-)
--
2.34.1
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 <[email protected]>
---
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
Add "out" goto label for irq_domain_update_bus_token(), and
"out_free_desc" goto label for irq_create_direct_mapping(), which can
simplify the code.
Signed-off-by: Jinjie Ruan <[email protected]>
---
kernel/irq/irqdomain.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index 42bdbd04bc3c..6d8a368c677b 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -317,10 +317,8 @@ void irq_domain_update_bus_token(struct irq_domain *domain,
domain->bus_token = bus_token;
name = kasprintf(GFP_KERNEL, "%s-%d", domain->name, bus_token);
- if (!name) {
- mutex_unlock(&irq_domain_mutex);
- return;
- }
+ if (!name)
+ goto out;
debugfs_remove_domain_dir(domain);
@@ -332,6 +330,7 @@ void irq_domain_update_bus_token(struct irq_domain *domain,
domain->name = name;
debugfs_add_domain_dir(domain);
+out:
mutex_unlock(&irq_domain_mutex);
}
EXPORT_SYMBOL_GPL(irq_domain_update_bus_token);
@@ -672,17 +671,18 @@ unsigned int irq_create_direct_mapping(struct irq_domain *domain)
if (virq >= domain->hwirq_max) {
pr_err("ERROR: no free irqs available below %lu maximum\n",
domain->hwirq_max);
- irq_free_desc(virq);
- return 0;
+ goto out_free_desc;
}
pr_debug("create_direct obtained virq %d\n", virq);
- if (irq_domain_associate(domain, virq, virq)) {
- irq_free_desc(virq);
- return 0;
- }
+ if (irq_domain_associate(domain, virq, virq))
+ goto out_free_desc;
return virq;
+
+out_free_desc:
+ irq_free_desc(virq);
+ return 0;
}
EXPORT_SYMBOL_GPL(irq_create_direct_mapping);
#endif
--
2.34.1