aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYinghai Lu <yhlu.kernel@gmail.com>2008-08-19 23:50:14 -0400
committerIngo Molnar <mingo@elte.hu>2008-10-16 10:52:50 -0400
commit7d94f7ca401dd7f445fda9a971a48aa5427b3e55 (patch)
tree8f4d4b73966fd0aa54df2da5bbcf67ea0a7ff43a
parent46b8214d12c274bd4265aae482ab7ffe69d94818 (diff)
irq: remove >= nr_irqs checking with config_have_sparse_irq
remove irq limit checks - nr_irqs is dynamic and we expand anytime. v2: fix checking about result irq_cfg_without_new, so could use msi again v3: use irq_desc_without_new to check irq is valid Signed-off-by: Yinghai Lu <yhlu.kernel@gmail.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r--arch/x86/kernel/io_apic_64.c9
-rw-r--r--arch/x86/kernel/irq_64.c2
-rw-r--r--kernel/irq/chip.c49
-rw-r--r--kernel/irq/manage.c43
4 files changed, 55 insertions, 48 deletions
diff --git a/arch/x86/kernel/io_apic_64.c b/arch/x86/kernel/io_apic_64.c
index 60d60061659c..1b8cccb5ba25 100644
--- a/arch/x86/kernel/io_apic_64.c
+++ b/arch/x86/kernel/io_apic_64.c
@@ -400,7 +400,6 @@ static inline void io_apic_sync(unsigned int apic)
400 struct irq_cfg *cfg; \ 400 struct irq_cfg *cfg; \
401 struct irq_pin_list *entry; \ 401 struct irq_pin_list *entry; \
402 \ 402 \
403 BUG_ON(irq >= nr_irqs); \
404 cfg = irq_cfg(irq); \ 403 cfg = irq_cfg(irq); \
405 entry = cfg->irq_2_pin; \ 404 entry = cfg->irq_2_pin; \
406 for (;;) { \ 405 for (;;) { \
@@ -480,7 +479,6 @@ static void __target_IO_APIC_irq(unsigned int irq, unsigned int dest, u8 vector)
480 struct irq_cfg *cfg; 479 struct irq_cfg *cfg;
481 struct irq_pin_list *entry; 480 struct irq_pin_list *entry;
482 481
483 BUG_ON(irq >= nr_irqs);
484 cfg = irq_cfg(irq); 482 cfg = irq_cfg(irq);
485 entry = cfg->irq_2_pin; 483 entry = cfg->irq_2_pin;
486 for (;;) { 484 for (;;) {
@@ -549,7 +547,6 @@ static void add_pin_to_irq(unsigned int irq, int apic, int pin)
549 struct irq_cfg *cfg; 547 struct irq_cfg *cfg;
550 struct irq_pin_list *entry; 548 struct irq_pin_list *entry;
551 549
552 BUG_ON(irq >= nr_irqs);
553 /* first time to refer irq_cfg, so with new */ 550 /* first time to refer irq_cfg, so with new */
554 cfg = irq_cfg_alloc(irq); 551 cfg = irq_cfg_alloc(irq);
555 entry = cfg->irq_2_pin; 552 entry = cfg->irq_2_pin;
@@ -841,7 +838,6 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin)
841 best_guess = irq; 838 best_guess = irq;
842 } 839 }
843 } 840 }
844 BUG_ON(best_guess >= nr_irqs);
845 return best_guess; 841 return best_guess;
846} 842}
847 843
@@ -973,7 +969,6 @@ static int pin_2_irq(int idx, int apic, int pin)
973 irq += nr_ioapic_registers[i++]; 969 irq += nr_ioapic_registers[i++];
974 irq += pin; 970 irq += pin;
975 } 971 }
976 BUG_ON(irq >= nr_irqs);
977 return irq; 972 return irq;
978} 973}
979 974
@@ -1008,7 +1003,6 @@ static int __assign_irq_vector(int irq, cpumask_t mask)
1008 int cpu; 1003 int cpu;
1009 struct irq_cfg *cfg; 1004 struct irq_cfg *cfg;
1010 1005
1011 BUG_ON((unsigned)irq >= nr_irqs);
1012 cfg = irq_cfg(irq); 1006 cfg = irq_cfg(irq);
1013 1007
1014 /* Only try and allocate irqs on cpus that are present */ 1008 /* Only try and allocate irqs on cpus that are present */
@@ -1082,7 +1076,6 @@ static void __clear_irq_vector(int irq)
1082 cpumask_t mask; 1076 cpumask_t mask;
1083 int cpu, vector; 1077 int cpu, vector;
1084 1078
1085 BUG_ON((unsigned)irq >= nr_irqs);
1086 cfg = irq_cfg(irq); 1079 cfg = irq_cfg(irq);
1087 BUG_ON(!cfg->vector); 1080 BUG_ON(!cfg->vector);
1088 1081
@@ -1924,8 +1917,6 @@ asmlinkage void smp_irq_move_cleanup_interrupt(void)
1924 struct irq_desc *desc; 1917 struct irq_desc *desc;
1925 struct irq_cfg *cfg; 1918 struct irq_cfg *cfg;
1926 irq = __get_cpu_var(vector_irq)[vector]; 1919 irq = __get_cpu_var(vector_irq)[vector];
1927 if (irq >= nr_irqs)
1928 continue;
1929 1920
1930 desc = irq_to_desc(irq); 1921 desc = irq_to_desc(irq);
1931 cfg = irq_cfg(irq); 1922 cfg = irq_cfg(irq);
diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
index b3cf55e325f5..a3e36336d914 100644
--- a/arch/x86/kernel/irq_64.c
+++ b/arch/x86/kernel/irq_64.c
@@ -202,7 +202,7 @@ asmlinkage unsigned int do_IRQ(struct pt_regs *regs)
202 stack_overflow_check(regs); 202 stack_overflow_check(regs);
203#endif 203#endif
204 204
205 if (likely(irq < nr_irqs)) 205 if (likely(__irq_to_desc(irq)))
206 generic_handle_irq(irq); 206 generic_handle_irq(irq);
207 else { 207 else {
208 if (!disable_apic) 208 if (!disable_apic)
diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c
index 2aa3d4b2fce8..a4bb0da9c88c 100644
--- a/kernel/irq/chip.c
+++ b/kernel/irq/chip.c
@@ -27,13 +27,13 @@ void dynamic_irq_init(unsigned int irq)
27 struct irq_desc *desc; 27 struct irq_desc *desc;
28 unsigned long flags; 28 unsigned long flags;
29 29
30 if (irq >= nr_irqs) { 30 desc = irq_to_desc(irq);
31 if (!desc) {
31 WARN(1, KERN_ERR "Trying to initialize invalid IRQ%d\n", irq); 32 WARN(1, KERN_ERR "Trying to initialize invalid IRQ%d\n", irq);
32 return; 33 return;
33 } 34 }
34 35
35 /* Ensure we don't have left over values from a previous use of this irq */ 36 /* Ensure we don't have left over values from a previous use of this irq */
36 desc = irq_to_desc(irq);
37 spin_lock_irqsave(&desc->lock, flags); 37 spin_lock_irqsave(&desc->lock, flags);
38 desc->status = IRQ_DISABLED; 38 desc->status = IRQ_DISABLED;
39 desc->chip = &no_irq_chip; 39 desc->chip = &no_irq_chip;
@@ -60,12 +60,12 @@ void dynamic_irq_cleanup(unsigned int irq)
60 struct irq_desc *desc; 60 struct irq_desc *desc;
61 unsigned long flags; 61 unsigned long flags;
62 62
63 if (irq >= nr_irqs) { 63 desc = __irq_to_desc(irq);
64 if (!desc) {
64 WARN(1, KERN_ERR "Trying to cleanup invalid IRQ%d\n", irq); 65 WARN(1, KERN_ERR "Trying to cleanup invalid IRQ%d\n", irq);
65 return; 66 return;
66 } 67 }
67 68
68 desc = irq_to_desc(irq);
69 spin_lock_irqsave(&desc->lock, flags); 69 spin_lock_irqsave(&desc->lock, flags);
70 if (desc->action) { 70 if (desc->action) {
71 spin_unlock_irqrestore(&desc->lock, flags); 71 spin_unlock_irqrestore(&desc->lock, flags);
@@ -92,7 +92,8 @@ int set_irq_chip(unsigned int irq, struct irq_chip *chip)
92 struct irq_desc *desc; 92 struct irq_desc *desc;
93 unsigned long flags; 93 unsigned long flags;
94 94
95 if (irq >= nr_irqs) { 95 desc = __irq_to_desc(irq);
96 if (!desc) {
96 WARN(1, KERN_ERR "Trying to install chip for IRQ%d\n", irq); 97 WARN(1, KERN_ERR "Trying to install chip for IRQ%d\n", irq);
97 return -EINVAL; 98 return -EINVAL;
98 } 99 }
@@ -121,12 +122,12 @@ int set_irq_type(unsigned int irq, unsigned int type)
121 unsigned long flags; 122 unsigned long flags;
122 int ret = -ENXIO; 123 int ret = -ENXIO;
123 124
124 if (irq >= nr_irqs) { 125 desc = __irq_to_desc(irq);
126 if (!desc) {
125 printk(KERN_ERR "Trying to set irq type for IRQ%d\n", irq); 127 printk(KERN_ERR "Trying to set irq type for IRQ%d\n", irq);
126 return -ENODEV; 128 return -ENODEV;
127 } 129 }
128 130
129 desc = irq_to_desc(irq);
130 if (type == IRQ_TYPE_NONE) 131 if (type == IRQ_TYPE_NONE)
131 return 0; 132 return 0;
132 133
@@ -149,13 +150,13 @@ int set_irq_data(unsigned int irq, void *data)
149 struct irq_desc *desc; 150 struct irq_desc *desc;
150 unsigned long flags; 151 unsigned long flags;
151 152
152 if (irq >= nr_irqs) { 153 desc = __irq_to_desc(irq);
154 if (!desc) {
153 printk(KERN_ERR 155 printk(KERN_ERR
154 "Trying to install controller data for IRQ%d\n", irq); 156 "Trying to install controller data for IRQ%d\n", irq);
155 return -EINVAL; 157 return -EINVAL;
156 } 158 }
157 159
158 desc = irq_to_desc(irq);
159 spin_lock_irqsave(&desc->lock, flags); 160 spin_lock_irqsave(&desc->lock, flags);
160 desc->handler_data = data; 161 desc->handler_data = data;
161 spin_unlock_irqrestore(&desc->lock, flags); 162 spin_unlock_irqrestore(&desc->lock, flags);
@@ -175,12 +176,13 @@ int set_irq_msi(unsigned int irq, struct msi_desc *entry)
175 struct irq_desc *desc; 176 struct irq_desc *desc;
176 unsigned long flags; 177 unsigned long flags;
177 178
178 if (irq >= nr_irqs) { 179 desc = __irq_to_desc(irq);
180 if (!desc) {
179 printk(KERN_ERR 181 printk(KERN_ERR
180 "Trying to install msi data for IRQ%d\n", irq); 182 "Trying to install msi data for IRQ%d\n", irq);
181 return -EINVAL; 183 return -EINVAL;
182 } 184 }
183 desc = irq_to_desc(irq); 185
184 spin_lock_irqsave(&desc->lock, flags); 186 spin_lock_irqsave(&desc->lock, flags);
185 desc->msi_desc = entry; 187 desc->msi_desc = entry;
186 if (entry) 188 if (entry)
@@ -201,8 +203,14 @@ int set_irq_chip_data(unsigned int irq, void *data)
201 struct irq_desc *desc; 203 struct irq_desc *desc;
202 unsigned long flags; 204 unsigned long flags;
203 205
204 desc = irq_to_desc(irq); 206 desc = __irq_to_desc(irq);
205 if (irq >= nr_irqs || !desc->chip) { 207 if (!desc) {
208 printk(KERN_ERR
209 "Trying to install chip data for IRQ%d\n", irq);
210 return -EINVAL;
211 }
212
213 if (!desc->chip) {
206 printk(KERN_ERR "BUG: bad set_irq_chip_data(IRQ#%d)\n", irq); 214 printk(KERN_ERR "BUG: bad set_irq_chip_data(IRQ#%d)\n", irq);
207 return -EINVAL; 215 return -EINVAL;
208 } 216 }
@@ -546,14 +554,13 @@ __set_irq_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
546 struct irq_desc *desc; 554 struct irq_desc *desc;
547 unsigned long flags; 555 unsigned long flags;
548 556
549 if (irq >= nr_irqs) { 557 desc = __irq_to_desc(irq);
558 if (!desc) {
550 printk(KERN_ERR 559 printk(KERN_ERR
551 "Trying to install type control for IRQ%d\n", irq); 560 "Trying to install type control for IRQ%d\n", irq);
552 return; 561 return;
553 } 562 }
554 563
555 desc = irq_to_desc(irq);
556
557 if (!handle) 564 if (!handle)
558 handle = handle_bad_irq; 565 handle = handle_bad_irq;
559 else if (desc->chip == &no_irq_chip) { 566 else if (desc->chip == &no_irq_chip) {
@@ -611,14 +618,13 @@ void __init set_irq_noprobe(unsigned int irq)
611 struct irq_desc *desc; 618 struct irq_desc *desc;
612 unsigned long flags; 619 unsigned long flags;
613 620
614 if (irq >= nr_irqs) { 621 desc = __irq_to_desc(irq);
622 if (!desc) {
615 printk(KERN_ERR "Trying to mark IRQ%d non-probeable\n", irq); 623 printk(KERN_ERR "Trying to mark IRQ%d non-probeable\n", irq);
616 624
617 return; 625 return;
618 } 626 }
619 627
620 desc = irq_to_desc(irq);
621
622 spin_lock_irqsave(&desc->lock, flags); 628 spin_lock_irqsave(&desc->lock, flags);
623 desc->status |= IRQ_NOPROBE; 629 desc->status |= IRQ_NOPROBE;
624 spin_unlock_irqrestore(&desc->lock, flags); 630 spin_unlock_irqrestore(&desc->lock, flags);
@@ -629,14 +635,13 @@ void __init set_irq_probe(unsigned int irq)
629 struct irq_desc *desc; 635 struct irq_desc *desc;
630 unsigned long flags; 636 unsigned long flags;
631 637
632 if (irq >= nr_irqs) { 638 desc = __irq_to_desc(irq);
639 if (!desc) {
633 printk(KERN_ERR "Trying to mark IRQ%d probeable\n", irq); 640 printk(KERN_ERR "Trying to mark IRQ%d probeable\n", irq);
634 641
635 return; 642 return;
636 } 643 }
637 644
638 desc = irq_to_desc(irq);
639
640 spin_lock_irqsave(&desc->lock, flags); 645 spin_lock_irqsave(&desc->lock, flags);
641 desc->status &= ~IRQ_NOPROBE; 646 desc->status &= ~IRQ_NOPROBE;
642 spin_unlock_irqrestore(&desc->lock, flags); 647 spin_unlock_irqrestore(&desc->lock, flags);
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 5070f55fdc16..c0b4d4df6de2 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -31,10 +31,10 @@ cpumask_t irq_default_affinity = CPU_MASK_ALL;
31 */ 31 */
32void synchronize_irq(unsigned int irq) 32void synchronize_irq(unsigned int irq)
33{ 33{
34 struct irq_desc *desc = irq_to_desc(irq); 34 struct irq_desc *desc = __irq_to_desc(irq);
35 unsigned int status; 35 unsigned int status;
36 36
37 if (irq >= nr_irqs) 37 if (!desc)
38 return; 38 return;
39 39
40 do { 40 do {
@@ -142,10 +142,11 @@ int irq_select_affinity(unsigned int irq)
142 */ 142 */
143void disable_irq_nosync(unsigned int irq) 143void disable_irq_nosync(unsigned int irq)
144{ 144{
145 struct irq_desc *desc = irq_to_desc(irq); 145 struct irq_desc *desc;
146 unsigned long flags; 146 unsigned long flags;
147 147
148 if (irq >= nr_irqs) 148 desc = __irq_to_desc(irq);
149 if (!desc)
149 return; 150 return;
150 151
151 spin_lock_irqsave(&desc->lock, flags); 152 spin_lock_irqsave(&desc->lock, flags);
@@ -171,9 +172,10 @@ EXPORT_SYMBOL(disable_irq_nosync);
171 */ 172 */
172void disable_irq(unsigned int irq) 173void disable_irq(unsigned int irq)
173{ 174{
174 struct irq_desc *desc = irq_to_desc(irq); 175 struct irq_desc *desc;
175 176
176 if (irq >= nr_irqs) 177 desc = __irq_to_desc(irq);
178 if (!desc)
177 return; 179 return;
178 180
179 disable_irq_nosync(irq); 181 disable_irq_nosync(irq);
@@ -213,10 +215,11 @@ static void __enable_irq(struct irq_desc *desc, unsigned int irq)
213 */ 215 */
214void enable_irq(unsigned int irq) 216void enable_irq(unsigned int irq)
215{ 217{
216 struct irq_desc *desc = irq_to_desc(irq); 218 struct irq_desc *desc;
217 unsigned long flags; 219 unsigned long flags;
218 220
219 if (irq >= nr_irqs) 221 desc = __irq_to_desc(irq);
222 if (!desc)
220 return; 223 return;
221 224
222 spin_lock_irqsave(&desc->lock, flags); 225 spin_lock_irqsave(&desc->lock, flags);
@@ -290,10 +293,14 @@ EXPORT_SYMBOL(set_irq_wake);
290 */ 293 */
291int can_request_irq(unsigned int irq, unsigned long irqflags) 294int can_request_irq(unsigned int irq, unsigned long irqflags)
292{ 295{
293 struct irq_desc *desc = irq_to_desc(irq); 296 struct irq_desc *desc;
294 struct irqaction *action; 297 struct irqaction *action;
295 298
296 if (irq >= nr_irqs || desc->status & IRQ_NOREQUEST) 299 desc = __irq_to_desc(irq);
300 if (!desc)
301 return 0;
302
303 if (desc->status & IRQ_NOREQUEST)
297 return 0; 304 return 0;
298 305
299 action = desc->action; 306 action = desc->action;
@@ -352,14 +359,15 @@ int __irq_set_trigger(struct irq_desc *desc, unsigned int irq,
352 */ 359 */
353int setup_irq(unsigned int irq, struct irqaction *new) 360int setup_irq(unsigned int irq, struct irqaction *new)
354{ 361{
355 struct irq_desc *desc = irq_to_desc(irq); 362 struct irq_desc *desc;
356 struct irqaction *old, **p; 363 struct irqaction *old, **p;
357 const char *old_name = NULL; 364 const char *old_name = NULL;
358 unsigned long flags; 365 unsigned long flags;
359 int shared = 0; 366 int shared = 0;
360 int ret; 367 int ret;
361 368
362 if (irq >= nr_irqs) 369 desc = __irq_to_desc(irq);
370 if (!desc)
363 return -EINVAL; 371 return -EINVAL;
364 372
365 if (desc->chip == &no_irq_chip) 373 if (desc->chip == &no_irq_chip)
@@ -518,10 +526,11 @@ void free_irq(unsigned int irq, void *dev_id)
518 unsigned long flags; 526 unsigned long flags;
519 527
520 WARN_ON(in_interrupt()); 528 WARN_ON(in_interrupt());
521 if (irq >= nr_irqs) 529
530 desc = __irq_to_desc(irq);
531 if (!desc)
522 return; 532 return;
523 533
524 desc = irq_to_desc(irq);
525 spin_lock_irqsave(&desc->lock, flags); 534 spin_lock_irqsave(&desc->lock, flags);
526 p = &desc->action; 535 p = &desc->action;
527 for (;;) { 536 for (;;) {
@@ -634,9 +643,11 @@ int request_irq(unsigned int irq, irq_handler_t handler,
634 */ 643 */
635 if ((irqflags & IRQF_SHARED) && !dev_id) 644 if ((irqflags & IRQF_SHARED) && !dev_id)
636 return -EINVAL; 645 return -EINVAL;
637 if (irq >= nr_irqs) 646
647 desc = __irq_to_desc(irq);
648 if (!desc)
638 return -EINVAL; 649 return -EINVAL;
639 desc = irq_to_desc(irq); 650
640 if (desc->status & IRQ_NOREQUEST) 651 if (desc->status & IRQ_NOREQUEST)
641 return -EINVAL; 652 return -EINVAL;
642 if (!handler) 653 if (!handler)