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

rtc: pcap: 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 -1
+3 -1
drivers/rtc/rtc-pcap.c
··· 151 151 152 152 pcap_rtc->pcap = dev_get_drvdata(pdev->dev.parent); 153 153 154 + platform_set_drvdata(pdev, pcap_rtc); 155 + 154 156 pcap_rtc->rtc = rtc_device_register("pcap", &pdev->dev, 155 157 &pcap_rtc_ops, THIS_MODULE); 156 158 if (IS_ERR(pcap_rtc->rtc)) { ··· 160 158 goto fail_rtc; 161 159 } 162 160 163 - platform_set_drvdata(pdev, pcap_rtc); 164 161 165 162 timer_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_1HZ); 166 163 alarm_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_TODA); ··· 178 177 fail_timer: 179 178 rtc_device_unregister(pcap_rtc->rtc); 180 179 fail_rtc: 180 + platform_set_drvdata(pdev, NULL); 181 181 kfree(pcap_rtc); 182 182 return err; 183 183 }