Linux MIPS Architecture development
 help / color / mirror / Atom feed
From: "David C. Hansen" <haveblue@us.ibm.com>
To: linux-mips@oss.sgi.com, ralf@gnu.org
Subject: [PATCH] to fix locking in ip27-rtc.c open() and release()
Date: Fri, 5 Oct 2001 11:26:51 -0700	[thread overview]
Message-ID: <200110051826.f95IQpb02486@localhost.localdomain> (raw)

This patch fixes a potential race condition in ip27-rtc.c.  The rtc_status variable is not sufficient to ensure exclusive write access to the file in the open() function.  This patch adds locking around the necessary critical areas in open() and replaces the big kernel lock in release().


--- linux-2.4.10-clean/arch/mips64/sgi-ip27/ip27-rtc.c	Tue Nov 28 21:42:04 2000
+++ linux/arch/mips64/sgi-ip27/ip27-rtc.c	Tue Oct  2 13:23:09 2001
@@ -61,6 +61,7 @@
 #define RTC_TIMER_ON		0x02	/* missed irq timer active	*/
 
 static unsigned char rtc_status;	/* bitmapped status byte.	*/
+static spinlock_t rtc_status_lock = SPIN_LOCK_UNLOCKED;
 static unsigned long rtc_freq;	/* Current periodic IRQ rate	*/
 static struct m48t35_rtc *rtc;
 
@@ -166,10 +167,15 @@
 
 static int rtc_open(struct inode *inode, struct file *file)
 {
+	spin_lock( rtc_status_lock );
 	if(rtc_status & RTC_IS_OPEN)
+	{
+		spin_unlock( rtc_status_lock );
 		return -EBUSY;
+	}
 
 	rtc_status |= RTC_IS_OPEN;
+	spin_unlock( rtc_status_lock );
 	return 0;
 }
 
@@ -180,9 +186,9 @@
 	 * in use, and clear the data.
 	 */
 
-	lock_kernel();
+	spin_lock( rtc_status_lock );
 	rtc_status &= ~RTC_IS_OPEN;
-	unlock_kernel();
+	spin_unlock( rtc_status_lock );
 	return 0;
 }
 

--
David C. Hansen
haveblue@us.ibm.com
IBM LTC Base/OS Group
(503)578-4080

                 reply	other threads:[~2001-10-05 18:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=200110051826.f95IQpb02486@localhost.localdomain \
    --to=haveblue@us.ibm.com \
    --cc=linux-mips@oss.sgi.com \
    --cc=ralf@gnu.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