__free_irq()/__free_percpu_irq() need to return if called from IRQ
context because the interrupt handler loop runs with desc->lock dropped
and dev_id can be subject to load and store tearing. Also move WARNs
out of lock region and print out dev_id to help debugging.

Signed-off-by: Ben Luo <luo...@linux.alibaba.com>
---
 kernel/irq/manage.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index e8f7f17..10ec3e9 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -1690,7 +1690,10 @@ static struct irqaction *__free_irq(struct irq_desc 
*desc, void *dev_id)
        struct irqaction *action, **action_ptr;
        unsigned long flags;
 
-       WARN(in_interrupt(), "Trying to free IRQ %d from IRQ context!\n", irq);
+       if (WARN(in_interrupt(),
+                "Trying to free IRQ %d (dev_id %p) from IRQ context!\n",
+                irq, dev_id))
+               return NULL;
 
        mutex_lock(&desc->request_mutex);
        chip_bus_lock(desc);
@@ -1705,10 +1708,11 @@ static struct irqaction *__free_irq(struct irq_desc 
*desc, void *dev_id)
                action = *action_ptr;
 
                if (!action) {
-                       WARN(1, "Trying to free already-free IRQ %d\n", irq);
                        raw_spin_unlock_irqrestore(&desc->lock, flags);
                        chip_bus_sync_unlock(desc);
                        mutex_unlock(&desc->request_mutex);
+                       WARN(1, "Trying to free already-free IRQ %d (dev_id 
%p)\n",
+                            irq, dev_id);
                        return NULL;
                }
 
@@ -2286,7 +2290,10 @@ static struct irqaction *__free_percpu_irq(unsigned int 
irq, void __percpu *dev_
        struct irqaction *action;
        unsigned long flags;
 
-       WARN(in_interrupt(), "Trying to free IRQ %d from IRQ context!\n", irq);
+       if (WARN(in_interrupt(),
+                "Trying to free IRQ %d (dev_id %p) from IRQ context!\n",
+                irq, dev_id))
+               return NULL;
 
        if (!desc)
                return NULL;
@@ -2295,14 +2302,17 @@ static struct irqaction *__free_percpu_irq(unsigned int 
irq, void __percpu *dev_
 
        action = desc->action;
        if (!action || action->percpu_dev_id != dev_id) {
-               WARN(1, "Trying to free already-free IRQ %d\n", irq);
-               goto bad;
+               raw_spin_unlock_irqrestore(&desc->lock, flags);
+               WARN(1, "Trying to free already-free IRQ (dev_id %p) %d\n",
+                    dev_id, irq);
+               return NULL;
        }
 
        if (!cpumask_empty(desc->percpu_enabled)) {
-               WARN(1, "percpu IRQ %d still enabled on CPU%d!\n",
-                    irq, cpumask_first(desc->percpu_enabled));
-               goto bad;
+               raw_spin_unlock_irqrestore(&desc->lock, flags);
+               WARN(1, "percpu IRQ %d (dev_id %p) still enabled on CPU%d!\n",
+                    irq, dev_id, cpumask_first(desc->percpu_enabled));
+               return NULL;
        }
 
        /* Found it - now remove it from the list of entries: */
@@ -2317,10 +2327,6 @@ static struct irqaction *__free_percpu_irq(unsigned int 
irq, void __percpu *dev_
        irq_chip_pm_put(&desc->irq_data);
        module_put(desc->owner);
        return action;
-
-bad:
-       raw_spin_unlock_irqrestore(&desc->lock, flags);
-       return NULL;
 }
 
 /**
-- 
1.8.3.1

Reply via email to