linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* (no subject)
@ 2005-03-08 16:32 Peter W. Morreale
  2005-03-08 19:32 ` Ross Biro
  0 siblings, 1 reply; 2+ messages in thread
From: Peter W. Morreale @ 2005-03-08 16:32 UTC (permalink / raw)
  To: linux-kernel

In a driver I am reviewing I found the following locking constructs.
Notice how 'foo" is being called while we have suspended interrupts.

This seems wrong since we've mixed locking primitives.

Is it?

Thanks in advance.

-PWM

---------------------snip--------------------------------------
spin_lock_irqsave(global_lock, &flags);
....
foo()
{
    unsigned long lflags;

    spin_unlock(global_lock);
    ...
    {
        spin_lock_irqsave(global_lock, &lflags);
                .
                .
        spin_unlock_irqrestore(global_lock, &lflags);
    }

    spin_lock_irq(global_lock);
}

spin_unlock_irqrestore(global_lock, &flags);



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re:
  2005-03-08 16:32 Peter W. Morreale
@ 2005-03-08 19:32 ` Ross Biro
  0 siblings, 0 replies; 2+ messages in thread
From: Ross Biro @ 2005-03-08 19:32 UTC (permalink / raw)
  To: Peter W. Morreale; +Cc: linux-kernel

On Tue, 08 Mar 2005 09:32:48 -0700, Peter W. Morreale
<peter_w_morreale@hotmail.com> wrote:
> 
> This seems wrong since we've mixed locking primitives.
> 
> Is it?

It's not really wrong, it just wastes time turning interrupts off over
and over again.
> ....
> foo()
> {
>     unsigned long lflags;

At this point, interrupts are off, the lock is held.
> 
>     spin_unlock(global_lock);

Interrupts are still off, the lock is no longer held.
>     ...
>     {
>         spin_lock_irqsave(global_lock, &lflags);

Interrupts are still off, and just to be sure we turned them off
again.  The lock is held.
>                 .
>                 .
>         spin_unlock_irqrestore(global_lock, &lflags);
Interrupts are still off, but we restored them to the off state they
were in before
we grabbed the lock the last time.  The lock is no longer held.
>     }
> 
>     spin_lock_irq(global_lock);
Turn off interrupts again just to be extra sure they are off.  The
lock is held again.

>From the looks of this code, the locking will work.  But it's not what
it should be.

If you know foo is only called with interrupts off, then there is no
reason to turn them off over and over again.  Just use the standard
spin_lock and spin_unlock and comment that interrupts are already off.

You should also question if interrupts need to be disabled at all.  If
the spin lock is never grabbed at interrupt time (and probably won't
be in the near future), then there is no point in turning interrupts
on and off at all.

    Ross

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-03-08 19:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-08 16:32 Peter W. Morreale
2005-03-08 19:32 ` Ross Biro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).