Re: [PATCH 24/37] powerpc: return early if irq_host lookup type is wrong
From: Grant Likely <hidden>
Date: 2011-05-11 19:04:18
On Wed, May 11, 2011 at 7:29 AM, Milton Miller [off-list ref] wrote:
If for some reason the code incrorectly calls the wrong function to manage the revmap, not only should we warn, we should take action. However, in the paths we expect to be taken every delivered interrupt change to WARN_ON_ONCE. =A0Use the if (WARN_ON(x)) format to get the unlikely for free. Signed-off-by: Milton Miller <redacted>
Looks right. Reviewed-by: Grant Likely <redacted>
quoted hunk ↗ jump to hunk
--- =A0arch/powerpc/kernel/irq.c | =A0 12 +++++++----- =A01 files changed, 7 insertions(+), 5 deletions(-)diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c index f42e869..4a5aa8c 100644 --- a/arch/powerpc/kernel/irq.c +++ b/arch/powerpc/kernel/irq.c@@ -814,8 +814,7 @@ void irq_dispose_mapping(unsigned int virq)=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return; =A0 =A0 =A0 =A0host =3D irq_map[virq].host; - =A0 =A0 =A0 WARN_ON (host =3D=3D NULL); - =A0 =A0 =A0 if (host =3D=3D NULL) + =A0 =A0 =A0 if (WARN_ON(host =3D=3D NULL)) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return; =A0 =A0 =A0 =A0/* Never unmap legacy interrupts */@@ -898,7 +897,8 @@ unsigned int irq_radix_revmap_lookup(struct irq_host =
*host,
=A0 =A0 =A0 =A0struct irq_map_entry *ptr; =A0 =A0 =A0 =A0unsigned int virq; - =A0 =A0 =A0 WARN_ON(host->revmap_type !=3D IRQ_HOST_MAP_TREE); + =A0 =A0 =A0 if (WARN_ON_ONCE(host->revmap_type !=3D IRQ_HOST_MAP_TREE)) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return irq_find_mapping(host, hwirq); =A0 =A0 =A0 =A0/* =A0 =A0 =A0 =A0 * No rcu_read_lock(ing) needed, the ptr returned can't go=
under us
quoted hunk ↗ jump to hunk
@@ -922,7 +922,8 @@ unsigned int irq_radix_revmap_lookup(struct irq_host =
*host,
=A0void irq_radix_revmap_insert(struct irq_host *host, unsigned int virq, =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 irq_hw_number_t h=
wirq)
quoted hunk ↗ jump to hunk
=A0{ - =A0 =A0 =A0 WARN_ON(host->revmap_type !=3D IRQ_HOST_MAP_TREE); + =A0 =A0 =A0 if (WARN_ON(host->revmap_type !=3D IRQ_HOST_MAP_TREE)) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return; =A0 =A0 =A0 =A0if (virq !=3D NO_IRQ) { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0mutex_lock(&revmap_trees_mutex);@@ -937,7 +938,8 @@ unsigned int irq_linear_revmap(struct irq_host *host,=A0{ =A0 =A0 =A0 =A0unsigned int *revmap; - =A0 =A0 =A0 WARN_ON(host->revmap_type !=3D IRQ_HOST_MAP_LINEAR); + =A0 =A0 =A0 if (WARN_ON_ONCE(host->revmap_type !=3D IRQ_HOST_MAP_LINEAR=
))
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return irq_find_mapping(host, hwirq); =A0 =A0 =A0 =A0/* Check revmap bounds */ =A0 =A0 =A0 =A0if (unlikely(hwirq >=3D host->revmap_data.linear.size)) -- 1.7.0.4
--=20 Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd.