Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtc: max8925: Initialize drvdata before registering device

Commit f44f7f96a20 ("RTC: Initialize kernel state from RTC") uncovered
an issue in a number of RTC drivers, where the drivers call
rtc_device_register before initializing the device or platform drvdata.

This frequently results in null pointer dereferences when the
rtc_device_register immediately makes use of the rtc device, calling
rtc_read_alarm.

The solution is to ensure the drvdata is initialized prior to registering
the rtc device.

CC: Wolfram Sang <w.sang@pengutronix.de>
CC: Alessandro Zummo <a.zummo@towertech.it>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: rtc-linux@googlegroups.com
Signed-off-by: John Stultz <john.stultz@linaro.org>

+3 -2
+3 -2
drivers/rtc/rtc-max8925.c
··· 258 258 } 259 259 260 260 dev_set_drvdata(&pdev->dev, info); 261 + /* XXX - isn't this redundant? */ 262 + platform_set_drvdata(pdev, info); 261 263 262 264 info->rtc_dev = rtc_device_register("max8925-rtc", &pdev->dev, 263 265 &max8925_rtc_ops, THIS_MODULE); ··· 269 267 goto out_rtc; 270 268 } 271 269 272 - platform_set_drvdata(pdev, info); 273 - 274 270 return 0; 275 271 out_rtc: 272 + platform_set_drvdata(pdev, NULL); 276 273 free_irq(chip->irq_base + MAX8925_IRQ_RTC_ALARM0, info); 277 274 out_irq: 278 275 kfree(info);