Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=e109ebd1eed2b91e3c9bb3b42cc27961f0dc22b3
Commit:     e109ebd1eed2b91e3c9bb3b42cc27961f0dc22b3
Parent:     0478e62e8a04154b7bdc0dfd33ffbcabc5446e9c
Author:     David Brownell <[EMAIL PROTECTED]>
AuthorDate: Wed Feb 28 20:12:40 2007 -0800
Committer:  Linus Torvalds <[EMAIL PROTECTED]>
CommitDate: Thu Mar 1 14:53:37 2007 -0800

    [PATCH] rtc_cmos oops fix
    
    Fix an oops on the rtc_device_unregister() path by waiting until the last
    moment before nulling the rtc->ops vector.  Fix some potential oopses by
    having the rtc_class_open()/rtc_class_close() interface increase the RTC's
    reference count while an RTC handle is available outside the RTC framework.
    
    Signed-off-by: David Brownell <[EMAIL PROTECTED]>
    Cc: Alessandro Zummo <[EMAIL PROTECTED]>
    Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
    Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>
---
 drivers/rtc/class.c     |   14 ++++++++++----
 drivers/rtc/interface.c |    3 ++-
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 7a0d8ee..04aaa63 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -113,10 +113,16 @@ EXPORT_SYMBOL_GPL(rtc_device_register);
  */
 void rtc_device_unregister(struct rtc_device *rtc)
 {
-       mutex_lock(&rtc->ops_lock);
-       rtc->ops = NULL;
-       mutex_unlock(&rtc->ops_lock);
-       class_device_unregister(&rtc->class_dev);
+       if (class_device_get(&rtc->class_dev) != NULL) {
+               mutex_lock(&rtc->ops_lock);
+               /* remove innards of this RTC, then disable it, before
+                * letting any rtc_class_open() users access it again
+                */
+               class_device_unregister(&rtc->class_dev);
+               rtc->ops = NULL;
+               mutex_unlock(&rtc->ops_lock);
+               class_device_put(&rtc->class_dev);
+       }
 }
 EXPORT_SYMBOL_GPL(rtc_device_unregister);
 
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 6f11f6d..ef40df0 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -179,7 +179,7 @@ struct class_device *rtc_class_open(char *name)
        down(&rtc_class->sem);
        list_for_each_entry(class_dev_tmp, &rtc_class->children, node) {
                if (strncmp(class_dev_tmp->class_id, name, BUS_ID_SIZE) == 0) {
-                       class_dev = class_dev_tmp;
+                       class_dev = class_device_get(class_dev_tmp);
                        break;
                }
        }
@@ -197,6 +197,7 @@ EXPORT_SYMBOL_GPL(rtc_class_open);
 void rtc_class_close(struct class_device *class_dev)
 {
        module_put(to_rtc_device(class_dev)->owner);
+       class_device_put(class_dev);
 }
 EXPORT_SYMBOL_GPL(rtc_class_close);
 
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to