misc_register() exposes the watchdog before its lock, completion, and timer are initialized. A userspace operation racing probe can therefore use any of these objects before it is ready. Finish initializing the watchdog state before registering the misc device. Fixes: b3e8f2c13ae9 ("[WATCHDOG] Add support for the built-int RDC R-321x SoC watchdog") Cc: stable@vger.kernel.org Signed-off-by: Jiale Yao --- drivers/watchdog/rdc321x_wdt.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/watchdog/rdc321x_wdt.c b/drivers/watchdog/rdc321x_wdt.c index 8955177072fa..a2520d8d5c90 100644 --- a/drivers/watchdog/rdc321x_wdt.c +++ b/drivers/watchdog/rdc321x_wdt.c @@ -233,12 +233,6 @@ static int rdc321x_wdt_probe(struct platform_device *pdev) rdc321x_wdt_device.queue = 0; rdc321x_wdt_device.default_ticks = ticks; - err = misc_register(&rdc321x_wdt_misc); - if (err < 0) { - dev_err(&pdev->dev, "misc_register failed\n"); - return err; - } - spin_lock_init(&rdc321x_wdt_device.lock); /* Reset the watchdog */ @@ -251,6 +245,12 @@ static int rdc321x_wdt_probe(struct platform_device *pdev) timer_setup(&rdc321x_wdt_device.timer, rdc321x_wdt_trigger, 0); + err = misc_register(&rdc321x_wdt_misc); + if (err < 0) { + dev_err(&pdev->dev, "misc_register failed\n"); + return err; + } + dev_info(&pdev->dev, "watchdog init success\n"); return 0; -- 2.34.1