* [PATCH] to fix locking in ip27-rtc.c open() and release()
@ 2001-10-05 18:26 David C. Hansen
0 siblings, 0 replies; only message in thread
From: David C. Hansen @ 2001-10-05 18:26 UTC (permalink / raw)
To: linux-mips, ralf
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2001-10-05 18:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-10-05 18:26 [PATCH] to fix locking in ip27-rtc.c open() and release() David C. Hansen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox