[PATCH] to fix locking in ip27-rtc.c open() and release()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Linux MIPS Home]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Linux]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux