Skip to content

Commit a91d2ba

Browse files
Wolfram Sangjohnstultz-work
authored andcommitted
rtc: stmp3xxx: Initialize drvdata before registering device
Commit f44f7f9 ("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. Signed-off-by: Wolfram Sang <w.sang@pengutronix.de> Tested-by: Shawn Guo <shawn.guo@freescale.com> Signed-off-by: John Stultz <john.stultz@linaro.org>
1 parent 46b2121 commit a91d2ba

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎drivers/rtc/rtc-stmp3xxx.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ static int stmp3xxx_rtc_remove(struct platform_device *pdev)
176176
free_irq(rtc_data->irq_alarm, &pdev->dev);
177177
free_irq(rtc_data->irq_1msec, &pdev->dev);
178178
rtc_device_unregister(rtc_data->rtc);
179+
platform_set_drvdata(pdev, NULL);
179180
iounmap(rtc_data->io);
180181
kfree(rtc_data);
181182

@@ -216,11 +217,14 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev)
216217
goto out_remap;
217218
}
218219

220+
platform_set_drvdata(pdev, rtc_data);
221+
219222
mxs_reset_block(rtc_data->io);
220223
__mxs_clrl(STMP3XXX_RTC_PERSISTENT0_ALARM_EN |
221224
STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN |
222225
STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE,
223226
rtc_data->io + STMP3XXX_RTC_PERSISTENT0);
227+
224228
rtc_data->rtc = rtc_device_register(pdev->name, &pdev->dev,
225229
&stmp3xxx_rtc_ops, THIS_MODULE);
226230
if (IS_ERR(rtc_data->rtc)) {
@@ -244,8 +248,6 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev)
244248
goto out_irq1;
245249
}
246250

247-
platform_set_drvdata(pdev, rtc_data);
248-
249251
return 0;
250252

251253
out_irq1:
@@ -256,6 +258,7 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev)
256258
rtc_data->io + STMP3XXX_RTC_CTRL);
257259
rtc_device_unregister(rtc_data->rtc);
258260
out_remap:
261+
platform_set_drvdata(pdev, NULL);
259262
iounmap(rtc_data->io);
260263
out_free:
261264
kfree(rtc_data);

0 commit comments

Comments
 (0)