linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Dittmer <j.dittmer@portrix.net>
To: Christoph Hellwig <hch@infradead.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Three drivers/i2c/ patches
Date: Sun, 13 Jul 2003 12:32:43 +0200	[thread overview]
Message-ID: <3F11354B.1080501@portrix.net> (raw)
In-Reply-To: <20030713102407.A24901@infradead.org>

Christoph Hellwig wrote:
> 
> Sleeping with interrupts disabled and a spinlock held still isn't exactly a
> good idea.  As is sleep_on..

So something like the following does make more sense?
I don't quite understand, how that code worked before - I suppose
interruptible_sleep_on_timeout activates irqs again, otherwise the interrupt 
handler would have never been called? But then, the sti() doesn't make much 
sense and should have been moved to the else path?

Thanks,

Jan

--- 2.5.75/drivers/i2c/i2c-elektor.c    2003-07-11 09:35:37.000000000 +0200
+++ 2.5.75-bk1/drivers/i2c/i2c-elektor.c        2003-07-13 12:06:06.000000000
+0200
@@ -59,6 +59,8 @@
    need to be rewriten - but for now just remove this for simpler reading */

  static wait_queue_head_t pcf_wait;
+
+spinlock_t pcf_pending_lock = SPIN_LOCK_UNLOCKED;
  static int pcf_pending;

  /* ----- global defines ----------------------------------------------- 
    */
@@ -120,12 +122,14 @@
         int timeout = 2;

         if (irq > 0) {
-               cli();
+               spin_lock_irq(&pcf_pending_lock);
                 if (pcf_pending == 0) {
+                       spin_unlock_irq(&pcf_pending_lock);
                         interruptible_sleep_on_timeout(&pcf_wait, timeout*HZ );
-               } else
+               } else {
                         pcf_pending = 0;
-               sti();
+                       spin_unlock_irq(&pcf_pending_lock);
+               }
         } else {
                 udelay(100);
         }
@@ -133,7 +137,10 @@


  static irqreturn_t pcf_isa_handler(int this_irq, void *dev_id, struct pt_regs
*regs) {
+       unsigned long flags;
+       spin_lock_irqsave(&pcf_pending_lock, flags);
         pcf_pending = 1;
+       spin_unlock_irqrestore(&pcf_pending_lock, flags);
         wake_up_interruptible(&pcf_wait);
         return IRQ_HANDLED;
  }


-- 
Linux rubicon 2.5.75-mm1-jd10 #1 SMP Sat Jul 12 19:40:28 CEST 2003 i686


  reply	other threads:[~2003-07-13 10:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-12 21:35 Three drivers/i2c/ patches Jan Dittmer
2003-07-13  9:24 ` Christoph Hellwig
2003-07-13 10:32   ` Jan Dittmer [this message]
2003-07-13 19:00 ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3F11354B.1080501@portrix.net \
    --to=j.dittmer@portrix.net \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).