Commit 201fac95 authored by Alexandre Belloni's avatar Alexandre Belloni

rtc: rk808: fix possible race condition

The probe function is not allowed to fail after registering the RTC because
the following may happen:

CPU0:                                CPU1:
sys_load_module()
 do_init_module()
  do_one_initcall()
   cmos_do_probe()
    rtc_device_register()
     __register_chrdev()
     cdev->owner = struct module*
                                     open("/dev/rtc0")
    rtc_device_unregister()
  module_put()
  free_module()
   module_free(mod->module_core)
   /* struct module *module is now
      freed */
                                      chrdev_open()
                                       spin_lock(cdev_lock)
                                       cdev_get()
                                        try_module_get()
                                         module_is_live()
                                         /* dereferences already
                                            freed struct module* */

Switch to devm_rtc_allocate_device/rtc_register_device to register the rtc
as late as possible.
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent 4cda172b
...@@ -405,12 +405,11 @@ static int rk808_rtc_probe(struct platform_device *pdev) ...@@ -405,12 +405,11 @@ static int rk808_rtc_probe(struct platform_device *pdev)
device_init_wakeup(&pdev->dev, 1); device_init_wakeup(&pdev->dev, 1);
rk808_rtc->rtc = devm_rtc_device_register(&pdev->dev, "rk808-rtc", rk808_rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
&rk808_rtc_ops, THIS_MODULE); if (IS_ERR(rk808_rtc->rtc))
if (IS_ERR(rk808_rtc->rtc)) { return PTR_ERR(rk808_rtc->rtc);
ret = PTR_ERR(rk808_rtc->rtc);
return ret; rk808_rtc->rtc->ops = &rk808_rtc_ops;
}
rk808_rtc->irq = platform_get_irq(pdev, 0); rk808_rtc->irq = platform_get_irq(pdev, 0);
if (rk808_rtc->irq < 0) { if (rk808_rtc->irq < 0) {
...@@ -427,9 +426,10 @@ static int rk808_rtc_probe(struct platform_device *pdev) ...@@ -427,9 +426,10 @@ static int rk808_rtc_probe(struct platform_device *pdev)
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed to request alarm IRQ %d: %d\n", dev_err(&pdev->dev, "Failed to request alarm IRQ %d: %d\n",
rk808_rtc->irq, ret); rk808_rtc->irq, ret);
return ret;
} }
return ret; return rtc_register_device(rk808_rtc->rtc);
} }
static struct platform_driver rk808_rtc_driver = { static struct platform_driver rk808_rtc_driver = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment