Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9a99247c authored by Alexandre Belloni's avatar Alexandre Belloni
Browse files

rtc: vr41xx: fix possible race condition



The probe function is not allowed to fail after the RTC is registered
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* */

Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent 94389b28
Loading
Loading
Loading
Loading
+7 −2
Original line number Original line Diff line number Diff line
@@ -292,13 +292,14 @@ static int rtc_probe(struct platform_device *pdev)
		goto err_rtc1_iounmap;
		goto err_rtc1_iounmap;
	}
	}


	rtc = devm_rtc_device_register(&pdev->dev, rtc_name, &vr41xx_rtc_ops,
	rtc = devm_rtc_allocate_device(&pdev->dev);
					THIS_MODULE);
	if (IS_ERR(rtc)) {
	if (IS_ERR(rtc)) {
		retval = PTR_ERR(rtc);
		retval = PTR_ERR(rtc);
		goto err_iounmap_all;
		goto err_iounmap_all;
	}
	}


	rtc->ops = &vr41xx_rtc_ops;

	rtc->max_user_freq = MAX_PERIODIC_RATE;
	rtc->max_user_freq = MAX_PERIODIC_RATE;


	spin_lock_irq(&rtc_lock);
	spin_lock_irq(&rtc_lock);
@@ -340,6 +341,10 @@ static int rtc_probe(struct platform_device *pdev)


	dev_info(&pdev->dev, "Real Time Clock of NEC VR4100 series\n");
	dev_info(&pdev->dev, "Real Time Clock of NEC VR4100 series\n");


	retval = rtc_register_device(rtc);
	if (retval)
		goto err_iounmap_all;

	return 0;
	return 0;


err_iounmap_all:
err_iounmap_all: