[patch 40/47] genirq: Sanitize dynamic irq handling

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Thomas Gleixner
Date: Thursday, September 30, 2010 - 4:17 pm

Use the cleanup functions of the dynamic allocator. No need to have
separate implementations.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/irq.h    |   12 +++--
 kernel/irq/chip.c      |  104 -------------------------------------------------
 kernel/irq/internals.h |    1 
 kernel/irq/irqdesc.c   |   37 +++++++++++------
 4 files changed, 33 insertions(+), 121 deletions(-)

Index: linux-2.6-tip/include/linux/irq.h
===================================================================
--- linux-2.6-tip.orig/include/linux/irq.h
+++ linux-2.6-tip/include/linux/irq.h
@@ -497,11 +497,15 @@ static inline int irq_has_action(unsigne
 	return desc->action != NULL;
 }
 
-/* Dynamic irq helper functions */
-extern void dynamic_irq_init(unsigned int irq);
-void dynamic_irq_init_keep_chip_data(unsigned int irq);
+/*
+ * Dynamic irq helper functions. Obsolete. Use irq_alloc_desc* and
+ * irq_free_desc instead.
+ */
 extern void dynamic_irq_cleanup(unsigned int irq);
-void dynamic_irq_cleanup_keep_chip_data(unsigned int irq);
+static inline void dynamic_irq_init(unsigned int irq)
+{
+	dynamic_irq_cleanup(irq);
+}
 
 /* Set/get chip/data for an IRQ: */
 extern int set_irq_chip(unsigned int irq, struct irq_chip *chip);
Index: linux-2.6-tip/kernel/irq/chip.c
===================================================================
--- linux-2.6-tip.orig/kernel/irq/chip.c
+++ linux-2.6-tip/kernel/irq/chip.c
@@ -18,110 +18,6 @@
 
 #include "internals.h"
 
