]> err.no Git - linux-2.6/commitdiff
RTC: assure proper memory ordering with respect to RTC_DEV_BUSY flag
authorJiri Kosina <jkosina@suse.cz>
Wed, 5 Dec 2007 07:45:05 +0000 (23:45 -0800)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Wed, 5 Dec 2007 17:21:18 +0000 (09:21 -0800)
We must make sure that the RTC_DEV_BUSY flag has proper lock semantics,
i.e.  that the RTC_DEV_BUSY stores clearing the flag don't get reordered
before the preceeding stores and loads and vice versa.

Spotted by Nick Piggin.

Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: David Brownell <david-b@pacbell.net>
Acked-by: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/rtc/interface.c
drivers/rtc/rtc-dev.c

index a4f56e95cf96836448bd6032d04c48078d4e3132..f1e00ff54ce880fb94c69a38064abe6680c83933 100644 (file)
@@ -293,7 +293,7 @@ int rtc_irq_register(struct rtc_device *rtc, struct rtc_task *task)
                return -EINVAL;
 
        /* Cannot register while the char dev is in use */
-       if (test_and_set_bit(RTC_DEV_BUSY, &rtc->flags))
+       if (test_and_set_bit_lock(RTC_DEV_BUSY, &rtc->flags))
                return -EBUSY;
 
        spin_lock_irq(&rtc->irq_task_lock);
@@ -303,7 +303,7 @@ int rtc_irq_register(struct rtc_device *rtc, struct rtc_task *task)
        }
        spin_unlock_irq(&rtc->irq_task_lock);
 
-       clear_bit(RTC_DEV_BUSY, &rtc->flags);
+       clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags);
 
        return retval;
 }
index ae1bf177d62546d4a9225ee40dd208a184403612..025c60a17a4a3c9841d4105bf0344a92f9c31510 100644 (file)
@@ -26,7 +26,7 @@ static int rtc_dev_open(struct inode *inode, struct file *file)
                                        struct rtc_device, char_dev);
        const struct rtc_class_ops *ops = rtc->ops;
 
-       if (test_and_set_bit(RTC_DEV_BUSY, &rtc->flags))
+       if (test_and_set_bit_lock(RTC_DEV_BUSY, &rtc->flags))
                return -EBUSY;
 
        file->private_data = rtc;
@@ -41,7 +41,7 @@ static int rtc_dev_open(struct inode *inode, struct file *file)
        }
 
        /* something has gone wrong */
-       clear_bit(RTC_DEV_BUSY, &rtc->flags);
+       clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags);
        return err;
 }
 
@@ -402,7 +402,7 @@ static int rtc_dev_release(struct inode *inode, struct file *file)
        if (rtc->ops->release)
                rtc->ops->release(rtc->dev.parent);
 
-       clear_bit(RTC_DEV_BUSY, &rtc->flags);
+       clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags);
        return 0;
 }