rtc: ds1307: switch to rtc_register_device
authorAlexandre Belloni <alexandre.belloni@free-electrons.com>
Thu, 6 Jul 2017 09:42:06 +0000 (11:42 +0200)
committerAlexandre Belloni <alexandre.belloni@free-electrons.com>
Fri, 7 Jul 2017 11:14:21 +0000 (13:14 +0200)
This removes a possible race condition and crash and allows for further
improvement of the driver.

Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
drivers/rtc/rtc-ds1307.c

index 57ea25400ecd4438046b987daeae68ed888159da..6f94f20326fb9a3336f3e09e33607d3f4d73c15c 100644 (file)
@@ -1674,8 +1674,8 @@ read_rtc:
                device_set_wakeup_capable(ds1307->dev, true);
                set_bit(HAS_ALARM, &ds1307->flags);
        }
-       ds1307->rtc = devm_rtc_device_register(ds1307->dev, ds1307->name,
-                               rtc_ops, THIS_MODULE);
+
+       ds1307->rtc = devm_rtc_allocate_device(ds1307->dev);
        if (IS_ERR(ds1307->rtc)) {
                return PTR_ERR(ds1307->rtc);
        }
@@ -1737,6 +1737,11 @@ read_rtc:
                }
        }
 
+       ds1307->rtc->ops = rtc_ops;
+       err = rtc_register_device(ds1307->rtc);
+       if (err)
+               return err;
+
        ds1307_hwmon_register(ds1307);
        ds1307_clks_register(ds1307);