to fix locking in ip27-rtc.c open() and release()
PATCH 1/1 to fix locking in ip27-rtc.c open() and release()
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().
arch/mips64/sgi-ip27/ip27-rtc.c +8 -2
@@ -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
[email protected]
IBM LTC Base/OS Group
(503)578-4080