diff options
-rw-r--r-- | drivers/char/random.c | 66 | ||||
-rw-r--r-- | include/linux/irq.h | 2 |
2 files changed, 63 insertions, 5 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c index 1610aa64c7cf..60c9c7ee6b2c 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c | |||
@@ -558,7 +558,7 @@ struct timer_rand_state { | |||
558 | unsigned dont_count_entropy:1; | 558 | unsigned dont_count_entropy:1; |
559 | }; | 559 | }; |
560 | 560 | ||
561 | static struct timer_rand_state input_timer_state; | 561 | #ifndef CONFIG_HAVE_SPARSE_IRQ |
562 | 562 | ||
563 | #ifdef CONFIG_HAVE_DYN_ARRAY | 563 | #ifdef CONFIG_HAVE_DYN_ARRAY |
564 | static struct timer_rand_state **irq_timer_state; | 564 | static struct timer_rand_state **irq_timer_state; |
@@ -567,6 +567,51 @@ DEFINE_DYN_ARRAY(irq_timer_state, sizeof(struct timer_rand_state *), nr_irqs, PA | |||
567 | static struct timer_rand_state *irq_timer_state[NR_IRQS]; | 567 | static struct timer_rand_state *irq_timer_state[NR_IRQS]; |
568 | #endif | 568 | #endif |
569 | 569 | ||
570 | static struct timer_rand_state *get_timer_rand_state(unsigned int irq) | ||
571 | { | ||
572 | if (irq >= nr_irqs) | ||
573 | return NULL; | ||
574 | |||
575 | return irq_timer_state[irq]; | ||
576 | } | ||
577 | |||
578 | static void set_timer_rand_state(unsigned int irq, struct timer_rand_state *state) | ||
579 | { | ||
580 | if (irq >= nr_irqs) | ||
581 | return; | ||
582 | |||
583 | irq_timer_state[irq] = state; | ||
584 | } | ||
585 | |||
586 | #else | ||
587 | |||
588 | static struct timer_rand_state *get_timer_rand_state(unsigned int irq) | ||
589 | { | ||
590 | struct irq_desc *desc; | ||
591 | |||
592 | desc = irq_to_desc(irq); | ||
593 | |||
594 | if (!desc) | ||
595 | return NULL; | ||
596 | |||
597 | return desc->timer_rand_state; | ||
598 | } | ||
599 | |||
600 | static void set_timer_rand_state(unsigned int irq, struct timer_rand_state *state) | ||
601 | { | ||
602 | struct irq_desc *desc; | ||
603 | |||
604 | desc = irq_to_desc(irq); | ||
605 | |||
606 | if (!desc) | ||
607 | return; | ||
608 | |||
609 | desc->timer_rand_state = state; | ||
610 | } | ||
611 | #endif | ||
612 | |||
613 | static struct timer_rand_state input_timer_state; | ||
614 | |||
570 | /* | 615 | /* |
571 | * This function adds entropy to the entropy "pool" by using timing | 616 | * This function adds entropy to the entropy "pool" by using timing |
572 | * delays. It uses the timer_rand_state structure to make an estimate | 617 | * delays. It uses the timer_rand_state structure to make an estimate |
@@ -654,11 +699,15 @@ EXPORT_SYMBOL_GPL(add_input_randomness); | |||
654 | 699 | ||
655 | void add_interrupt_randomness(int irq) | 700 | void add_interrupt_randomness(int irq) |
656 | { | 701 | { |
657 | if (irq >= nr_irqs || irq_timer_state[irq] == NULL) | 702 | struct timer_rand_state *state; |
703 | |||
704 | state = get_timer_rand_state(irq); | ||
705 | |||
706 | if (state == NULL) | ||
658 | return; | 707 | return; |
659 | 708 | ||
660 | DEBUG_ENT("irq event %d\n", irq); | 709 | DEBUG_ENT("irq event %d\n", irq); |
661 | add_timer_randomness(irq_timer_state[irq], 0x100 + irq); | 710 | add_timer_randomness(state, 0x100 + irq); |
662 | } | 711 | } |
663 | 712 | ||
664 | #ifdef CONFIG_BLOCK | 713 | #ifdef CONFIG_BLOCK |
@@ -918,7 +967,14 @@ void rand_initialize_irq(int irq) | |||
918 | { | 967 | { |
919 | struct timer_rand_state *state; | 968 | struct timer_rand_state *state; |
920 | 969 | ||
921 | if (irq >= nr_irqs || irq_timer_state[irq]) | 970 | #ifndef CONFIG_HAVE_SPARSE_IRQ |
971 | if (irq >= nr_irqs) | ||
972 | return; | ||
973 | #endif | ||
974 | |||
975 | state = get_timer_rand_state(irq); | ||
976 | |||
977 | if (state) | ||
922 | return; | 978 | return; |
923 | 979 | ||
924 | /* | 980 | /* |
@@ -927,7 +983,7 @@ void rand_initialize_irq(int irq) | |||
927 | */ | 983 | */ |
928 | state = kzalloc(sizeof(struct timer_rand_state), GFP_KERNEL); | 984 | state = kzalloc(sizeof(struct timer_rand_state), GFP_KERNEL); |
929 | if (state) | 985 | if (state) |
930 | irq_timer_state[irq] = state; | 986 | set_timer_rand_state(irq, state); |
931 | } | 987 | } |
932 | 988 | ||
933 | #ifdef CONFIG_BLOCK | 989 | #ifdef CONFIG_BLOCK |
diff --git a/include/linux/irq.h b/include/linux/irq.h index 80b8200f2adb..60c856aaac0f 100644 --- a/include/linux/irq.h +++ b/include/linux/irq.h | |||
@@ -127,6 +127,7 @@ struct irq_chip { | |||
127 | const char *typename; | 127 | const char *typename; |
128 | }; | 128 | }; |
129 | 129 | ||
130 | struct timer_rand_state; | ||
130 | /** | 131 | /** |
131 | * struct irq_desc - interrupt descriptor | 132 | * struct irq_desc - interrupt descriptor |
132 | * | 133 | * |
@@ -155,6 +156,7 @@ struct irq_desc { | |||
155 | unsigned int irq; | 156 | unsigned int irq; |
156 | #ifdef CONFIG_HAVE_SPARSE_IRQ | 157 | #ifdef CONFIG_HAVE_SPARSE_IRQ |
157 | struct irq_desc *next; | 158 | struct irq_desc *next; |
159 | struct timer_rand_state *timer_rand_state; | ||
158 | #endif | 160 | #endif |
159 | irq_flow_handler_t handle_irq; | 161 | irq_flow_handler_t handle_irq; |
160 | struct irq_chip *chip; | 162 | struct irq_chip *chip; |