diff options
| author | Alexandre Belloni <alexandre.belloni@bootlin.com> | 2018-02-21 05:57:05 -0500 |
|---|---|---|
| committer | Alexandre Belloni <alexandre.belloni@bootlin.com> | 2018-03-17 09:20:42 -0400 |
| commit | 201fac95e799c3d0304ec724d555e1251b9f6e84 (patch) | |
| tree | 1b6758467df034e9207fe9a083faabaccb3bda5e /drivers/rtc | |
| parent | 4cda172bc338abf770dcdbcf61049ef0d76b17fc (diff) | |
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: Alexandre Belloni <alexandre.belloni@bootlin.com>
Diffstat (limited to 'drivers/rtc')
| -rw-r--r-- | drivers/rtc/rtc-rk808.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/drivers/rtc/rtc-rk808.c b/drivers/rtc/rtc-rk808.c index e40f35d1ced3..739c0d42e835 100644 --- a/drivers/rtc/rtc-rk808.c +++ b/drivers/rtc/rtc-rk808.c | |||
| @@ -405,12 +405,11 @@ static int rk808_rtc_probe(struct platform_device *pdev) | |||
| 405 | 405 | ||
| 406 | device_init_wakeup(&pdev->dev, 1); | 406 | device_init_wakeup(&pdev->dev, 1); |
| 407 | 407 | ||
| 408 | rk808_rtc->rtc = devm_rtc_device_register(&pdev->dev, "rk808-rtc", | 408 | rk808_rtc->rtc = devm_rtc_allocate_device(&pdev->dev); |
| 409 | &rk808_rtc_ops, THIS_MODULE); | 409 | if (IS_ERR(rk808_rtc->rtc)) |
| 410 | if (IS_ERR(rk808_rtc->rtc)) { | 410 | return PTR_ERR(rk808_rtc->rtc); |
| 411 | ret = PTR_ERR(rk808_rtc->rtc); | 411 | |
| 412 | return ret; | 412 | rk808_rtc->rtc->ops = &rk808_rtc_ops; |
| 413 | } | ||
| 414 | 413 | ||
| 415 | rk808_rtc->irq = platform_get_irq(pdev, 0); | 414 | rk808_rtc->irq = platform_get_irq(pdev, 0); |
| 416 | if (rk808_rtc->irq < 0) { | 415 | if (rk808_rtc->irq < 0) { |
| @@ -427,9 +426,10 @@ static int rk808_rtc_probe(struct platform_device *pdev) | |||
| 427 | if (ret) { | 426 | if (ret) { |
| 428 | dev_err(&pdev->dev, "Failed to request alarm IRQ %d: %d\n", | 427 | dev_err(&pdev->dev, "Failed to request alarm IRQ %d: %d\n", |
| 429 | rk808_rtc->irq, ret); | 428 | rk808_rtc->irq, ret); |
| 429 | return ret; | ||
| 430 | } | 430 | } |
| 431 | 431 | ||
| 432 | return ret; | 432 | return rtc_register_device(rk808_rtc->rtc); |
| 433 | } | 433 | } |
| 434 | 434 | ||
| 435 | static struct platform_driver rk808_rtc_driver = { | 435 | static struct platform_driver rk808_rtc_driver = { |