-static void dynamic_irq_init_x(unsigned int irq, bool keep_chip_data)
-{
-	struct irq_desc *desc;
-	unsigned long flags;
-
-	desc = irq_to_desc(irq);
-	if (!desc) {
-		WARN(1, KERN_ERR "Trying to initialize invalid IRQ%d\n", irq);
-		return;
-	}
-
-	/* Ensure we don't have left over values from a previous use of this irq */
-	raw_spin_lock_irqsave(&desc->lock, flags);
-	desc->status = IRQ_DEFAULT_INIT_FLAGS;
-	desc->chip = &no_irq_chip;
-	desc->irq_data.chip = &no_irq_chip;
-	desc->handle_irq = handle_bad_irq;
-	desc->depth = 1;
-	desc->irq_data.msi_desc = NULL;
-	desc->irq_data.handler_data = NULL;
-	if (!keep_chip_data)
-		desc->irq_data.chip_data = NULL;
-	desc->action = NULL;
-	desc->irq_count = 0;
-	desc->irqs_unhandled = 0;
-#ifdef CONFIG_SMP
-	cpumask_setall(desc->affinity);
-#ifdef CONFIG_GENERIC_PENDING_IRQ
-	cpumask_clear(desc->pending_mask);
-#endif
-#endif
-	raw_spin_unlock_irqrestore(&desc->lock, flags);
-}
-
-/**
- *	dynamic_irq_init - initialize a dynamically allocated irq
- *	@irq:	irq number to initialize
- */
-void dynamic_irq_init(unsigned int irq)
-{
-	dynamic_irq_init_x(irq, false);
-}
-
-/**
- *	dynamic_irq_init_keep_chip_data - initialize a dynamically allocated irq
- *	@irq:	irq number to initialize
- *
- *	does not set irq_to_desc(irq)->chip_data to NULL
- */
-void dynamic_irq_init_keep_chip_data(unsigned int irq)
-{
-	dynamic_irq_init_x(irq, true);
-}
-
-static void dynamic_irq_cleanup_x(unsigned int irq, bool keep_chip_data)
-{
-	struct irq_desc *desc = irq_to_desc(irq);
-	unsigned long flags;
-
-	if (!desc) {
-		WARN(1, KERN_ERR "Trying to cleanup invalid IRQ%d\n", irq);
-		return;
-	}
-
-	raw_spin_lock_irqsave(&desc->lock, flags);
-	if (desc->action) {
-		raw_spin_unlock_irqrestore(&desc->lock, flags);
-		WARN(1, KERN_ERR "Destroying IRQ%d without calling free_irq\n",
-			irq);
-		return;
-	}
-	desc->irq_data.msi_desc = NULL;
-	desc->irq_data.handler_data = NULL;
-	if (!keep_chip_data)
-		desc->irq_data.chip_data = NULL;
-	desc->handle_irq = handle_bad_irq;
-	desc->chip = &no_irq_chip;
-	desc->irq_data.chip = &no_irq_chip;
-	desc->name = NULL;
-	clear_kstat_irqs(desc);
-	raw_spin_unlock_irqrestore(&desc->lock, flags);
-}
-
-/**
- *	dynamic_irq_cleanup - cleanup a dynamically allocated irq
- *	@irq:	irq number to initialize
- */
-void dynamic_irq_cleanup(unsigned int irq)
-{
-	dynamic_irq_cleanup_x(irq, false);
-}
-
-/**
- *	dynamic_irq_cleanup_keep_chip_data - cleanup a dynamically allocated irq
- *	@irq:	irq number to initialize
- *
- *	does not set irq_to_desc(irq)->chip_data to NULL
- */
-void dynamic_irq_cleanup_keep_chip_data(unsigned int irq)
-{
-	dynamic_irq_cleanup_x(irq, true);
-}
-
-
 /**
  *	set_irq_chip - set the irq chip for an irq
  *	@irq:	irq number
Index: linux-2.6-tip/kernel/irq/internals.h
===================================================================
--- linux-2.6-tip.orig/kernel/irq/internals.h
+++ linux-2.6-tip/kernel/irq/internals.h
@@ -17,7 +17,6 @@ extern void __enable_irq(struct irq_desc
 
 extern struct lock_class_key irq_desc_lock_class;
 extern void init_kstat_irqs(struct irq_desc *desc, int node, int nr);
-extern void clear_kstat_irqs(struct irq_desc *desc);
 extern raw_spinlock_t sparse_irq_lock;
 
 #ifdef CONFIG_SPARSE_IRQ
Index: linux-2.6-tip/kernel/irq/irqdesc.c
===================================================================
--- linux-2.6-tip.orig/kernel/irq/irqdesc.c
+++ linux-2.6-tip/kernel/irq/irqdesc.c
@@ -54,10 +54,13 @@ static void desc_smp_init(struct irq_des
 	desc->node = node;
 	desc->irq_data.affinity = &desc->affinity;
 	cpumask_copy(desc->affinity, irq_default_affinity);
+#ifdef CONFIG_GENERIC_PENDING_IRQ
+	cpumask_clear(desc->pending_mask);
+#endif
 }
-
+static inline int desc_node(struct irq_desc *desc) { return desc->node; }
 #else
-static inline int
+static inline int desc_node(struct irq_desc *desc) { return 0; }
 alloc_masks(struct irq_desc *desc, gfp_t gfp, int node) { return 0; }
 static inline void desc_smp_init(struct irq_desc *desc, int node) { }
 #endif
@@ -72,6 +75,8 @@ static void desc_set_defaults(unsigned i
 	desc->irq_data.chip = &no_irq_chip;
 	desc->handle_irq = handle_bad_irq;
 	desc->depth = 1;
+	desc->irq_count = 0;
+	desc->irqs_unhandled = 0;
 	desc->name = NULL;
 	memset(desc->kstat_irqs, 0, nr_cpu_ids * sizeof(*(desc->kstat_irqs)));
 	desc_smp_init(desc, node);
@@ -136,6 +141,7 @@ static void free_masks(struct irq_desc *
 #endif
 	free_cpumask_var(desc->affinity);
 }
+static int node
 #else
 static inline void free_masks(struct irq_desc *desc) { }
 #endif
@@ -290,16 +296,7 @@ struct irq_desc *irq_to_desc_alloc_node(
 
 static void free_desc(unsigned int irq)
 {
-	struct irq_desc *desc = irq_to_desc(irq);
-	unsigned long flags;
-
-	raw_spin_lock_irqsave(&desc->lock, flags);
-#ifdef CONFIG_SMP
-	desc_set_defaults(irq, desc, desc->node);
-#else
-	desc_set_defaults(irq, desc, 0);
-#endif
-	raw_spin_unlock_irqrestore(&desc->lock, flags);
+	dynamic_irq_cleanup(irq);
 }
 
 static inline int alloc_descs(unsigned int start, unsigned int cnt, int node)
@@ -386,6 +383,22 @@ unsigned int irq_get_next_irq(unsigned i
 	return res;
 }
 
+/**
+ * dynamic_irq_cleanup - cleanup a dynamically allocated irq
+ * @irq:	irq number to initialize
+ */
+void dynamic_irq_cleanup(unsigned int irq)
+{
+	struct irq_desc *desc = irq_to_desc(irq);
+	unsigned long flags;
+
+	raw_spin_lock_irqsave(&desc->lock, flags);
+	desc_set_defaults(irq, desc, desc_node(desc));
+	raw_spin_unlock_irqrestore(&desc->lock, flags);
+}
+
+ unsigned int kstat_irqs_cpu(unsigned int irq, int cpu)
+
 /* Statistics access */
 void clear_kstat_irqs(struct irq_desc *desc)
 {


--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[patch 00/47] Sparse irq rework, Thomas Gleixner, (Thu Sep 30, 4:14 pm)
[patch 01/47] x86: Plug memory leak in sparse irq, Thomas Gleixner, (Thu Sep 30, 4:14 pm)
[patch 03/47] genirq: Provide status modifier, Thomas Gleixner, (Thu Sep 30, 4:14 pm)
[patch 04/47] arm: Use irq status modifier, Thomas Gleixner, (Thu Sep 30, 4:14 pm)
[patch 05/47] genirq-sanitize-irq-data-accessors.patch, Thomas Gleixner, (Thu Sep 30, 4:14 pm)
[patch 06/47] genirq: Distangle kernel/irq/handle.c, Thomas Gleixner, (Thu Sep 30, 4:15 pm)
[patch 07/47] genirq: Remove early_init_irq_lock_class(), Thomas Gleixner, (Thu Sep 30, 4:15 pm)
[patch 08/47] genirq: Move core only inlines to kernel/irq, Thomas Gleixner, (Thu Sep 30, 4:15 pm)
[patch 10/47] genirq: Remove export of kstat_irqs_cpu, Thomas Gleixner, (Thu Sep 30, 4:15 pm)
[patch 11/47] genirq: Provide default irq init flags, Thomas Gleixner, (Thu Sep 30, 4:15 pm)
[patch 12/47] arm: Use ARCH_IRQ_INIT_FLAGS, Thomas Gleixner, (Thu Sep 30, 4:15 pm)
[patch 13/47] powerpc: Use ARCH_IRQ_INIT_FLAGS, Thomas Gleixner, (Thu Sep 30, 4:15 pm)
[patch 14/47] genirq: Implement a sane sparse_irq allocator, Thomas Gleixner, (Thu Sep 30, 4:15 pm)
[patch 16/47] genirq: Implement sane enumeration, Thomas Gleixner, (Thu Sep 30, 4:15 pm)
[patch 17/47] genirq-update-kerneldoc.patch, Thomas Gleixner, (Thu Sep 30, 4:15 pm)
[patch 18/47] genirq: Use sane sparse allocator, Thomas Gleixner, (Thu Sep 30, 4:16 pm)
[patch 21/47] x86: Sanitize apb timer interrupt handling, Thomas Gleixner, (Thu Sep 30, 4:16 pm)
[patch 22/47] x86: lguest: Convert to new irq chip functions, Thomas Gleixner, (Thu Sep 30, 4:16 pm)
[patch 23/47] x86: Cleanup visws interrupt handling, Thomas Gleixner, (Thu Sep 30, 4:16 pm)
[patch 24/47] x86: i8259: Convert to new irq_chip functions, Thomas Gleixner, (Thu Sep 30, 4:16 pm)
[patch 25/47] x86: Cleanup io_apic, Thomas Gleixner, (Thu Sep 30, 4:16 pm)
[patch 29/47] pci: Convert msi to new irq_chip functions, Thomas Gleixner, (Thu Sep 30, 4:16 pm)
[patch 30/47] dmar: Convert to new irq chip functions, Thomas Gleixner, (Thu Sep 30, 4:16 pm)
[patch 31/47] ht: Convert to new irq_chip functions, Thomas Gleixner, (Thu Sep 30, 4:17 pm)
[patch 33/47] pci: Cleanup the irq_desc mess in msi, Thomas Gleixner, (Thu Sep 30, 4:17 pm)
[patch 35/47] x86: ioapic: Cleanup some more, Thomas Gleixner, (Thu Sep 30, 4:17 pm)
[patch 36/47] x86: ioapic: Cleanup sparse irq code, Thomas Gleixner, (Thu Sep 30, 4:17 pm)
[patch 38/47] x86: Use sane enumeration, Thomas Gleixner, (Thu Sep 30, 4:17 pm)
[patch 39/47] genirq: Remove arch_init_chip_data(), Thomas Gleixner, (Thu Sep 30, 4:17 pm)
[patch 40/47] genirq: Sanitize dynamic irq handling, Thomas Gleixner, (Thu Sep 30, 4:17 pm)
[patch 41/47] arm: davinci: Cleanup irq_desc access, Thomas Gleixner, (Thu Sep 30, 4:18 pm)
[patch 43/47] x86: xen: Sanitise sparse_irq handling, Thomas Gleixner, (Thu Sep 30, 4:18 pm)
[patch 44/47] sh: Sanitize sparse irq, Thomas Gleixner, (Thu Sep 30, 4:18 pm)
[patch 45/47] x86: lguest: Use new irq allocator, Thomas Gleixner, (Thu Sep 30, 4:18 pm)
[patch 46/47] powerpc: Use new irq allocator, Thomas Gleixner, (Thu Sep 30, 4:18 pm)
Re: [patch 46/47] powerpc: Use new irq allocator, Benjamin Herrenschmidt, (Thu Sep 30, 5:42 pm)
Re: [patch 00/47] Sparse irq rework, Linus Torvalds, (Thu Sep 30, 8:32 pm)
Re: [patch 00/47] Sparse irq rework, Yinghai Lu, (Thu Sep 30, 10:54 pm)
Re: [patch 46/47] powerpc: Use new irq allocator, Thomas Gleixner, (Fri Oct 1, 6:07 am)
Re: [patch 00/47] Sparse irq rework, Thomas Gleixner, (Fri Oct 1, 1:35 pm)
Re: [patch 46/47] powerpc: Use new irq allocator, Benjamin Herrenschmidt, (Fri Oct 1, 1:46 pm)
Re: [patch 46/47] powerpc: Use new irq allocator, Grant Likely, (Fri Oct 1, 2:11 pm)
Re: [patch 46/47] powerpc: Use new irq allocator, Benjamin Herrenschmidt, (Fri Oct 1, 2:17 pm)
Re: [patch 16/47] genirq: Implement sane enumeration, Grant Likely, (Sun Oct 3, 3:55 am)
Re: [patch 00/47] Sparse irq rework, Grant Likely, (Sun Oct 3, 4:23 am)
Re: [patch 00/47] Sparse irq rework, Russell King - ARM Linux, (Sun Oct 3, 4:29 am)
Re: [patch 00/47] Sparse irq rework, Grant Likely, (Sun Oct 3, 4:57 am)
Re: [patch 00/47] Sparse irq rework, Thomas Gleixner, (Sun Oct 3, 6:48 am)
Re: [patch 20/47] x86: Remove useless reinitialization of ..., Eric W. Biederman, (Sun Oct 3, 8:21 am)
Re: [patch 00/47] Sparse irq rework, Eric W. Biederman, (Sun Oct 3, 9:41 am)
Re: [patch 46/47] powerpc: Use new irq allocator, Eric W. Biederman, (Sun Oct 3, 9:53 am)
Re: [patch 46/47] powerpc: Use new irq allocator, Thomas Gleixner, (Sun Oct 3, 11:34 am)
Re: [patch 00/47] Sparse irq rework, Thomas Gleixner, (Sun Oct 3, 12:16 pm)
Re: [patch 46/47] powerpc: Use new irq allocator, Thomas Gleixner, (Sun Oct 3, 1:04 pm)
Re: [patch 46/47] powerpc: Use new irq allocator, Benjamin Herrenschmidt, (Sun Oct 3, 3:54 pm)
Re: [patch 00/47] Sparse irq rework, Benjamin Herrenschmidt, (Sun Oct 3, 3:57 pm)
Re: [patch 46/47] powerpc: Use new irq allocator, Eric W. Biederman, (Sun Oct 3, 5:15 pm)
Re: [patch 46/47] powerpc: Use new irq allocator, Benjamin Herrenschmidt, (Sun Oct 3, 5:37 pm)
Re: [patch 00/47] Sparse irq rework, Eric W. Biederman, (Sun Oct 3, 5:49 pm)
Re: [patch 00/47] Sparse irq rework, Eric W. Biederman, (Sun Oct 3, 6:13 pm)
Re: [patch 00/47] Sparse irq rework, Ingo Molnar, (Sun Oct 3, 11:36 pm)
Re: [patch 00/47] Sparse irq rework, Thomas Gleixner, (Mon Oct 4, 1:05 am)
Re: [patch 00/47] Sparse irq rework, Grant Likely, (Mon Oct 4, 9:31 am)
Re: [patch 46/47] powerpc: Use new irq allocator, Grant Likely, (Mon Oct 4, 9:46 am)
Re: [patch 00/47] Sparse irq rework, Thomas Gleixner, (Tue Oct 5, 3:22 am)
Re: [patch 00/47] Sparse irq rework, Yinghai Lu, (Wed Oct 6, 3:45 pm)
Re: [patch 00/47] Sparse irq rework, Thomas Gleixner, (Wed Oct 6, 3:52 pm)
Re: [patch 00/47] Sparse irq rework, Yinghai Lu, (Wed Oct 6, 4:37 pm)
Re: [patch 00/47] Sparse irq rework, Yinghai Lu, (Wed Oct 6, 5:16 pm)
Re: [patch 00/47] Sparse irq rework, Thomas Gleixner, (Wed Oct 6, 9:01 pm)
Re: [patch 00/47] Sparse irq rework, Yinghai Lu, (Wed Oct 6, 9:38 pm)
Re: [patch 00/47] Sparse irq rework, Thomas Gleixner, (Fri Oct 8, 2:50 pm)
Re: [patch 00/47] Sparse irq rework, Thomas Gleixner, (Fri Oct 8, 2:54 pm)
Re: [patch 00/47] Sparse irq rework, Yinghai Lu, (Fri Oct 8, 9:26 pm)
Re: [patch 00/47] Sparse irq rework, Yinghai Lu, (Fri Oct 8, 10:44 pm)
Re: [patch 00/47] Sparse irq rework, Thomas Gleixner, (Fri Oct 8, 11:10 pm)
Re: [patch 00/47] Sparse irq rework, Thomas Gleixner, (Fri Oct 8, 11:34 pm)
Re: [patch 00/47] Sparse irq rework, Yinghai Lu, (Sat Oct 9, 12:03 am)
Re: [patch 00/47] Sparse irq rework, Yinghai Lu, (Sat Oct 9, 12:08 am)
Re: [patch 00/47] Sparse irq rework, Thomas Gleixner, (Sat Oct 9, 5:08 am)
Re: [patch 00/47] Sparse irq rework, Thomas Gleixner, (Sat Oct 9, 5:12 am)
Re: [patch 00/47] Sparse irq rework, Yinghai Lu, (Sat Oct 9, 7:32 pm)
Re: [patch 00/47] Sparse irq rework, Yinghai Lu, (Sat Oct 9, 10:11 pm)
Re: [patch 00/47] Sparse irq rework, Thomas Gleixner, (Sun Oct 10, 1:20 am)
Re: [patch 00/47] Sparse irq rework, Thomas Gleixner, (Sun Oct 10, 2:32 am)
Re: [patch 00/47] Sparse irq rework, Anca Emanuel, (Sun Oct 10, 6:30 am)
Re: [patch 00/47] Sparse irq rework, Yinghai Lu, (Sun Oct 10, 7:20 pm)
Re: [patch 00/47] Sparse irq rework, Yinghai Lu, (Sun Oct 10, 8:50 pm)
Re: [patch 00/47] Sparse irq rework, Thomas Gleixner, (Mon Oct 11, 1:16 am)
Re: [patch 00/47] Sparse irq rework, Benjamin Herrenschmidt, (Mon Oct 11, 4:34 am)
Re: [patch 00/47] Sparse irq rework, Yinghai Lu, (Mon Oct 11, 9:19 am)
Re: [patch 33/47] pci: Cleanup the irq_desc mess in msi, Jesse Barnes, (Mon Oct 11, 10:08 am)
[tip:irq/core] x86: Don't setup ioapic irq for sci twice, tip-bot for Yinghai Lu, (Tue Oct 12, 1:23 pm)