diff mbox

[2/8] staging: omap-thermal: use spin_lock_irqsave inside IRQ handler

Message ID 1363618756-15851-3-git-send-email-eduardo.valentin@ti.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Eduardo Valentin March 18, 2013, 2:59 p.m. UTC
Even if the IRQ is not firing because it is ONE_SHOT and disable
at INTC level, the IRQ handler must use spin_lock_irqsave.
It is necessary to disable IRQs from the current
CPU while it is holding a spin_lock which is need.

Cc: Dan Carpenter <dan.carpenter@oracle.com>

Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>

Comments

Dan Carpenter March 18, 2013, 7:16 p.m. UTC | #1
On Mon, Mar 18, 2013 at 10:59:10AM -0400, Eduardo Valentin wrote:
> Even if the IRQ is not firing because it is ONE_SHOT and disable
> at INTC level, the IRQ handler must use spin_lock_irqsave.
> It is necessary to disable IRQs from the current
> CPU while it is holding a spin_lock which is need.
> 

Gar...  I think I was just totally wrong on this.  I think your
original code was fine.  Sorry Eduardo and Greg.

This is a threaded IRQ so the regular spin_lock is fine or even the
mutex would have been.

IRQ_ONESHOT is about triggering a second IRQ before the first one
has been finished, btw.

I am an idiot.

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Eduardo Valentin March 18, 2013, 7:38 p.m. UTC | #2
On 18-03-2013 15:16, Dan Carpenter wrote:
> On Mon, Mar 18, 2013 at 10:59:10AM -0400, Eduardo Valentin wrote:
>> Even if the IRQ is not firing because it is ONE_SHOT and disable
>> at INTC level, the IRQ handler must use spin_lock_irqsave.
>> It is necessary to disable IRQs from the current
>> CPU while it is holding a spin_lock which is need.
>>
>
> Gar...  I think I was just totally wrong on this.  I think your
> original code was fine.  Sorry Eduardo and Greg.
>
> This is a threaded IRQ so the regular spin_lock is fine or even the
> mutex would have been.

In fact it is. But I rather prefer to use spinlocks there, just to keep 
the irq handler sane, even if it is moved to non-threaded IRQ.

>
> IRQ_ONESHOT is about triggering a second IRQ before the first one
> has been finished, btw.

It is, and that gets done by masking the IRQ at INTC level.

>
> I am an idiot.


Not really. Thanks for your time reviewing the driver.

  I will resend this series. Drop this one and split patch 4/8 into two 
I think (one for moving files, one for renaming functions)

>
> regards,
> dan carpenter
>
>
>

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dan Carpenter March 18, 2013, 7:58 p.m. UTC | #3
On Mon, Mar 18, 2013 at 03:38:38PM -0400, Eduardo Valentin wrote:
> On 18-03-2013 15:16, Dan Carpenter wrote:
> >On Mon, Mar 18, 2013 at 10:59:10AM -0400, Eduardo Valentin wrote:
> >>Even if the IRQ is not firing because it is ONE_SHOT and disable
> >>at INTC level, the IRQ handler must use spin_lock_irqsave.
> >>It is necessary to disable IRQs from the current
> >>CPU while it is holding a spin_lock which is need.
> >>
> >
> >Gar...  I think I was just totally wrong on this.  I think your
> >original code was fine.  Sorry Eduardo and Greg.
> >
> >This is a threaded IRQ so the regular spin_lock is fine or even the
> >mutex would have been.
> 
> In fact it is. But I rather prefer to use spinlocks there, just to
> keep the irq handler sane, even if it is moved to non-threaded IRQ.

Yep.  I'd agree there.

> 
> >
> >IRQ_ONESHOT is about triggering a second IRQ before the first one
> >has been finished, btw.
> 
> It is, and that gets done by masking the IRQ at INTC level.
> 
> >
> >I am an idiot.
> 
> 
> Not really. Thanks for your time reviewing the driver.
> 
>  I will resend this series. Drop this one and split patch 4/8 into
> two I think (one for moving files, one for renaming functions)

Great.  Much appreciated.

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/staging/omap-thermal/omap-bandgap.c b/drivers/staging/omap-thermal/omap-bandgap.c
index cb7aa35..a4ac06c 100644
--- a/drivers/staging/omap-thermal/omap-bandgap.c
+++ b/drivers/staging/omap-thermal/omap-bandgap.c
@@ -168,9 +168,10 @@  static irqreturn_t omap_bandgap_talert_irq_handler(int irq, void *data)
 	struct omap_bandgap *bg_ptr = data;
 	struct temp_sensor_registers *tsr;
 	u32 t_hot = 0, t_cold = 0, ctrl;
+	unsigned long flags;
 	int i;
 
-	spin_lock(&bg_ptr->lock);
+	spin_lock_irqsave(&bg_ptr->lock, flags);
 	for (i = 0; i < bg_ptr->conf->sensor_count; i++) {
 		tsr = bg_ptr->conf->sensors[i].registers;
 		ctrl = omap_bandgap_readl(bg_ptr, tsr->bgap_status);
@@ -209,7 +210,7 @@  static irqreturn_t omap_bandgap_talert_irq_handler(int irq, void *data)
 		if (bg_ptr->conf->report_temperature)
 			bg_ptr->conf->report_temperature(bg_ptr, i);
 	}
-	spin_unlock(&bg_ptr->lock);
+	spin_unlock_irqrestore(&bg_ptr->lock, flags);
 
 	return IRQ_HANDLED;
 }